Parking with reservation
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
THINGS TO NOTICE
(suggested things for the user to notice while running the model)
THINGS TO TRY
(suggested things for the user to try to do (move sliders, switches, etc.) with the model)
EXTENDING THE MODEL
(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)
NETLOGO FEATURES
(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)
RELATED MODELS
(models in the NetLogo Models Library and elsewhere which are of related interest)
CREDITS AND REFERENCES
(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)
Comments and Questions
Globals [ticks1 z w t walk avgwalk] turtles-own [parktimer distparked diststart disttraveled parked reservation_made] patches-own [empty reserved reserved-by] ;;parked is a boolean indicating whether a car is parked or not ;;parktimer is a counter that counts down to when a parked car departs ;;ticks2 is a counter that resets every time a new car is created ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ to setup clear-all setup-patches setup-turtles reset-ticks set w list "null" "Walking Distance" set t list "null" "Cruise Distance" set z round(random-exponential arrival_headway) end ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ to setup-patches ask patch 0 1 [ set pcolor 75] ask patches with [ pycor = -1] [ set empty true set reserved false set pcolor green if (pxcor mod 2 = 0) [ set pcolor green + 2 ] ] ask patches with [pycor = 0] [ set pcolor gray ] end ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ to setup-turtles ask n-of 1 patches with [pycor = -1] [ sprout 1 [set parktimer round((random-exponential depart_headway))] ] ;print max [count turtles-here] of patches ask turtles with [who > 0] [set color blue set shape "car" set heading 90 set pcolor red set empty false ] Ask turtle 0 [ set color orange set shape "car" set heading 90 set xcor (- startposition) ;;This xcor indicates the spot where someone will start searching set ycor 0 ;;ycor of 0 indicates this car is on the road set diststart abs(xcor) set parked false set reservation_made false reserve-closest-free-spot patch 0 -1 ] end ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ to advance ifelse ticks = 0 [] [ ;;This is the arrival rate/creation of new cars searching for parking ifelse (ticks1 >= z) [ create-turtles 1 [ set color orange - 2 set shape "car" set heading 90 set xcor (- startposition) set diststart abs( xcor) set parked false reserve-closest-free-spot patch 0 -1 set parktimer round(random-exponential depart_headway) ] set ticks1 0 set z round(random-exponential arrival_headway) ] [ set ticks1 ticks1 + 1 ] ] ask turtles with [ (color = orange) and (ycor = 0)] [ ifelse(not any? turtles-on patch-at 0 -1 and [reserved-by] of patch-at 0 -1 = self) [ right 90 forward 1 set pcolor red set parked true set distparked abs( xcor) set disttraveled (xcor + startposition) set w lput (abs(distparked)) w set t lput (disttraveled) t set parked true let walk1 but-first w set walk but-first walk1 set avgwalk (sum walk / length walk) ] [ forward 1 ] ] ask turtles with [ (color = orange - 2) and (ycor = 0)] [ set color orange ] ask turtles with [color = yellow] [ forward 1 ] ask turtles with [ycor = -1] ;;Departure code-- Cars will depart when their parktimer is 0. Parktimer is set randomly (exponentially) upon creation. [ ifelse (parktimer <= 0 and (not any? turtles-on patch-at 0 1 )) [ depart ] [ set parktimer (parktimer - 1) ] ] ask turtles with [ (xcor = max-pxcor) and (color = yellow)] [ die ] tick end ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ to depart set pcolor blue set parked false set reserved-by false set ycor 0 set heading 90 set color yellow end ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ to reserve-closest-free-spot [destination] let free-spots patches with [pycor = -1 and not is-turtle? reserved-by and not any? turtles-here] let closest-to-destination free-spots with-min [distance destination] let closest-to-me min-one-of closest-to-destination [distance myself] ask closest-to-me [ set reserved-by myself set pcolor magenta ] end ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is only one version of this model, created about 10 years ago by zhibin chen.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Parking with reservation.png | preview | Preview for 'Parking with reservation' | about 10 years ago, by zhibin chen | Download |
This model does not have any ancestors.
This model does not have any descendants.