Child of Waiting Bar Customers

No preview image

1 collaborator

Default-person wesley sun (Author)


(This model has yet to be categorized with any tags)
Child of model Waiting Bar Customers preview imageWaiting Bar Customers
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 46 times • Downloaded 5 times • Run 0 times
Download the 'Child of Waiting Bar Customers' modelDownload this modelEmbed this model

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


This is a HubNet activity that acts as a supplement to [this]( 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.


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.


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


- 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?


Try the different service-plans to see how participants feel about each one. Do they prefer one over the other?


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.


This HubNet activity is related to [this]( model.


[Modeling Commons URL](

This model is based on the [social forces model](

Comments and Questions

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

Important notice: Applets are deprecated

Click to Run Model

  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
  obstacle-forcex   ;; force exerted by obstacles
  territorial-forcex;; force exerted by neighbors

;; set everything up

to setup
  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 ]

;; run the activity

to go
  ;; run the social forces model on thirsty turtles
  ;; calculate the forces first...
  ask turtles
    if any? other turtles
      [ calc-territorial-forces ] 
  ;; then move the turtles and have them grow impatient if need be
  ask turtles
  ;; 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 ]

;; 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
;; helper function to find the magnitude of a vector

to-report magnitude [x y]
  report sqrt ((x ^ 2) + (y ^ 2))
;; 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]

;; 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
;; 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
;; 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)
;; 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

;; hubnet functions
;; handle any incoming messages

to listen-clients
  while [ hubnet-message-waiting? ]
    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 ]
;; 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
;; have a turtle execute a command

to execute-command [command]
  if command = "up"
    set desired-direction 0
    set pushiness base-pushiness 
  if command = "down"
    set desired-direction 180
    set pushiness base-pushiness 
  if command = "left"
    set desired-direction 270
    set pushiness base-pushiness 
  if command = "right"
    set desired-direction 90
    set pushiness base-pushiness 
;; remove a turtle

to remove-turtle
  ask turtles with [user-id = hubnet-message-source]
  [ die ]
;; hubnet startup

to startup

There are 2 versions of this model.

Uploaded by When Description Download
wesley sun 10 months ago added some comments to the code Download this version
wesley sun 10 months ago Corresponding HubNet activity. Download this version

Attached files

No files

Parent: Waiting Bar Customers

This model does not have any descendants.

Graph of models related to 'Child of Waiting Bar Customers'