Conference Socialization Section Model

Conference Socialization Section Model preview image

1 collaborator

Tags

conference 

Tagged by Konstantin Knyazkov almost 4 years ago

crowd 

Tagged by Konstantin Knyazkov almost 4 years ago

infection 

Tagged by Konstantin Knyazkov almost 4 years ago

rumors 

Tagged by Konstantin Knyazkov almost 4 years ago

social forces model 

Tagged by Konstantin Knyazkov almost 4 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.1.0 • Viewed 280 times • Downloaded 20 times • Run 0 times
Download the 'Conference Socialization Section 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.)


MODEL DESCRIPTION

This model is intended to simulate the coffee-brake and a socialization part of a conference. What do people do during this kind of sections? Eat, drink, and communicate. So, all of these activities are represented in the agents' behaviors.

Agent's behavior consists of wishes and current actions. Agent may 'walk', 'talk', 'listen'. Intentions are presented by 'wanna-walk', 'wanna-eat', 'wanna-talk' and 'wanna-listen' wishes. Wishes define goals of an agent. When a goal is reached an agent randomly chooses another wish (each behavior type has a corresponding probability).

As for the low-level movement model, the model incorporates the Social Forces Model (by Dirk Helbing, http://pre.aps.org/abstract/PRE/v51/i5/p42821), which is used in order to provide collision avoidance. The implementation of the SFM was taken from the "Waiting Bar Customers" model http://modelingcommons.org/browse/onemodel/3645.

Conversations are set by temporary links between talker and listeners.

As an addon, the model of infection propagation is implemented.

PURPOSE

The main purpose of the model is in use during educational master-class for students on theme of Agent-Based modeling and simulation in NetLogo.

As an example of a task, students were proposed to extend the base model with infection propagation model.

CREDITS AND REFERENCES

Author: Konstantin Knyazkov

The model is based on the the Social Forces Model implementation taken from Waiting Bar Customers model

Comments and Questions

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

Click to Run Model

;;----------------------------------------------------------------------------
;; Agents' properties
;;----------------------------------------------------------------------------
turtles-own 
[
  ;; Infection status
  infected

  ;; Жажда
  drinks-had        ;; the number of drinks i've had
  talks-given
  talks-listened

  ;; Движение
  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

  ;; Поведение
  wish              ;; wanna-walk, wanna-talk, wanna-listen, wanna-eat
  action            ;; walk, talk, listen
  walking-point     ;; Chosen random direction to walk
  
  time-left-in-talk ;; Timer which counts down time left to participate in a talk
]

;;----------------------------------------------------------------------------
;; Map
;;----------------------------------------------------------------------------
patches-own
[
  density
]

;;----------------------------------------------------------------------------
;; Model initialization
;;----------------------------------------------------------------------------

to setup
  clear-all

  ;; Icon for an agent: circle, default, ...
  set-default-shape turtles "default"
  
  ;; == Map initialization ==
  
  ;;-----------------
  ;; Blue color for walls
  ;;-----------------
  ask patches with [pxcor = min-pxcor or pxcor = max-pxcor or pycor = min-pycor or pycor = max-pycor]
  [ set pcolor blue ]

  ;;-----------------
  ;; Obstacles are walls too
  ;;-----------------
  ask patches with [pycor > 4 and pycor < 13 and abs pxcor > 10 and abs pxcor < 13]
  [ set pcolor blue ]

  ;;-----------------
  ;; Cofee break table will be green
  ;;-----------------
  ask patches with [pycor < (max-pycor - 4) and pycor > (max-pycor - 8) and abs pxcor > 3 and abs pxcor < 10]
  [ set pcolor green ]

  ;; == Create agents ==
  create-turtles patrons
  [
    let point one-of patches with [pcolor = black]
    setxy ([pxcor] of point) ([pycor] of point)
    
    set drinks-had 0
    set talks-given 0
    set talks-listened 0

    ;; Initial behavior is random walking
    set wish "wanna-walk"
    set action "walk"
    choose-walking-direction
    
    ;; Coloring an agent
    color-turtle
    
    ;; Infection
    set infected false
    
  ]

  ;; Restet tick counter
  reset-ticks
end 

;;----------------------------------------------------------------------------
;; General function of one simulation iteration
;;----------------------------------------------------------------------------

to go
  
  ;;-----------------
  ;; Density
  ;;-----------------
  ; Calculate density
  ask patches with [member? pcolor (list blue green) = false]
  [ 
    set density count turtles in-radius 2.5 
  ]
  ; Show density
  ifelse show-density
  [
    ask patches with [member? pcolor (list blue green) = false]
    [ 
      set pcolor (scale-color white (count turtles in-radius 2) 0 5)
    ]
  ]
  [
    ask patches with [member? pcolor (list blue green) = false]
    [ set pcolor black ]
  ]


  ;;-----------------
  ;; Constants (may be placed in UI)
  ;;-----------------
  let radius 4            ;; Talk radius
  let enoughListeners 4   ;; Talker search for enough listeners in radius
  let timeToTalk 200      ;; Number of ticks for one conversation

  ;;-----------------
  ;; Behavior matrix
  ;; x-axis means wish: wanna-walk (w), wanna-talk (t), wanna-listen (l), wanna-eat (e)
  ;; y-axis means action: walk, talk, listen
  ;; + means probable agent state
  ;;-----------------
  ;;   w t l e
  ;; w + + + +
  ;; t   +
  ;; l     +
  
  ;; Want to walk - is walkin
  ask turtles with [wish = "wanna-walk" and action = "walk"]
  [
    set desired-direction towards walking-point
    ;; Поворачиваем пиктограмму в сторону цели
    face walking-point
    ;; Если достигли цели - меняем поведение
    if distance walking-point < 3
    [ model-behavior-change ]
  ]
  
  ;; Want to eat - is walking towards table
  ask turtles with [wish = "wanna-eat" and action = "walk"]
  [
    let goal min-one-of (patches with [pcolor = green]) [ distance myself ]
    face goal
    set desired-direction towards goal
  ]
  
  ;; Want to listen - is searching for talker
  ask turtles with [wish = "wanna-listen" and action = "walk"]
  [
    let goal max-one-of (turtles with [ action = "talk" ]) [ count my-out-links / distance myself]
    if goal != NOBODY
    [
      face goal
      ifelse distance goal <= radius
      [
        set action "listen"
        set time-left-in-talk timeToTalk
        create-link-from goal
      ]
      [
        set desired-direction towards goal
      ]
    ]
  ]
  
  ;; Want to talk - is searching for enough number of listeners
  ask turtles with [wish = "wanna-talk" and action = "walk"]
  [
    ;; Достаточно человек рядом -> начинаю говорить
    ifelse count turtles in-radius radius >= enoughListeners
    [ 
      if any? turtles in-radius radius with [wish = "wanna-listen" and action = "walk"]
      [
        ;; start talking
        set action "talk"
        set time-left-in-talk timeToTalk
        
        let listeners turtles in-radius radius with [wish = "wanna-listen" and action = "walk"]
        ask listeners
        [
          set action "listen"
          set time-left-in-talk timeToTalk
        ]
        
        create-links-to listeners
      ]
    ]
    ;; Not enough listeners -> continue searching
    [
      let goal max-one-of (patches with [ pcolor = black ]) [ count turtles in-radius radius ]
      face goal
      set desired-direction towards goal
    ]
  ]
  
  ;; Want to talk - is talking
  ask turtles with [wish = "wanna-talk" and action = "talk"]
  [
    ifelse time-left-in-talk = 0
    [
      set talks-given talks-given + 1

      ;; Finish talking
      ask out-link-neighbors
      [
        set talks-listened talks-listened + 1
        model-behavior-change
      ]

      ask my-out-links [die]
      
      model-behavior-change
    ]
    [
      ;; Infection spreading
      set infected infected or reduce or [infected] of out-link-neighbors
      if infected [ 
        ask out-link-neighbors [
          set infected true
          color-turtle
        ] 
      ]
      
      color-turtle
      
      set time-left-in-talk time-left-in-talk - 1
    ]
  ]
  
  ;; Want to listen - is listening
  ask turtles with [wish = "wanna-listen" and action = "listen"]
  [
    ifelse time-left-in-talk = 0
    [
      set talks-listened talks-listened + 1
      
      ;; Tired of listening - leave
      ask my-in-links [die]
      model-behavior-change
    ]
    [
      set time-left-in-talk time-left-in-talk - 1
    ]
  ]
  
  ;; Social forces model
  ;; calculate the forces first...
  ask turtles with [action = "walk"]
  [ 
    calc-driving-force
    calc-obstacle-force
    if any? other turtles
      [ calc-territorial-forces ] 
    move-turtle
  ]
  
  ;; Table service model
  let p 1 / mean-service-time
  if random-float 1 < p
  [
    ask one-of patches with [pcolor = green]
    [ service-patron ]
  ]
  
  tick
end 

;;============================================================================
;; Поведение
;;============================================================================

;;----------------------------------------------------------------------------
;; Выбираем случайную цель движения из нераскрашенных
;;----------------------------------------------------------------------------

to choose-walking-direction
  let point one-of patches with [pcolor = black and distance myself > 2]
  set walking-point point 
end 

;;----------------------------------------------------------------------------
;; Random behavior choice: walk, table, talk
;;----------------------------------------------------------------------------

to model-behavior-change
  set action "walk"
  
  let t random-float 1 
  if t < 0.20
  [
    set wish "wanna-walk"
    choose-walking-direction
    let init-direction -90 + random 180
    set vx sin init-direction
    set vy cos init-direction

  ]

  if t >= 0.20 and t < 0.4
  [
    set wish "wanna-eat"
  ]
  
  if t >= 0.4 and t < 0.8
  [
    set wish "wanna-listen"
  ]
  
  if t >= 0.8 and t <= 1.0
  [
    set wish "wanna-talk"
  ]
  
  color-turtle
end 

;;----------------------------------------------------------------------------
;; Drinks and food service
;;----------------------------------------------------------------------------

to service-patron 
  if any? (turtles with [wish = "wanna-eat"]) in-radius 2.5
  [
    ;; take random agent
    let next-served one-of turtles with [wish = "wanna-eat"] in-radius 2.5
    ask next-served
    [
      set wish "wanna-walk"
      choose-walking-direction
      set drinks-had drinks-had + 1
      color-turtle
    ]
  ]
end 

;;----------------------------------------------------------------------------
;; Coloring agents
;;----------------------------------------------------------------------------

to color-turtle
  if coloring-scheme = "role-based"
  [
    ifelse (wish = "wanna-eat")
    [ set color magenta ]
    [
      ifelse (wish = "wanna-walk")
      [ set color red ]
      [  
        ifelse (wish = "wanna-talk")
        [ set color yellow ]
        [ set color turquoise ]
      ]
    ]
  ]

  if coloring-scheme = "infected-based"
  [
    ifelse (infected = true)
    [ set color red ]
    [ set color green ]
  ]  
end 

to recolor-all
  ask turtles
  [
    color-turtle
  ]
end 

;; Infect one not infected talker of listener

to infect-one-agent
  if any? turtles with [action = "talk" or action = "listen" and infected = false]
  [ 
    ask one-of turtles with [action = "talk" or action = "listen" and infected = false]
    [ set infected true ]
  ]
end 


;;============================================================================
;; Movement
;;============================================================================

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

;;----------------------------------------------------------------------------
;; Social Force Model
;; 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 

;;-----------------------------------------------------------------
;; Social Force Model
;; 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 

;;----------------------------------------------------------------------------
;; Social Force Model
;; 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 = blue or pcolor = green) and distance myself < 10]
  [
    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 

;;----------------------------------------------------------------------------
;; Social Force Model
;; find the driving force of the turtle
;;----------------------------------------------------------------------------

to calc-driving-force
  set driving-forcex (1 / tau) * (max-speed * (sin desired-direction) - vx) * 1.5 ;; 1.5 is pushiness
  set driving-forcey (1 / tau) * (max-speed * (cos desired-direction) - vy) * 1.5
end 

There is only one version of this model, created almost 4 years ago by Konstantin Knyazkov.

Attached files

File Type Description Last updated
Conference Socialization Section Model.png preview Preview for 'Conference Socialization Section Model' almost 4 years ago, by Konstantin Knyazkov Download

This model does not have any ancestors.

This model does not have any descendants.