Dark theme

Control flow


So, we've now got num_of_agents coordinates moving twice. The final thing we need is to make our agent coordinations change an arbitrary number of times. Make a num_of_iterations variable just below the num_of_agents, and assign it the value 100. Can you now adapt the code so it moves the agents num_of_iterations times?

Hints: Remember that you can nest for-loops inside each other provided you use a different name for the index variables. In theory, you can get this running with one additional well-placed for loop clause looping through to num_of_iterations. In general, in ABM, all agents move one step at a time, rather than one agent moving a large number of steps, and then the next. This allows agents to interact as they move around, rather than where they end up. How might you nest loops to achieve this?


Get this working, and then look at your graph. Are any of the points missing? They may well be. Why do you think this is?


  1. Looping agents I
  2. Looping agents II
  3. This page
  4. Boundary effects <-- next
  5. Boundary solutions