Skip to content

jenxwa/Bee-Foraging-RL-Simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bee Foraging RL Simulation

This repository contains a Reinforcement Learning (RL) project in which a bee collects pollen from flowers and returns it to a hive. The agent uses Q-learning to discover efficient foraging strategies under various vision constraints.

Screenshot 2025-03-10 at 14 33 50

Features

  • Grid Environment: A 6×6 board with a hive and multiple flowers.
  • Health Mechanic: Bee loses health with each move; dying ends the episode.
  • Pollen Delivery: Collect pollen from flowers and earn a large reward upon hive return.
  • Vision Modes:
    1. Full Vision: Bee knows its exact (x,y) location and carrying status.
    2. 3×3 Partial Vision: Bee only sees a local 3×3 window around its position.
    3. Single-Tile Vision: Bee sees only the tile it stands on.

Key Files

  • bee_foraging_simulation.py: Main Python script running Q-learning with adjustable vision modes.
  • bee.png, flower1.png, flower2.png, flower3.png: Images for rendering the bee and flowers.
  • Dependencies:
    • pygame for rendering
    • matplotlib for real-time plotting
    • python 3.7+

How to Run

  1. Install dependencies: pip install pygame matplotlib
  2. Launch the simulation: bash python bee_foraging_simulation.py
  3. Adjust parameters (episodes, learning rate, vision mode) in the script to experiment with different settings.

Learning Logic

image

Q-Learning

State can be:

  • (x, y, carrying_flag) for full vision, or
  • (local_3x3_view, carrying_flag) for partial vision, or
  • (single_tile_view, carrying_flag) for single-tile vision.

Actions: Move up/down/left/right (or turn/move if orientation-based).

Rewards:

  • Small penalty for each step.
  • Positive for picking up pollen.
  • Large bonus for delivering pollen to the hive.
  • Penalty for running out of health.

Observations

Even with partial or single-tile vision, the bee can eventually learn routes back to the hive in a small environment, because Q-learning’s table effectively encodes the path from each state to the hive.

Feel free to fork or modify the project for your own experiments. Happy foraging!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages