runningqert.blogg.se

Netlogo traffic simulation
Netlogo traffic simulation









netlogo traffic simulation netlogo traffic simulation

Move-to one-of roads with Īsk current-intersection Find a road patch without any turtles on it and place the turtle there. Ifelse (floor ((pxcor + max-pxcor - floor(grid-x-inc - 1)) mod grid-x-inc) = 0) [ if the turtle is on a vertical road (rather than a horizontal one) Initialize the turtle variables to appropriate values and place the turtle on an empty road patch. Set my-column floor ((pxcor + max-pxcor) / grid-x-inc) Set my-row floor ((pycor + max-pycor) / grid-y-inc) Make all the traffic lights start off so that the lights are red Give the intersections appropriate values for the intersection?, my-row, and my-column (floor ((pxcor + max-pxcor - floor (grid-x-inc - 1)) mod grid-x-inc) = 0) and (floor ((pycor + max-pycor) mod grid-y-inc) = 0) (floor ((pxcor + max-pxcor - floor (grid-x-inc - 1)) mod grid-x-inc) = 0) or initialize the global variables that hold patch agentsets initialize the patch-owned variables and color the patches to a base-color and initialize the traffic lights to one setting Make the patches have appropriate colors, set up the roads and intersections agentsets, don't make acceleration 0.1 since we could get a rounding error and end up on a patch boundary Set grid-y-inc world-height / grid-size-y Set current-intersection nobody just for now, since there are no intersections yet Initialize the global variables to appropriate values Set work one-of goal-candidates with of myself ] choose at random a location for work, make sure work is not located at same location as house choose at random a location for the house Set-car-color slower turtles are blue, faster ones are colored cyan Now create the cars and have each created car call the functions setup-cars and set-car-color "number of cars by lowering the NUM-CAR slider. "There are too many cars for the amount of " Pcolor = 38 and any? neighbors with Īsk one-of intersections those patches with the background color shade of brown and next to a road Make an agentset of all patches where there can be a house or road Setup-patches ask the patches to draw themselves and set up a few variables Create num-cars of turtles if there are enough road patches for one turtle to Initialize the display by giving the global and patch variables initial values. 1 for non-intersection patches.Īuto? whether or not this intersection will switch automatically. My-column the column of the intersection counting from the upper left corner of the My-row the row of the intersection counting from the upper left corner of the Green-light-up? true if the green light is above the intersection. Intersection? true if the patch is at the intersection of two roads Wait-time the amount of time since the last time a turtle has moved Up-car? true if the turtle moves downwards and false if it moves to the right Roads agentset containing the patches that are roads Intersections agentset containing the patches that are intersections Num-cars-stopped the number of cars that are stopped during a single pass thru the go procedureĬurrent-intersection the currently selected intersection Grid-y-inc the amount of patches in between two roads in the y directionĪcceleration the constant that controls how much a car speeds up or slows down by if Grid-x-inc the amount of patches in between two roads in the x direction











Netlogo traffic simulation