Yu_Thomas_Gas_Station
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This section could give a general understanding of what the model is trying to show or explain.
HOW IT WORKS
This section could explain what rules the agents use to create the overall behavior of the model.
HOW TO USE IT
This section could explain how to use the model, including a description of each of the items in the interface tab.
THINGS TO NOTICE
This section could give some ideas of things for the user to notice while running the model.
THINGS TO TRY
This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.
EXTENDING THE MODEL
This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.
NETLOGO FEATURES
This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.
RELATED MODELS
This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.
CREDITS AND REFERENCES
This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.
Comments and Questions
globals [ grid-x-b grid-y-b roads homes gasstation gas-time ] turtles-own [ car energy home-x home-y dest-x dest-y fdest-x fdest-y direction intersection gas-refuel-time ] patches-own [ count-neighbors count-homes gas-level gas-price ] to setup clear-all setup-globals setup-patches setup-homes setup-gasstation setup-dest set-default-shape turtles "car" ask patches [ if pcolor = green [ sprout 1 ] ;; sprout a car on each home if pcolor = grey [ set gas-level 2000 set gas-price random-normal 3.5 1 ] ;; set oil level of each gas station ] ask patches [ if pcolor = grey [ set plabel gas-level set plabel-color black ] ] ask turtles [ set energy 300 set car turtles set home-x [pxcor] of min-one-of (patches with [pcolor = green]) [distance myself] set home-y [pycor] of min-one-of (patches with [pcolor = green]) [distance myself] set car turtles set dest-x [pxcor] of one-of (patches with [pcolor = orange]) set dest-y [pycor] of one-of (patches with [pcolor = orange]) move-to min-one-of (roads with [not any? turtles-on self]) [distance myself] ] end to setup-globals set grid-x-b world-width / grid-size set grid-y-b world-width / grid-size end to setup-patches ask patches [ set pcolor brown] set roads patches with [ ( floor (( pxcor + max-pxcor - floor (grid-x-b - 1)) mod grid-x-b) = 0 ) or (floor((pycor + max-pycor) mod grid-y-b) = 0 ) ] ask roads [ set pcolor white ] end to setup-homes ask patches [ set count-neighbors count neighbors4 with [pcolor = white] ] ask patches [ if pcolor = brown and count-neighbors > 0 [ if random-float 10 > (10 - home-prob) [ set pcolor green ] ] ] set homes patches with [ pcolor = green ] end to setup-gasstation ask patches [ set count-neighbors count neighbors4 with [pcolor = white] ] ask patches [ if pcolor = brown and count-neighbors = 1 [ if random-float 10 > (10 - gas-prob) [ set pcolor grey ] ] ] set gasstation patches with [ pcolor = grey ] end to setup-dest ask patches [ set count-neighbors count neighbors4 with [pcolor = white] set count-homes count neighbors with [pcolor = green ] ] ask patches [ if pcolor = brown and pcolor != grey and pcolor != green and count-neighbors > 0 and count-homes = 0 [ if random-float 10 > (10 - dest-prob) [ set pcolor orange ] ] ] end to setup-car-home end ;to update-gas-price ; set label " gas-price " ;end to go ask turtles [ facexy (dest-x) (dest-y) ifelse energy < 40 [ ifelse gas-searching-mode = "Mode 1" [ move-to-gas-mode1 ] [ if gas-searching-mode = "Mode 2" [ move-to-gas-mode2 ] ] ] [ ifelse distancexy dest-x dest-y < 1 ;; determine whether the car has reached its destination [ ifelse distancexy home-x home-y < 1 and distancexy home-x home-y = distancexy dest-x dest-y [ set dest-x [pxcor] of one-of (patches with [pcolor = orange]) ;; if it is a home, it assignes a new destination set dest-y [pycor] of one-of (patches with [pcolor = orange]) ] [ set dest-x home-x ;; if it is a home, it assignes a new destination set dest-y home-y ] ] [ move-easy ] ] ] ;; if it is an actual destination, it proceed to move closer to it ask patches [ check-gas-level1 update-label ] tick end to move-easy facexy (dest-x) (dest-y) if [pcolor] of patch-ahead 1 != white [ rt 45 ] if [pcolor] of patch-ahead 1 != white [ lt 90 ] fd 1 set energy energy - 1 end to move-to-gas-mode1 set fdest-x [pxcor] of min-one-of (patches with [pcolor = grey]) [distance myself] set fdest-y [pycor] of min-one-of (patches with [pcolor = grey]) [distance myself] facexy (fdest-x) (fdest-y) ; if [pcolor] of patch-ahead 1 != white ; [ rt 45 ] ; if [pcolor] of patch-ahead 1 != white ; [ lt 90 ] fd 1 set energy energy - 1 if distancexy fdest-x fdest-y < 1 [ set gas-level (gas-level - (300 - energy)) set energy 300 ] end to move-to-gas-mode2 if energy < 40 [ let cheapest-gas count patches in-radius (10) with [pcolor = gray] ifelse cheapest-gas < 2 [ set fdest-x [pxcor] of min-one-of (patches with [pcolor = grey]) [distance myself] set fdest-y [pycor] of min-one-of (patches with [pcolor = grey]) [distance myself] ] [ set fdest-x [pxcor] of min-one-of (patches in-radius 10 with [pcolor = grey]) [gas-price] set fdest-y [pycor] of min-one-of (patches in-radius 10 with [pcolor = grey]) [gas-price] ] ] facexy (fdest-x) (fdest-y) ; if [pcolor] of patch-ahead 1 != white ; [ rt 45 ] ; if [pcolor] of patch-ahead 1 != white ; [ lt 90 ] fd 1 set energy energy - 1 if distancexy fdest-x fdest-y < 1 [ set gas-level (gas-level - (300 - energy)) set energy 300 ] end to check-gas-level1 if gas-level < 300 [ set gas-level 2000 ;; gas is replenished set gas-time ticks set gas-price ( gas-price + (ticks - 1000) / 1000 )] ;; formula needs adjustment end to update-label if pcolor = grey [ set plabel gas-level ] end
There are 4 versions of this model.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.