Child of Waiting Bar Customers
Comments and Questions
## WHAT IS IT?
This is a HubNet activity that acts as a supplement to [this](http://modelingcommons.org/browse/one_model/3645) model.
This activity is a simplified version of the original model. It demonstrates D. Helbing and P. Molnar's social forces model in a bar setting. The point of this activity is for the participants to get as many drinks as possible while finding the best way to approach the bar.
## HOW IT WORKS
The model's core is based on D. Helbing and P. Molnar's social forces model. Each turtle has a force that drives it towards a direction (determined by the participants), a force that repels from the walls (white patches), and a force that repels from other turtles. The force from other turtles is reduced if they are not in the field of view.
## HOW TO USE IT
First click setup, the go to run the activity.
Explanation of variables:
- initial-pushiness, how pushy the turtles are
- mean-service-time, the mean time it takes for the bartender to serve a turtle
- service-plan, whether the bartender randomly chooses a turtle or chooses the one thats been waiting the longest to serve
## THINGS TO NOTICE
- Is going straight for the bar counter the best way to get a drink? What if there are many participants in the activity?
- Do you get frustrated with everyone trying to push their way to the front?
## THINGS TO TRY
Try the different service-plans to see how participants feel about each one. Do they prefer one over the other?
## EXTENDING THE MODEL
This model might benefit from extending it so that participants who stick with a single direction will gain extra pushiness over time but will lose it once they change directions. The strategy that they use would be interesting to see.
## RELATED MODELS
This HubNet activity is related to [this](http://modelingcommons.org/browse/one_model/3645) model.
## CREDITS AND REFERENCES
[Modeling Commons URL](http://modelingcommons.org/browse/one_model/3645)
This model is based on the [social forces model](http://pre.aps.org/abstract/PRE/v51/i5/p4282_1)
turtles-own [ user-id ;; the id of the logged in user drinks-had ;; the number of drinks i've had start-of-thirst ;; how long has it been since the last drink 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 prev-desired-direction ;; my previous 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 ] ;; set everything up to setup cp cd clear-output set-default-shape turtles "circle" ;; 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 activity to go ;; run the social forces model on thirsty turtles ;; calculate the forces first... ask turtles [ 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 [ move-turtle ] ;; 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 ] ] listen-clients tick end ;; helper functions ;; "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 vx 0 set vy 0 set start-of-thirst ticks set drinks-had drinks-had + 1 set pushiness 0 ;; update the client with the number of drinks had hubnet-send user-id "drinks" drinks-had ] ] 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] let field-of-view 200 let c .5 ifelse (desiredx * (- forcex) + desiredy * (- forcey)) >= (magnitude forcex forcey) * cos (field-of-view / 2) [ report 1 ] [ report c] end ;; social forces functions ;; move the turtle according to the rules of the social forces model to move-turtle let max-speed 0.2 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 let v0 2.1 let sigma 0.3 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 let u0 10 let r 0.2 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 let tau 10 let max-speed 0.2 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 ;; hubnet functions ;; handle any incoming messages to listen-clients while [ hubnet-message-waiting? ] [ hubnet-fetch-message ifelse hubnet-enter-message? [ create-new-turtle ] [ ifelse hubnet-exit-message? [ remove-turtle ] [ ask turtles with [user-id = hubnet-message-source] [ execute-command hubnet-message-tag ] ] ] ] end ;; create a turtle to create-new-turtle create-turtles 1 [ set user-id hubnet-message-source set label user-id setxy 0 0 set start-of-thirst ticks set drinks-had 0 set base-pushiness initial-pushiness set vx 0 set vy 0 ;; update the client with the number of drinks hubnet-send user-id "drinks" drinks-had ] end ;; have a turtle execute a command to execute-command [command] if command = "up" [ set desired-direction 0 set pushiness base-pushiness stop ] if command = "down" [ set desired-direction 180 set pushiness base-pushiness stop ] if command = "left" [ set desired-direction 270 set pushiness base-pushiness stop ] if command = "right" [ set desired-direction 90 set pushiness base-pushiness stop ] end ;; remove a turtle to remove-turtle ask turtles with [user-id = hubnet-message-source] [ die ] end ;; hubnet startup to startup hubnet-reset end
There are 2 versions of this model.
Parent: Waiting Bar Customers
This model does not have any descendants.