An implementation of Craig Reynolds's Boids flocker model. Agents (simulated birds) try to fly towards the average position of their neighbors and in the same direction as them, while maintaining a minimum distance. This produces flocking behavior.
This model tests Mesa's continuous space feature, and uses numpy arrays to represent vectors. It also demonstrates how to create custom visualization components. This model also fixes the issue of agents condensing in clusters in the example model of mesa by rewriting the step update logic.
Note that you have two components you can turn on: 'Jiggle Points', which separates the agents visually / positionally, and 'Set seed to 10?' which allows you to set a seed.
BE SURE TO INSTALL REQUIREMENTS FIRST!
pip install -r requirements.txt
Launch the model:
python Flocker_Server.py
Then open your browser to http://127.0.0.1:8521/ and press Reset, then Run.
- flocking/model.py: Core model file; contains the BoidModel class.
- flocking/boid.py: The Boid agent class.
- flocking/SimpleContinuousModule.py: Defines
SimpleCanvas
, the Python side of a custom visualization module for drawing agents with continuous positions. - flocking/simple_continuous_canvas.js: JavaScript side of the
SimpleCanvas
visualization module; takes the output generated by the PythonSimpleCanvas
element and draws it in the browser window via HTML5 canvas. - flocking/server.py: Sets up the visualization; uses the SimpleCanvas element defined above
- run.py Launches the visualization.
- [Flocker Test.ipynb](Flocker Test.ipynb): Tests the model in a Jupyter notebook.
- See [NetLogo version of model here]. (https://ccl.northwestern.edu/netlogo/models/Flocking)
=======
mesa runserver
- Visit your browser: http://127.0.0.1:8521/
- In your browser hit run