3.12. Lab 11: Herds, flocks, and traffic jams¶
Due Date: 11:59pm March 12, 2024 Labs should be submitted as a single Jupyter notebook to CourseLink Dropbox This lab counts for 4% of the final grade |
To do in advance of this lab:
Make sure you have run the code in Allen Downey’s Chapter 10 notebook.
3.12.1. Exercises¶
Complete the exercises corresponding to Exercise 10.1 – 10.2 in Chapter 10 of Think Complexity (version 2):
In the traffic jam simulation, define a class,
BetterDriver
, that inherits fromDriver
and overrideschoose_acceleration
. See if you can define driving rules that do better than the basic implementation inDriver
. You might try to achieve higher average speed, or a lower number of collisions.(BONUS) The code for my Jupyter port of Downey’s Boid implementation is in
Boids7nb.ipynb
in thelab11
directory of the course repository. If you attempt this exercise, make sure you read the warning at the beginning of the notebook and do not proceed unless you understand it. This warning only pertains to running code on the ENGG*3130 Virtual Lab. This does not apply to running locally.Run the notebook. It should create an animated display showing Boids, as white cones, circling a red sphere, which is the carrot. If you click and move the mouse, you can move the carrot and see how the Boids react.
Read the code to see how the parameters control Boid behaviors. Experiment with different parameters. What happens if you “turn off” one of the behaviors by setting its weight to 0?
To generate more bird-like behavior, Flake suggests adding a behavior to maintain a clear line of sight; in other words, if there is another bird directly ahead, the Boid should move away laterally. What effect do you expect this rule to have on the behavior of the flock? Implement it and see.
3.12.2. Submission¶
Please submit one or two Jupyter notebooks depending on whether or not you
attempted the bonus. There is a placeholder in the chap10
notebook for your
work. You can simply append your work to the end of the Boids7nb
notebook if
you attempt that question.