1- """
2- Flockers
3- =============================================================
4- A Mesa implementation of Craig Reynolds's Boids flocker model.
1+ """A Mesa implementation of Craig Reynolds's Boids flocker model.
2+
53Uses numpy arrays to represent vectors.
64"""
75
119
1210
1311class Boid (mesa .Agent ):
14- """
15- A Boid-style flocker agent.
12+ """A Boid-style flocker agent.
1613
1714 The agent follows three behaviors to flock:
1815 - Cohesion: steering towards neighboring agents.
@@ -36,10 +33,10 @@ def __init__(
3633 separate = 0.015 ,
3734 match = 0.05 ,
3835 ):
39- """
40- Create a new Boid flocker agent.
36+ """Create a new Boid flocker agent.
4137
4238 Args:
39+ model: a Model instance
4340 speed: Distance to move per step.
4441 direction: numpy vector for the Boid's direction of movement.
4542 vision: Radius to look around for nearby Boids.
@@ -59,10 +56,7 @@ def __init__(
5956 self .match_factor = match
6057
6158 def step (self ):
62- """
63- Get the Boid's neighbors, compute the new vector, and move accordingly.
64- """
65-
59+ """Get the Boid's neighbors, compute the new vector, and move accordingly."""
6660 neighbors = self .model .space .get_neighbors (self .pos , self .vision , False )
6761 n = 0
6862 match_vector , separation_vector , cohere = np .zeros ((3 , 2 ))
@@ -84,9 +78,7 @@ def step(self):
8478
8579
8680class BoidFlockers (mesa .Model ):
87- """
88- Flocker model class. Handles agent creation, placement and scheduling.
89- """
81+ """Flocker model class. Handles agent creation, placement and scheduling."""
9082
9183 def __init__ (
9284 self ,
@@ -102,18 +94,21 @@ def __init__(
10294 match = 0.05 ,
10395 simulator = None ,
10496 ):
105- """
106- Create a new Flockers model.
97+ """Create a new Flockers model.
10798
10899 Args:
100+ seed: seed for random number generator
109101 population: Number of Boids
110- width, height: Size of the space.
102+ width: the width of the space
103+ height: the height of the space
111104 speed: How fast should the Boids move.
112105 vision: How far around should each Boid look for its neighbors
113- separation: What's the minimum distance each Boid will attempt to
114- keep from any other
115- cohere, separate, match: factors for the relative importance of
106+ separation: What's the minimum distance each Boid will attempt to keep from any other
107+ cohere: the relative importance of matching neighbors' positions'
108+ separate: the relative importance of avoiding close neighbors
109+ match: factors for the relative importance of
116110 the three drives.
111+ simulator: a Simulator Instance
117112 """
118113 super ().__init__ (seed = seed )
119114 self .population = population
@@ -146,6 +141,7 @@ def __init__(
146141 self .schedule .add (boid )
147142
148143 def step (self ):
144+ """Run the model for one step."""
149145 self .schedule .step ()
150146
151147
0 commit comments