# Waiting Bar Customers

Model was written in NetLogo 5.0.4
•
Viewed 790 times
•
Downloaded 83 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

turtles-own [ thirsty? ;; am i thirsty? start-of-thirst ;; when did i start getting thirsty? drinks-had ;; the number of drinks i've had base-pushiness ;; the pushiness i am born with pushiness ;; how pushy i am at the moment vx ;; x velocity vy ;; y velocity desired-direction ;; my desired direction driving-forcex ;; my main motivating force driving-forcey obstacle-forcex ;; force exerted by obstacles obstacle-forcey territorial-forcex;; force exerted by neighbors territorial-forcey ] globals [ total-times ;; a list containing 10 accumulators for total time spent waiting by agents with the nth decile pushiness value total-counts ;; a list containing 10 accumulators for total times agents with the nth decile of pushiness was served ] ;; Set up the view to setup ca set-default-shape turtles "circle" ;; initialize the globals set total-times (list 0 0 0 0 0 0 0 0 0 0) set total-counts (list 0 0 0 0 0 0 0 0 0 0) ;; create patrons create-turtles patrons [ setxy 0 0 set thirsty? false ;; give the turtles an initial nudge towards the goal let init-direction -90 + random 180 set vx sin init-direction set vy cos init-direction set drinks-had 0 set base-pushiness (random-float 1) * (upper-pushiness - lower-pushiness) + lower-pushiness set pushiness base-pushiness color-turtle ] ;; set boundary patches as walls ask patches with [pxcor = min-pxcor or pxcor = max-pxcor or pycor = min-pycor or pycor = max-pycor] [ set pcolor white ] ;; create the bar counter ask patches with [pycor = (max-pycor - 2) and abs pxcor < 3] [ set pcolor white ] ask patches with [pycor = (max-pycor - 1) and abs pxcor = 2] [ set pcolor white ] ;; create the goals ask patches with [pycor = (max-pycor - 1) and abs pxcor < 2] [ set pcolor green ] reset-ticks end ;; run the simulation to go ;; run the social forces model on thirsty turtles ;; calculate the forces first... ask turtles with [ thirsty? = true ] [ calc-desired-direction calc-driving-force calc-obstacle-force if any? other turtles [ calc-territorial-forces ] ] ;; then move the turtles and have them grow impatient if need be ask turtles with [ thirsty? = true ] [ move-turtle if get-impatient? [ grow-impatient ] ;; color the turtle to show how pushy it is color-turtle ] ;; control the arrival of new thirsty turtles if any? turtles with [thirsty? = false] [ wait-around ] ;; control the service rate of bartenders. follow an exponential distribution for service times let p 1 / mean-service-time if random-float 1 < p [ ask one-of patches with [pcolor = green] [ service-patron ] ] tick end ;;;; Function for waiting around and other functions ;;;; ;; returns a value from 0-9 which is the decile of pushiness that an agent has to-report pushiness-index [pushiness-value] let p-index floor (((pushiness-value - lower-pushiness) / (upper-pushiness - lower-pushiness)) * 10) ifelse p-index = 10 ;; if it's 10, just treat it as 9 [ report 9 ] [ report p-index ] end ;; "serve" a turtle a drink to service-patron if any? turtles in-radius 2.5 [ ;; default to "random" service-plan let next-served one-of turtles in-radius 2.5 if service-plan = "waited-longest" [ set next-served max-one-of turtles in-radius 2.5 [ ticks - start-of-thirst ] ] ask next-served [ ;; reset the turtle setxy 0 0 set thirsty? false let init-direction -90 + random 180 set vx sin init-direction set vy cos init-direction set drinks-had drinks-had + 1 set pushiness base-pushiness let p-index pushiness-index pushiness ;; increment the corresponding elements in the global arrays to keep track of wait times and service counts set total-counts replace-item p-index total-counts ((item p-index total-counts) + 1) set total-times replace-item p-index total-times ((item p-index total-times) + (ticks - start-of-thirst)) if get-belligerent? [ set pushiness min (list upper-pushiness (base-pushiness + belligerence-rate * drinks-had)) ] color-turtle ] ] end ;; get more pushy over time to grow-impatient set pushiness pushiness + impatience-rate ;; make sure i'm not too pushy set pushiness min list pushiness upper-pushiness end ;; color a turtle according to its pushiness to color-turtle set color 19 - ((pushiness - lower-pushiness) / (upper-pushiness - lower-pushiness)) * 4 end ;; control when newly thirsty turtles arrive. follow an exponential distribution of inter-arrival times to wait-around let p 1 / mean-time-between-arrivals if random-float 1 < p [ ask one-of turtles with [thirsty? = false] [ set thirsty? true set start-of-thirst ticks ] ] end ;; helper function to find the magnitude of a vector to-report magnitude [x y] report sqrt ((x ^ 2) + (y ^ 2)) end ;; returns 1 if the angle between the desired vector and the force vector is within a threshold, else return c to-report field-of-view-modifier [desiredx desiredy forcex forcey] ifelse (desiredx * (- forcex) + desiredy * (- forcey)) >= (magnitude forcex forcey) * cos (field-of-view / 2) [ report 1 ] [ report c] end ;;;; Functions for calculating the social forces ;;;; ;; move the turtle according to the rules of the social forces model to move-turtle let ax driving-forcex + obstacle-forcex + territorial-forcex let ay driving-forcey + obstacle-forcey + territorial-forcey set vx vx + ax set vy vy + ay ;; scale down the velocity if it is too high let vmag magnitude vx vy let multiplier 1 if vmag > max-speed [set multiplier max-speed / vmag] set vx vx * multiplier set vy vy * multiplier set xcor xcor + vx set ycor ycor + vy end ;; find the territorial force according to the social forces model to calc-territorial-forces set territorial-forcex 0 set territorial-forcey 0 ask other turtles with [distance myself > 0] [ let to-agent (towards myself) - 180 let rabx [xcor] of myself - xcor let raby [ycor] of myself - ycor let speed magnitude vx vy let to-root ((magnitude rabx raby) + (magnitude (rabx - (speed * sin desired-direction)) (raby - (speed * cos desired-direction)))) ^ 2 - speed ^ 2 if to-root < 0 [set to-root 0] let b 0.5 * sqrt to-root let agent-force (- v0) * exp (- b / sigma) ask myself [ let agent-forcex agent-force * (sin to-agent) let agent-forcey agent-force * (cos to-agent) ;; modify the effect this force has based on whether or not it is in the field of view let vision field-of-view-modifier driving-forcex driving-forcey agent-forcex agent-forcey set territorial-forcex territorial-forcex + agent-forcex * vision set territorial-forcey territorial-forcey + agent-forcey * vision ] ] end ;; find the obstacle force of the turtle according to the social forces model to calc-obstacle-force set obstacle-forcex 0 set obstacle-forcey 0 ask patches with [pcolor = white] [ let to-obstacle (towards myself) - 180 let obstacle-force (- u0) * exp (- (distance myself) / r) ask myself [ set obstacle-forcex obstacle-forcex + obstacle-force * (sin to-obstacle) set obstacle-forcey obstacle-forcey + obstacle-force * (cos to-obstacle) ] ] end ;; find the driving force of the turtle to calc-driving-force set driving-forcex (1 / tau) * (max-speed * (sin desired-direction) - vx) * pushiness set driving-forcey (1 / tau) * (max-speed * (cos desired-direction) - vy) * pushiness end ;; find the heading towards the nearest goal to calc-desired-direction let goal min-one-of (patches with [pcolor = green]) [ distance myself ] set desired-direction towards goal end

There are 6 versions of this model.

## Attached files

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

5-19-13_progress.docx | word | Progress Report | over 11 years ago, by wesley sun | Download |

5-27_progress.docx | word | Progress Report | over 11 years ago, by wesley sun | Download |

6-3_progress.docx | word | Progress Report | over 11 years ago, by wesley sun | Download |

EECS 472 Slam Slides - Wesley Sun.pptx | powerpoint | poster slam slides | over 11 years ago, by wesley sun | Download |

Pushy Jerks.pdf | Project Poster | over 11 years ago, by wesley sun | Download | |

Waiting Bar Customers.png | preview | model preview | over 11 years ago, by wesley sun | Download |

WesleySun_FinalPaper.docx | word | final project paper | over 11 years ago, by wesley sun | Download |

WesleySun_May13.docx | word | Progress Report | over 11 years ago, by wesley sun | Download |

Abhishek Bhatia

## Escape Panic Netlogo Model

I wish to know if there is a model of "Simulating Dynamical Features of Escape Panic" (http://arxiv.org/pdf/cond-mat/0009448.pdf) available in NetLogo.

## Posted about 10 years ago