Efficient Logistics by Exploration with Robotic Retrieval
A real-time multi-agent simulation framework where autonomous agents explore warehouse environments, discover objects, and optimize retrieval through swarm intelligence principles. Built with Python (Streamlit) backend for interactive visualization and benchmarking.
Repository: SwarmLab
Live demo: swarm-lab.streamlit.app
- Python 3.9+
- Virtual environment (optional but recommended)
# 1. Activate your virtual environment (if you have one)
# Windows PowerShell:
.\.venv\Scripts\Activate.ps1
# macOS / Linux:
source .venv/bin/activate
# 2. Install dependencies
pip install -r requirements.txt
# or with uv (recommended)
uv pip install -r requirements.txt
# 3. Launch the app
streamlit run app.pyOpen your browser at http://localhost:8501 β you'll see the interactive dashboard with:
- Live grid visualization
- Agent configuration panel
- Real-time metrics & battery monitoring
- Preset save/load
- Benchmark mode for batch testing
Note: this project uses pygame-ce (drop-in compatible with import pygame) to ensure reliable wheel installs on modern Windows/Python setups.
| Strategy | Colour | Approach |
|---|---|---|
| Frontier | Blue | Frontier-based systematic exploration with target lock |
| Greedy | Orange | Warehouse-centric greedy search |
| Sector | Green | Grid-partitioning with assigned sectors per agent |
| Repulsion | Red | Emergent dispersion based on inter-agent repulsion |
| Smart Random | Purple | Information-gain guided random walk with stale avoidance |
| Ant-Colony | Teal | Experimental prototype (currently not usable) |
- Live grid visualization with Pygame offscreen rendering β fog-of-war, agent vision radius, communication range
- Three-column layout: agent configuration | simulation grid | live metrics & battery bars
- Preset system β save/load agent configurations as JSON for reproducible runs
- Battery monitoring β real-time per-agent energy consumption tracking
- Run history β compare multiple simulation runs side-by-side
- Full-screen benchmarking β automated batch testing of strategy combinations
- Random preset generation β vary usable strategies, vision radius, communication radius independently
- Exhaustive or sampled search β generate unique presets up to the full combinatorial space
- Multi-run execution with configurable random seeds
- Delivery curves β cumulative object retrieval over time (per preset)
- CSV export β download full results for external analysis
- Top-10 rankings β filters by tick count, completion rate, energy consumption
- Ant-Colony excluded β currently treated as a prototype and not used in benchmark runs
- Two provided warehouse instances (
A.json,B.json) with identical structure:- Grid size: 25Γ25 cells
- 4 warehouses with entrance/exit per warehouse
- 10 objects to retrieve per instance
- Easy JSON format for custom scenarios
βββ π README.md (this file)
βββ π requirements.txt (Python dependencies)
βββ π app.py (Streamlit entry point)
βββ π benchmark_strategies.py (CLI benchmarking script)
β
βββ π assets/ (Images: logo, icons)
β βββ 2.png
β βββ agent.png
β βββ package.png
β
βββ π ui/ (Streamlit UI modules)
β βββ π __init__.py
β βββ (future: component split)
β
βββ π src/
β βββ π agents/
β β βββ π agent.py (Core Agent class)
β β βββ π sensors.py (Perception: visibility, communication)
β β βββ π strategies/
β β βββ π base.py (Strategy interface)
β β βββ π frontier.py (Frontier exploration)
β β βββ π greedy.py (Warehouse-centric greedy)
β β βββ π sector.py (Sector partitioning)
β β βββ π Repulsion.py (Emergent repulsion)
β β βββ π random_walk.py (Info-gain random walk)
β β βββ π ant_colony_lite.py (Pheromone-based)
β β
β βββ π environment/
β β βββ π environment.py (Simulator state & logic)
β β βββ π grid.py (Cell types, grid data)
β β βββ π __init__.py
β β
β βββ π simulation/
β β βββ π simulator.py (Tick loop & step generator)
β β βββ π metrics.py (Statistics collection)
β β βββ π __init__.py
β β
β βββ π pathfinding/
β β βββ π pathfinder.py (A* navigation)
β β βββ π __init__.py
β β
β βββ π communication/
β β βββ π protocol.py (Inter-agent messaging)
β β βββ π __init__.py
β β
β βββ π visualization/
β β βββ π base.py (Abstract visualizer)
β β βββ π matplotlib_viz.py (Matplotlib rendering)
β β βββ π pygame_viz.py (Pygame rendering)
β β βββ π __init__.py
β β
β βββ π __init__.py
β
βββ π __pycache__/ (Python cache)
| Parameter | Min | Max | Default | Notes |
|---|---|---|---|---|
| Vision radius | 1 | 3 | 2 | Cells visible in Manhattan distance (orthogonal) |
| Comm radius | 1 | 2 | 2 | Max distance for inter-agent message exchange |
| Initial battery | β | β | 500 | Energy units; β1 per step; agent stops at 0 |
| Grid size | β | β | 25Γ25 | Environment dimensions (fixed per instance) |
| Num agents | 1 | 10 | 5 | Team size; configurable per run |
| Max ticks | 100 | 750 | 500 | Simulation duration limit |
Both instances (A.json, B.json) contain:
- 4 warehouses β rectangular regions marked
WAREHOUSE(value 2) - 4 entrances β one per warehouse, marked
ENTRANCE(value 3) - 4 exits β one per warehouse, marked
EXIT(value 4) - Corridors β
EMPTYcells (value 0) connecting warehouses - Obstacles β
WALLcells (value 1) representing shelves - 10 objects β coordinates in separate
objectsarray (not grid-embedded)
Cell type values:
| Value | Type | Walkable | Role |
|---|---|---|---|
| 0 | EMPTY | β | Corridor, general space |
| 1 | WALL | β | Obstacle, shelf |
| 2 | WAREHOUSE | β | Interior; delivery target |
| 3 | ENTRANCE | β | Gateway into warehouse |
| 4 | EXIT | β | Gateway out of warehouse |
-
Initialization
- Load environment from JSON
- Create N agents with assigned strategies
- Reset batteries, local maps, object tracking
-
Per-tick loop (up to
max_ticks)- Each agent perceives surroundings (vision + communication)
- Each agent executes strategy logic (navigation, exploration)
- Local maps (agent knowledge) are updated
- Metrics are collected (ticks, objects delivered, energy)
- Stop if all objects are delivered
-
Metrics & reporting
- Total ticks: simulation duration
- Objects delivered: count of objects successfully carried to warehouse
- Completion rate: delivered / total objects (0β1)
- Average energy consumed: sum of energy spent / num agents
- First pickup tick: when first object was picked up
- First delivery tick: when first object was delivered
Run from the π¬ Benchmark tab in Streamlit:
-
Select parametrization mode:
- Random: vary each parameter independently across a range
- Fixed: lock each parameter to a single value
-
Configure ranges:
- Strategy pool (subset of usable strategies; Ant-Colony excluded)
- Vision radius range (1β5, or fixed)
- Communication radius range (1β2, or fixed)
-
Generate presets:
- Displayed: max unique combinations
- Input: number of presets to test (sampled or exhaustive)
-
Execute & analyze:
- Run all presets with progress bar
- Download CSV with all results
- View delivery curves (cumulative objects/tick)
- Rank by efficiency (ticks, energy, completion)
Explores based on "frontier" cells β boundaries between known and unknown areas. Prioritizes distant frontiers and locks on selected targets to avoid oscillation. Weights frontier distance sub-linearly to prefer nearby exploration while still reaching far areas.
Performs warehouse-centric search: prioritizes cells closest to known warehouse locations, exploring warehouse interiors first. Simpler but may miss distributed objects.
Divides the grid into equal sectors and assigns each agent a sector. Agents explore only their assigned area to minimize overlap and ensure uniform coverage.
Agents repel each other based on proximity, creating emergent separation. No explicit coordination; behavior emerges from local repulsion forces.
Enhances random walk with:
- Information gain β prefers cells that reveal more unknown area
- Stale avoidance β deprioritizes recently visited cells
- Separation β avoids crowding with nearby agents
Prototype: Pheromone-inspired strategy where agents should lay virtual pheromones and bias motion toward low-pheromone cells. This strategy is not fully implemented yet, so it is documented for completeness only. Do not use in production runs or benchmark comparisons.
Daniele Barabagallo β GitHub