Parking Model

No preview image

1 collaborator

Default-person david price (Author)

Tags

(This model has yet to be categorized with any tags)
Model group EECS 372-Spring 2011 | Visible to everyone | Changeable by everyone
Model was written in NetLogo 4.1.3 • Viewed 952 times • Downloaded 55 times • Run 10 times
Download the 'Parking Model' modelDownload this modelEmbed this model

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


WHAT IS IT?

Model of a population of cars trying to find parking spaces along a street. There are stores positioned along the street that the passengers of the cars are trying to go to. The cars attempt to minimize the distance that they park away from the store that they are going to, but they may end up driving past all open spaces in attempting to do this or instead settle for a spot far away in order to insure finding a spot. The model examines which store locations are the best for minimizing customer walking distance. It finds that, given the basic assumptions the modeler believes to be most accurate, positioning a store towards the end of a block minimizes the distance that cars have to park from the store-front. However, if certain assumptions, such as parking availability beyond the block, are not true, then it is much better to be in the middle or the front of the block.

HOW IT WORKS

At each tick, each car that is not parked moves forward one patch along the road. After moving, each car checks if the spot it can park at is full. If the spot is empty, the car checks whether it wants to park. If there is no side-street parking, the car only checks if there are any open spots closer to the store that it can see. If no such spots exist, the car parks, otherwise it moves on. If _side-street-parking?_ is selected, the car also makes sure that neither side offers better parking (on average) than its current location before deciding to park. When the car parks, it moves onto the patch above it and based on the distance to its destination determines how long it will be parked. When it has parked for its given duration, it leaves (dies). Cars that fail to park on the block also leave and either miss their destinations or park on other streets. Data on the average distance cars are parking from each store is recorded as well as how many cars are unable to find parking for each store.

HOW TO USE IT

This model can be used to represent a block containing one to five stores. Given the coding, stores must be removed or added sequentially, with higher-numbered stores only being included if all stores below it in number are also included.

The user can also pick the positioning of each store along the block. The number in the slider corresponds to which parking space the store entrance is located at, with one being the leftmost and fifty being the rightmost.

When side-street-parking? is turned on, it means that cars will park on another street if they don't find a spot along the block. They will park either to the left or the right of the block with their distance to the block being either avg-dist-left or avg-dist-right respectivally. When side-street-parking? is turned off, cars cannot park on side-streets and if they can't find a spot on the block are recorded as missed.

Vision refers to how many spots ahead a car can see. When "vision?" is turned on, they can only see either as far as the long-vision (20% of the cars) or the low-vision (80%). When "vision?" is off, cars can see the entire block.

time-in-# refers to how long customers stay in a given store on average which affects how long cars remain parked.

pop-# refers to the chance a car will be generated with passengers going to a given store. The exact probability for each store is pop-# divided by the number of stores.

The model ends after 10,000 ticks because an equilibrium has generally been reached before that point.

The two plots report the average distances that cars are parking from each store as well as the proportion of cars headed to each store that are unable to find spots.

THINGS TO NOTICE

When vision? is on and side-street-parking? is off, the store in the middle does the best and the store at the end does the worst. However, when side-street-parking? is turned back on, the store at the end of the block does the best. Why might that be?

As well, When vision? is on and side-street-parking? is off, most of the parking occurs near the first and second store, but the stores in the middle do the best, why is that?

What do cars do when they cannot see very far ahead and there is no side--street-parking and what does this create?

THINGS TO TRY

Changing the variables to create different combinations. Sometimes if you change a variable in a store beween the edge and the middle, the biggest effect occurs to its neigbor on the edge, rather than itself.

EXTENDING THE MODEL

An easy extension of this model would be to add code to compute the combined average distance for the stores and run a BehaviorSpace analysis from a societal or landlord perspective.

Harder extensions would be to expand the view to an entire block or multiple blocks in order to actually model cars parking on other streets, or have the number of cars being created become time dependent, to simulate fluctuations in the number of shoppers based on the time of day.

NETLOGO FEATURES

This model uses global variables as a means of passing information from one type of agent to another.

RELATED MODELS

Traffic Basic, Traffic Grid, El Farol

CREDITS AND REFERENCES

Author: David Price

Model created as final project for EECS 372 in Spring 2011, at Northwestern University

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [
  filled          ;; whether the spot a car is considering parking in is filled
  destin-x2       ;; x-location of a store
  time            ;; how long a customer is in a store
  all-filled      ;; whether all the visible parking spots better than the current one are open
  dist            ;; x-coordinate of a car
  dist-destin     ;; distance between a car and its destination
  dist-vision     ;; global variable of the farthest x-coordinate a car can see
  total-pop       ;; total popularity value of the stores
  num-stores
;;
  avg-dist-0      ;; average distance cars park from store-1
  avg-dist-1      ;; average distance cars park from store-2
  avg-dist-2      ;; average distance cars park from store-3
  avg-dist-3      ;; average distance cars park from store-4
  avg-dist-4      ;; average distance cars park from store-5
;;  
  miss-rate-0     ;; average distance cars park from store-1
  miss-rate-1     ;; average distance cars park from store-2
  miss-rate-2     ;; average distance cars park from store-3
  miss-rate-3     ;; average distance cars park from store-4
  miss-rate-4     ;; average distance cars park from store-5
]

breed [cars car]    
breed [stores store] 

cars-own [
  destin          ;; store where passengers are going
  destin-x        ;; x-coordinate of destin
  time-in-store   ;; amount of time will stay in store
  parked          ;; amount of time parked
  parking-time    ;; amount of time remains parked before leaving
  vision          ;; amount of spots car can see ahead if vision? turned on
]

stores-own [
  popularity      ;; variable that affects liklihood that cars will be coming to that store
  time-in         ;; average amount of time people stay in the store
  total-dist      ;; total amount of distance cars have parked away from the store
  avg-dist        ;; average distance cars park away from the store
  count-parked    ;; amount of cars that have parked on the street in one try (used if side-street-parking? is off)
  count-missed    ;; amount of cars unable to find a spot (used if side-street-parking? is off)
  miss-rate       ;; count-missed / ( count-parked + count-missed )
]

to setup
  clear-all
  setup-cars          
  setup-parking
  setup-stores
  determine-total-pop
  do-plots
end 

to setup-cars ;; sets the shape of the cars
  set-default-shape cars "car"
end  

to setup-parking ;; colors the parking spaces
  ask patches with [pycor = 0 and pxcor > -25] [set pcolor yellow]
end 

to setup-stores ;; sets the possible store locations white, and then places stores at user defined locations, also sets the shape of stores
  ask patches with [pycor > 0] [set pcolor white]
  create-stores 1 [
    set color red
    setxy (store-1-location - 25) 1
    set time-in time-in-1
  ]
  if add-store-2?[
    create-stores 1 [
      set color blue
      setxy (store-2-location - 25) 1
      set time-in time-in-2
    ]
  ]
  
  if add-store-3?[
    create-stores 1 [
      set color green
      setxy (store-3-location - 25) 1
      set time-in time-in-3
    ]
  ]
  
  if add-store-4?[
    create-stores 1 [
      set color orange
      setxy (store-4-location - 25) 1
      set time-in time-in-4
    ]
  ]
  
  if add-store-5?[
    create-stores 1 [
      set color violet
      setxy (store-5-location - 25)  1
      set time-in time-in-5
    ]
  ]
  set-default-shape stores "house"
end  

to go
  move-cars
  decide-to-park
  parked-time
  new-car-parking
  do-plots
  tick
  if ticks >= 10000 [
    stop
  ]
end 

to move-cars ;; moves the cars forward 1 patch along the road
  ask cars [
    if ycor = -1 [
      forward 1
    ]
  ]
end  

to decide-to-park ;; determines if a car parks 
  ask cars [ 
    ;; next line specifies that this only applies to cars on the road
    if ycor = -1 [
      ;; this section determines if the space a car is next to is full
      if patch-at 0 1 != nobody [
        ask patch-at 0 1 [
          ifelse count turtles-here = 0 [
            set filled 0
          ]
          [ set filled 1
          ]
        ]
      ]
      ;; if the spot is full and it is the last spot, either the car fails to find a spot or parks elsewhere
      if filled = 1 and xcor = 25 [
        ;; if there is side parking, the car parks elsewhere
        ifelse side-street-parking? [
          ask destin [  
            set count-parked count-parked + 1
            ;; this is determining whether the car parked to the left of the block or to the right based on which distance is shorter
            ifelse avg-dist-left + 2 * xcor <= avg-dist-right [
              set total-dist total-dist + avg-dist-left + xcor + 25
            ]
            [
              set total-dist total-dist + avg-dist-right - xcor + 25
            ]
          ]
        ]
        [ ;; in this case there is no other parking and the car does not find a spot on the first pass
          ask destin [
            set count-missed count-missed + 1
            set miss-rate count-missed / (count-missed + count-parked)
          ]
        ]
      die
      ]
      
      ;; the biggest factor in whether a car chooses to park is whether it has passed the store it is going to
      ;; this code applies when a car is at or has passed the destination
      ifelse side-street-parking? [ 
        ;; the car will only want to park in spaces that are closer than a side-street alternative on average
        if filled = 0 and xcor >= destin-x and xcor - destin-x <= avg-dist-left + destin-x + 25 and patch-at 0 1 != nobody [
          ;; if the space is open and closer than alternatives on other streets, car parks
          move-to patch-at 0 1
          ;; the distance to the destination and the amount of time consumers stay in the destination determine length of parking
          set parking-time distance destin + time-in-store
          ask destin [
            set count-parked count-parked + 1
            set total-dist total-dist + distance myself
            set avg-dist total-dist / count-parked
            set miss-rate count-missed / (count-missed + count-parked)
          ]
        ]
      ]
      ;; the car will always want to park if their is no side street parking and it has passed the destination
      [ if filled = 0 and xcor >= destin-x and patch-at 0 1 != nobody [
          move-to patch-at 0 1
          set parking-time distance destin + time-in-store
          ask destin [
            set count-parked count-parked + 1
            set total-dist total-dist + distance myself
            set avg-dist total-dist / count-parked
            set miss-rate count-missed / (count-missed + count-parked)
          ]
        ]
      ]
      
      ;; this code applies when a car has not passed its destination
      ;; first a turtle checks to see if better spots are available farther down
      if filled = 0 and xcor < destin-x [
        set dist xcor
        set dist-destin destin-x - xcor
        ;; vison affects how many spots a turtle can see
        ifelse vision? [
           set dist-vision xcor + vision
           ;; these lines ask all the spots closer than the current alternative and visible whether they are open, if any are open, the turtle doesn't park
           ask patches with [pxcor > dist and pxcor <= dist-vision and pxcor < (2 * dist-destin + dist) and pycor = 0] [
             if count turtles-here = 0 [
             set all-filled 0
             ]
           ]
        ]
        ;; when vision? is not on, cars ask all parking spots that are closer whether they are open
        [
          set dist-destin destin-x - xcor
          ask patches with [pxcor > dist and pxcor < (2 * dist-destin + dist) and pycor = 0] [
            if count turtles-here = 0 [
            set all-filled 0
            ]
          ]
        ]
      ]
      
      ;; whether other parking exists effects whether a turtle will choose to park
      ifelse side-street-parking? [
        ;; when side-street-parking? is on, a turtle will only consider a spot when no better alternative exists on the current street or a different street
        if filled = 0 and all-filled = 1 and destin-x - xcor <= avg-dist-right - destin-x + 25 and xcor < destin-x and patch-at 0 1 != nobody [
          move-to patch-at 0 1
          set parking-time distance destin + time-in-store
          ask destin [
            set count-parked count-parked + 1
            set total-dist total-dist + distance myself
            set avg-dist total-dist / count-parked
            set miss-rate count-missed / (count-missed + count-parked)
          ]
        ]
      ]
        ;; when side-street-parking? is off, a turtle will only consider if a better alternative exists on the current street
      [ if filled = 0 and all-filled = 1 and xcor < destin-x and patch-at 0 1 != nobody [
          move-to patch-at 0 1
          set parking-time distance destin + time-in-store
          ask destin [
            set count-parked count-parked + 1
            set total-dist total-dist + distance myself
            set avg-dist total-dist / count-parked
            set miss-rate count-missed / (count-missed + count-parked)
          ]
        ]
      ]
      ;; resets the global variable all-filled for the next car
      set all-filled 1
    ]
  ]
end 

to parked-time ;; keeps track of how long cars remain parked and removes them when their time is up
  ask cars [
    if ycor = 0 [
    set parked parked + 1
    if parked >= parking-time [die]
    ]
  ]
end 

to new-car-parking ;; generates a new car to start parking
  ;; generates cars based on the popularites of the stores
  if random 100 < total-pop / num-stores [
    create-cars 1 [
       setxy -25 -1 
       facexy -24 -1
       determine-total-pop 
       decide-destin
       create-link-with destin
       ask destin [set destin-x2 xcor]
       set destin-x destin-x2
       ask destin [set time (time-in + random time-in + random time-in) / 2]
       set time-in-store time
       set parking-time 1
       set parked 0
       ifelse random 100 < 70 [
         set vision low-vision
       ]
       [
         set vision long-vision
       ]
    ]
  ]
end 

to determine-total-pop ;; sets the total-pop the sum of the individual popularities of the stores
  ifelse add-store-5? [
    set total-pop pop-1 + pop-2 + pop-3 + pop-4 + pop-5
    set num-stores 5
  ]
    [ ifelse add-store-4? [
      set total-pop pop-1 + pop-2 + pop-3 + pop-4
      set num-stores 4
      ]
      [ ifelse add-store-3? [
        set total-pop pop-1 + pop-2 + pop-3
        set num-stores 3
        ]
        [ ifelse add-store-2? [
           set total-pop pop-1 + pop-2
           set num-stores 2
          ]
          [ set total-pop pop-1
            set num-stores 1 
          ]
        ]
      ]
    ]
end 

to decide-destin ;; turtle procedure, determines which destination a turtle will choose
  let temp-pop random total-pop
  ifelse temp-pop < pop-1 [
    set destin one-of stores with [color = red]
  ]
    [ ifelse temp-pop < pop-1 + pop-2 [
       set destin one-of stores with [color = blue]
      ]
      [ ifelse temp-pop < pop-1 + pop-2 + pop-3 [
         set destin one-of stores with [color = green]
        ]
        [ ifelse temp-pop < pop-1 + pop-2 + pop-3 + pop-4 [
            set destin one-of stores with [color = orange]
          ]
          [
            set destin one-of stores with [color = violet]
          ]
        ]
      ]
    ]
end 

to do-plots ;; plots the average distances cars are parking from stores and how many are unable to find spots
  ask stores with [color = red] [
    set miss-rate-0 miss-rate
    set avg-dist-0 avg-dist
  ]
  if add-store-2? [
    ask stores with [color = blue] [
      set miss-rate-1 miss-rate
      set avg-dist-1 avg-dist
    ]
  ]
  if add-store-3? [
    ask stores with [color = green] [
      set miss-rate-2 miss-rate
      set avg-dist-2 avg-dist
    ]
  ]
  if add-store-4? [
    ask stores with [color = orange] [
      set miss-rate-3 miss-rate
      set avg-dist-3 avg-dist
    ]
  ]
  if add-store-5? [
    ask stores with [color = violet] [
      set miss-rate-4 miss-rate
      set avg-dist-4 avg-dist
    ]
  ]
  set-current-plot "Average Distances"
    set-current-plot-pen "red-store"
      plot avg-dist-0
    set-current-plot-pen "blue-store"
      plot avg-dist-1 
    set-current-plot-pen "green-store"
      plot avg-dist-2 
    set-current-plot-pen "orange-store"
      plot avg-dist-3 
    set-current-plot-pen "violet-store"
      plot avg-dist-4
  set-current-plot "Miss Rates"
    set-current-plot-pen "red"
      plot miss-rate-0
    set-current-plot-pen "blue"
      plot miss-rate-1
    set-current-plot-pen "green"
      plot miss-rate-2 
    set-current-plot-pen "orange"
      plot miss-rate-3 
    set-current-plot-pen "violet"
      plot miss-rate-4
end 

There is only one version of this model, created over 13 years ago by david price.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.