Agent-based model simulating cooperative vs. individual farming strategies across Morocco's agro-ecological zones — 107% mean profit advantage for cooperatives, validated over 20 random seeds.
# FarmSwarm: Network-Based Collective Intelligence for Smart Agriculture
An agent-based model (ABM) built with Mesa that simulates farmer decision-making across Morocco's agro-ecological zones. The simulation compares **cooperative (SHARED)** and **individual (INDIVIDUAL)** farming strategies using real-world data from FAO, Copernicus, and NASA POWER.
## Research Question
> Does cooperative knowledge-sharing between farmers improve crop yields and profitability compared to individual decision-making?
## Key Features
- **100 paired agents** (50 SHARED + 50 INDIVIDUAL) across 6 agro-ecological zones
- **24 crops** with FAO EcoCrop suitability and FAOSTAT pricing
- **Real cost model**: labor (SMAG × days/ha) + fertilizers (NPK by category) + seeds (by category) + mechanization (by category) + water (zone-specific tariffs × crop needs)
- **Climate data**: NASA POWER temperature and precipitation per zone
- **Soil moisture**: Copernicus C3S root-zone soil moisture
- **Social network**: NetworkX-based knowledge propagation (small-world, random, scale-free)
- **Interactive dashboard**: Solara web interface
## Quick Start
```bash
pip install -r requirements.txt
```
Open `simulation.ipynb` in Jupyter or VS Code. The main simulation parameters are set in the `SIM_CONFIG` dataclass (see the first code cell):
```python
from dataclasses import dataclass
@dataclass
class SIM_CONFIG:
n_agents: int = 100 # Number of agents (farmers)
n_seasons: int = 30 # Number of seasons to simulate
shared_strategy: str = "both" # 'zone', 'neighbor', or 'both'
use_neighbor_graph: bool = True
# ... other parameters ...
```
To change the number of agents, update `n_agents` in the config cell. For example, to run with 200 agents:
```python
cfg = SIM_CONFIG(n_agents=200)
model, df, hist_df = run_sim(cfg)
```
Run all cells to execute the simulation and export results.
Optional — launch the interactive dashboard (from the folder containing `dashboard_solara.py`):
```bash …