Skip to main content
Version: 🚧 Alpha 🚧

7. Introduction and the continuous world

Why Deep RL?​

In Part 1, we built a Smart Forager using Tabular Q-Learning directly in GAML. While it worked on a 10×10 grid, it has two fundamental limitations:

  1. Discrete only: The Q-Table requires a finite set of states. A forager that moves freely in continuous space has infinite states - the table would be infinitely large.
  2. No generalization: The agent learns nothing about positions it has never visited. If it learned that (3, 5) is good, it knows nothing about (3.1, 5.2).

Deep RL solves both problems by replacing the Q-Table with a neural network that can generalize across similar states and handle continuous spaces.

What changes in Part 2​

AspectPart 1 (Native GAML)Part 2 (Gymnasium)
World10×10 grid100×100 continuous space
Movement4 discrete directions (up/down/left/right)2D velocity vector (dx, dy)
SensorsGrid position (x, y)8 ray-cast obstacle sensors + position + food direction
LearningGAML map<string, float> Q-TablePython neural network
AlgorithmQ-Learning (Bellman equation)PPO (Proximal Policy Optimization)
TrainingInside GAMAHeadless GAMA + Python
TestingRun another episode in GAMAPython policy evaluation through the bridge

Architecture Overview​

---
config:
flowchart:
wrappingWidth: 220
nodeSpacing: 22
rankSpacing: 28
padding: 10
diagramPadding: 8
look: classic
fontFamily: "system-ui, sans-serif"
theme: base
themeVariables:
fontFamily: "system-ui, sans-serif"
fontSize: "14px"
primaryColor: "#dbeafe"
primaryTextColor: "#172b4d"
primaryBorderColor: "#2563a6"
lineColor: "#526780"
secondaryColor: "#dcfce7"
secondaryTextColor: "#14532d"
secondaryBorderColor: "#39805a"
tertiaryColor: "#fff1cc"
tertiaryTextColor: "#713f12"
tertiaryBorderColor: "#a66b16"
clusterBkg: "#f1f5f9"
clusterBorder: "#94a3b8"
edgeLabelBackground: "#ffffff"
actorBkg: "#dbeafe"
actorBorder: "#2563a6"
actorTextColor: "#172b4d"
actorLineColor: "#94a3b8"
signalColor: "#526780"
signalTextColor: "#172b4d"
activationBkgColor: "#dcfce7"
activationBorderColor: "#39805a"
---
flowchart TD
subgraph gama["GAMA (headless)"]
model["Continuous GAML model"]
world["Continuous world and obstacles"]
sensors["Eight ray-cast sensors"]
bridge["GymAgent bridge species"]
model --> world
model --> sensors
model --> bridge
end
subgraph python["Python"]
environment["Gymnasium interface"]
training["PPO training code"]
policy["Policy evaluation"]
training --> policy
end
bridge <-->|"observations and actions"| environment
environment <--> training
classDef result fill:#dcfce7,stroke:#39805a,color:#14532d
class policy result

Prerequisites​

Install GAMA with headless server support. For Python, install the packages required by the current GAMA-Gymnasium README and the PyTorch package used by the PPO example. Check the bridge's current compatibility requirements before choosing a Python version.


The Continuous World​

Instead of using a grid species with discrete cells, we set up a plain continuous world of 100×100 units.

Key Differences from Part 1​

  • No grid species: Instead of grid world_cell width: 10 height: 10, the world is a plain 100×100 area.
  • Obstacles are geometries: We use square(10) (matching one grid cell) placed at each cell's center, instead of setting is_obstacle on grid cells.
  • Same layout: The 6 obstacle cells {2,2},{3,2},{2,3},{6,4},{7,4},{7,5} are preserved exactly.
  • Food is a point: food_location <- {95.0, 95.0} (center of native cell 9,9) with food_radius <- 5.0.

Run the bridge​

The complete model below defines the continuous world and its display. To connect a Python environment, start the GAMA server on the port it uses; the package README demonstrates port 6868.


Complete Model​

The example at the end of this step defines the continuous world, its visualization and a placeholder forager species. Steps 8 and 9 extend the example with the bridge and forager behavior.

/**
* Name: SmartForagerGym - Step 7: The Continuous World
* Author: Killian Trouillet
* Description: Continuous 100x100 world matching the Part 1 layout.
* Scaffold for the GymAgent bridge (Steps 8-9).
* Tags: reinforcement-learning, gymnasium, continuous, tutorial
*/

model SmartForagerGym

global {
float world_size <- 100.0;
point food_location <- {95.0, 95.0}; // native cell (9,9)
float food_radius <- 5.0;

list<geometry> obstacles <- [];

int max_steps <- 300;
int current_step <- 0;

init {
// Same 6 obstacles as Part 1, scaled to 100x100
obstacles << square(10) at_location {25.0, 25.0}; // cell (2,2)
obstacles << square(10) at_location {35.0, 25.0}; // cell (3,2)
obstacles << square(10) at_location {25.0, 35.0}; // cell (2,3)
obstacles << square(10) at_location {65.0, 45.0}; // cell (6,4)
obstacles << square(10) at_location {75.0, 45.0}; // cell (7,4)
obstacles << square(10) at_location {75.0, 55.0}; // cell (7,5)

create forager number: 1 {
location <- {5.0, 5.0};
}
}
}

species forager {
// To be fully implemented in Steps 8 and 9
aspect default {
draw circle(3) color: #blue;
}
}

experiment gym_env {
output {
display Continuous_World title: "Continuous World" renderer: 2d {
graphics "background" {
draw rectangle(world_size, world_size)
at: {world_size / 2, world_size / 2}
color: rgb(240, 240, 240);
}
graphics "obstacles" {
loop obs over: obstacles {
draw obs color: rgb(80, 80, 80);
}
}
graphics "food" {
draw circle(food_radius) at: food_location color: rgb(50, 180, 50);
}
species forager;
}
}
}