P2P Sugarscape

Simulation

Simulating Society Through Agents


Overview


Sugarscape is a classic agent-based model where autonomous agents move around a 2D grid, gather resources, consume energy, age, and die, creating lifelike patterns of wealth, survival, and emergence.

For this project, I rebuilt the Sugarscape simulation as a distributed system instead of running it on a single machine. The goal was to take a traditionally single-node simulation and split computation across multiple nodes, making it scalable, fault-tolerant, and fully peer-to-peer.

What I Built


Instead of running Sugarscape on one computer, we distributed the simulation across four laptops for 14 team members, with nodes working together like a small supercomputer cluster. Each node handled a portion of the environment and exchanged updates over a P2P network.


The system included:


  1. Distributed Job Execution


   The Sugarscape grid and agent tasks were sliced into “jobs.”


   Each node was assigned jobs and executed its part of the simulation.


   A shared job ledger tracked:


   jobs completed


   jobs in progress


   jobs yet to run


   This ledger was broadcast along with heartbeats to keep the entire cluster in sync.


  1. Fault Tolerance Through Heartbeats


Each node sent out periodic heartbeat messages to let others know it was alive. If a node stopped responding:


   other nodes detected the failure,


   checked the last shared ledger,


   reassigned unfinished jobs automatically.


This helped the system recover from crashes without restarting the simulation.


3. Leader Election With Bully Algorithm


We implemented the Bully Algorithm to manage coordination:


   One node acts as the coordinator to assign and collect jobs.


   If the coordinator dies, the remaining nodes run an election.


   The node with the highest ID becomes the new leader.


   This ensured the system always had an active coordinator, even after failures.


4. Makefile-Based Job Distribution


We used Unix Makefiles to automate running tasks across machines.
Each simulation step could be triggered, distributed, executed, and recombined using simple make commands.



Why This Project Matters


This project let us take a social-simulation model and push it into the world of real distributed systems. I learned how to build:


   Registration & login validation


   peer-to-peer messaging


   heartbeat monitoring


   leader election


   distributed job scheduling


   fault-tolerant execution


   collaborative simulation across multiple physical nodes


It combined distributed systems, systems design, algorithms, and agent-based modeling into a hands-on, real-world engineering challenge.




Tech Stack


Python · Makefiles · Sockets/P2P Networking · Bully Algorithm · Heartbeat Protocols · Distributed Job Scheduling



Create a free website with Framer, the website builder loved by startups, designers and agencies.