My process for understanding the NetLogo code is to convert the method to python code and add comments to explain. I have done that with the following three methods
For all these cases there are a few things to note, the route variable is taken as 0 = top route, 1 = bottom route, and 2 is the route taken with braess road. Also there are methods and classes
that have not been defined when writing the python code, they have been assumed to exist as the project has not been started yet.
===================================================================================
#netlogo
to spawn-commuters ;turtle procedure
; spawns new commuters and sets up their properties
ifelse spawn-time > (250 / spawn-rate) [
ask patch -22 22 [
sprout-commuters 1 [
set cars-spawned cars-spawned + 1
set color one-of [99]
set birth-tick ticks
set ticks-here 1
set route new-route
ifelse route = 0 or route = 2 [ facexy 22 22 ][ facexy -22 -22 ]
set size 3.5
set shape one-of [ "car" "truck" ]
]
]
set spawn-time 0
]
[ set spawn-time spawn-time + 1 ]
end
#python
def spawn_commuters():
#waits the appropriate spawn time to create a new commuter
#spawn rate is given by the gui
if spawn_time > (250 / spawn_rate):
#make a new commuter in the starting patch with the values\
#in this case the method is in the start patch class, but this could be written in the World class and given the start patch as an argument
new_commuter = start_patch.sprout_commuter(color=random_color, birth_tick=ticks, ticks_here=1, route=new_route(), size=3.5, shape='square')
cars_spawned += 1
#check to see which route the commuter chose and face it in the correct direction
if new_commuter.route in [0,2]:
new_commuter.face('top_right')
else:
new_commuter.face('bottom_left')
#reset spawn timer
spawn_time = 0
else:
#increase spawn timer
spawn_time += 1
This method creates the commuters for the model. They spawn at the rate given in the gui and give them a route to compelte.