# Parking Space Simulation

Model was written in NetLogo 5.0.3
•
Viewed 1220 times
•
Downloaded 78 times
•
Run 0 times

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)

## Comments and Questions

Click to Run Model

globals [pk revenue ] turtles-own [gdist xdest ydest parked start finish navval ] patches-own [occupied navvalue closed] to setup clear-all set stay (floor ( budget - fixedrate ) / rate ) * 60 + fixedstay ask patches with [pxcor = 16][set navvalue 0 set pcolor green] ask patches with [pycor = 16][set navvalue 0 set pcolor green] ask patches with [pxcor = -16][set navvalue 0 set pcolor green] ask patches with [pycor = -4][set navvalue 0 set pcolor green] if complexmap [ ask patches with [pycor = -1 ][set navvalue 0 set pcolor green] ask patches with [pxcor = 1 and pycor = -1 ] [set pcolor black] ask patches with [pycor = -4][set navvalue 0 set pcolor green] ] ;corner ask patches with [pxcor = -15 and pycor = 16][set navvalue 0 set pcolor black] ask patches with [pxcor = -16 and pycor = 16][set navvalue 0 set pcolor black] ask patches with [pxcor = -16 and pycor = 15][set navvalue 0 set pcolor black] foreach [-16 -11 -6 -1 4 ][ ask patches with [pxcor = ? and pycor < 13 and pycor > -1][set navvalue 0 set pcolor green] ] let i 1 foreach [12 10 8 6 4 2 0 ][ ask patches with [pxcor = -15 and pycor = ?] [set pcolor pink set navvalue 100 * i + 1] set i i + 1 ] set i 1 foreach [ 12 10 8 6 4 2 0 ][ ask patches with [pxcor = -12 and pycor = ?] [set pcolor pink set navvalue 100 * i + 2] set i i + 1 ] set i 1 foreach [ 12 10 8 6 4 2 0 ][ ask patches with [pxcor = -10 and pycor = ?] [set pcolor pink set navvalue 100 * i + 3] set i i + 1 ] set i 1 foreach [ 12 10 8 6 4 2 0 ][ ask patches with [pxcor = -7 and pycor = ?] [set pcolor pink set navvalue 100 * i + 4] set i i + 1 ] set i 1 foreach [12 10 8 6 4 2 0 ][ ask patches with [pxcor = -5 and pycor = ?] [set pcolor pink set navvalue 100 * i + 4] set i i + 1 ] set i 1 foreach [ 12 10 8 6 4 2 0 ][ ask patches with [pxcor = -2 and pycor = ?] [set pcolor pink set navvalue 100 * i + 3] set i i + 1 ] set i 1 foreach [12 10 8 6 4 2 0 ][ ask patches with [pxcor = 0 and pycor = ?] [set pcolor pink set navvalue 100 * i + 2] set i i + 1 ] set i 1 foreach [12 10 8 6 4 2 0 ][ ask patches with [pxcor = 3 and pycor = ?] [set pcolor pink set navvalue 100 * i + 1] set i i + 1 ] set i 1 foreach [ 12 10 8 6 4 2 0 ][ ask patches with [pxcor = 5 and pycor = ?] [set pcolor pink set navvalue 100 * i + 0] set i i + 1 ] ask patches with [pxcor = 9 and pycor < 13] [set pcolor green set navvalue 0] set i 1 foreach [-12 -10 -8 -6][ ask patches with [pycor = -3 and pxcor = ?] [set pcolor pink set navvalue 1910 + i] set i i + 1 ] foreach [4 2 0][ ask patches with [pycor = -3 and pxcor = ?] [set pcolor pink set navvalue 1900 + i] set i i + 1 ] ask turtles [die] ask patches [set plabel round navvalue] reset-ticks end to arrive let interval 1 / ( 2 ^ (8 * rate / 60) - 1 ) if ( int (ticks / 30) mod int (1 / interval) = 0) [ if count turtles < 70[ create-turtles 1 [setxy -16 16 set gdist 0 set shape "car" ] ask patches with [pcolor = black][ set closed 0] ask patches with [pcolor = orange] [set pcolor black set navvalue 0] ] foreach sort turtles with [xcor = -16 and ycor = 16] [ if count turtles <= 70[ go ? ] ] ] end to parkall reset-ticks while [ticks / 30 <= operatingtime ] [ arrive foreach sort turtles with [ start + stay * 30 <= ticks and navval > 0] [ ask ? [ ifelse ticks >= stay * 30 + start [ set finish ticks set xdest 6 set ydest 15 set gdist 0 set parked 0 ask patch xcor ycor [set occupied 0 set closed 0 ] let len (finish - fixedstay * 30 - start) set revenue revenue + len * rate / 1800 + fixedrate print "REVENUE: " show revenue print "TIME: " show len ] [ if ticks - start > 1 [ set revenue revenue + fixedrate ] ] ] set pk 0 while [pk != 1][ create-track2 ? ] ask ? [die] ask patch 6 15 [set occupied 0 set pcolor black] ifelse (count turtles with [parked = 1 ] < 1 * 70 ) and ticks / 30 <= operatingtime [ arrive ][ if random-float 1 < 0.1 [arrive] ] ] if ticks / 30 >= operatingtime [ leave-all ] tick ] end to go [ i ] ask i [ print "Turtle Number : " ;show i set pk parked set start ticks ] while [pk != 1][ dest i create-track2 i ] end to dest [ n ] let nav [] let destx [] let desty [] ask n [ foreach sort patches with [pcolor = pink and occupied != 1][ ask ? [ set nav lput navvalue nav set destx lput pxcor destx set desty lput pycor desty ] ] let mmax max nav ;print "Maximum distance" ;print mmax let mpos position mmax nav set navval mmax set xdest item mpos destx set ydest item mpos desty facexy xdest ydest print "XY DEST" print xdest print ydest ] end to create-track2 [n] ask n [ let mytdist [] let ggdist gdist let gdestx xdest let gdesty ydest let prvx xcor let prvy ycor show xdest show ydest let xc [] let yc [] let mygdist [] let myncount [] let xpos 0 let ypos 0 let nc 0 let nc3 0 let mxt [] ;let nc1 0 ;if gdist < 10 [ ; ask patch-ahead 1 [ if pcolor = green [set nc1 1]] ;] ask neighbors with [closed != 1 and ((pcolor = black) or (pxcor = gdestx and pycor = gdesty and occupied != 1))] [ ;ask neighbors with [closed != 1 and pcolor != green ] [ ;and ((pcolor = black ) or (pxcor = gdestx and pycor = gdesty and occupied != 1))] [ if occupied != 1 [ set mxt lput navvalue mxt let nc1 count neighbors with [pcolor = green] let nc2 count neighbors with [pcolor = pink and occupied = 0] set nc3 count neighbors with [pxcor = gdestx and pycor = gdesty] set nc nc1 + nc2 - nc3 let pxc pxcor let pyc pycor set xpos pxc set ypos pyc if nc < 5 or (pxcor = gdestx and pycor = gdesty) [ ifelse pcolor = black [ ;set mytdist lput (ggdist + (dist pxcor pycor gdestx gdesty) + (dist pxcor pycor prvx prvy ) + navvalue * 5 ) mytdist set mytdist lput (ggdist + (distancexy gdestx gdesty) + (dist pxcor pycor prvx prvy ) + navvalue * 5 ) mytdist ][ set mytdist lput (ggdist + (dist pxcor pycor prvx prvy ) ) mytdist ] ;set mygdist lput (ggdist + (dist pxcor pycor gdestx gdesty) + (dist pxcor pycor prvx prvy ) ) mygdist set mygdist lput (ggdist + (dist pxcor pycor prvx prvy ) ) mygdist let xcoord pxcor set xc lput xcoord xc let ycoord pycor set yc lput ycoord yc print "NEIGHBORS" show pxcor show pycor set myncount lput count neighbors myncount ] ] ] if length myncount < 1 or max mxt >= 2 [ ask patches with [closed = 1 and pcolor = orange] [set closed 0 set pcolor black] ] if length mytdist > 0 [ let mx min mytdist let px position mx mytdist ;let nc position mx myncount set xpos item px xc set ypos item px yc set xcor item px xc set ycor item px yc ask patches with [pcolor = black and pxcor = xpos and pycor = ypos] [set navvalue navvalue + 1] set gdist item px mygdist print "Current Path: " show xpos show ypos if xcor = gdestx and ycor = gdesty [ set parked 1 set pk parked ] ifelse parked = 1 [ ask patch xpos ypos [set occupied 1 set closed 1 ] ask patches with [pcolor = orange] [set pcolor black] ask patches with [pcolor = black] [set closed 0 set navvalue 0 set plabel navvalue show plabel] ask patch xpos ypos [set pcolor pink ] print "Closed!!!" ][ ask patch xpos ypos [set closed 1 set pcolor orange set plabel navvalue show plabel ] ] ] ] tick end to leave [n] ask n [set finish ticks set xdest 6 set ydest 15 set gdist 0 set parked 0 ask patch xcor ycor [set occupied 0 set closed 0 ] ask patch xcor ycor [set occupied 0 set closed 0 ] ifelse finish >= fixedstay + start [set revenue revenue + (finish - (fixedstay * 30) - start) * rate / 1800 + fixedrate print "REVENUE: " show revenue] [ if ticks - start > 1 [ set revenue revenue + fixedrate ] ] ] set pk 0 while [pk != 1][ create-track2 n ] ask n [die] ask patch 6 15 [set occupied 0 set pcolor black] end to leave-all foreach sort turtles with [ parked = 1] [ leave ? ] end to-report dist [a b c d ] report abs(a - c) + abs( b - d) end

There are 4 versions of this model.

## Attached files

File | Type | Description | Last updated | |
---|---|---|---|---|

Parking Space Simulation.png | preview | Preview for 'Parking Space Simulation' | over 5 years ago, by Marco Lucena | Download |

This model does not have any ancestors.

This model does not have any descendants.

ali atik

## parameters explanation (Question)

can you please explane the role of each paramter in your model

## Posted over 1 year ago

Marco Lucena

## n is the car instance

n is the car instance

## Posted over 1 year ago

ali atik

## parameter explanation

thank you for your answer And what about the parameters rate / fixedrate

## Posted over 1 year ago