Skip to main content
Version: 🚧 Alpha 🚧

Smart Forager: reinforcement learning in GAMA

This tutorial uses a foraging model to introduce reinforcement learning in three stages. The first uses tabular Q-learning implemented in GAML. The second connects a continuous GAMA model to Python through Gymnasium and trains a PPO policy. The third extends the model to cooperative multi-agent learning with PettingZoo.

Part 1 can be followed with GAMA alone. Parts 2 and 3 use external Python packages and a GAMA server. Check the current requirements for GAMA-Gymnasium and GAMA-PettingZoo before installing them.

Part 1: Tabular Q-learning in GAML​

Build a grid world, add a forager, define rewards and episode resets, then implement a Q-table and Q-learning policy. The final step adds training metrics, a learned-value heatmap and a test mode.

Each step in this part ends with a complete model for that stage. The listing repeats the previous step and adds the new behavior, so it can be used without assembling code from earlier pages.

  1. The grid world
  2. The forager agent
  3. Rewards and episodes
  4. The Q-table
  5. The Q-learning algorithm
  6. Training charts and test mode

Grid heatmap and training charts showing learned values, episode reward and epsilon

The model's grid heatmap and reward and epsilon charts during training.

Part 2: Continuous forager with Gymnasium​

Replace the grid with a continuous world and connect it to Python using the gama-gymnasium bridge. The steps define the bridge, sensors, movement and rewards, then train and test a PPO policy.

  1. Introduction and continuous world
  2. The GymAgent bridge
  3. Sensors, movement and rewards
  4. Headless training with PPO
  5. Evaluating the trained policy

Part 3: Cooperative foragers with PettingZoo​

Extend the continuous model to multiple foragers with a shared policy. The final step applies that policy to a larger group.

  1. From one forager to multiple agents
  2. The multi-agent GAML model
  3. Training multiple agents
  4. Testing and summary
  5. Scaling to ten agents