Behavioural synchrony model

No preview image

1 collaborator

Default-person Vishwanath Varma (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.1.0 • Viewed 149 times • Downloaded 9 times • Run 0 times
Download the 'Behavioural synchrony 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.)


Comments and Questions

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

Click to Run Model

globals [ day ]

turtles-own [
  speed
  bspeed
  neighbor
  move-countdown
  rest-countdown
  movement
  sync
  energy
  reward
  shelters
  nearest-shelter ]


breed [ fishes fish ]

to setup
  clear-all
  reset-ticks
  set day 1

  ;;to randomly create food patches with given density
  ask patches [
    if random-normal 50 50 > (200 - (food-density)) [
        set pcolor green ] ]

  ;;set 5 brown shelters with yellow boundaries
  ask n-of 5 patches [ set pcolor brown
    ask neighbors [ set pcolor yellow ] ]

  ;;for spatial restriction of food to the corner
  ;ask patches [
  ;  if (pxcor > 40 * corner and pycor > 25 * corner) [
  ;    if random-normal (50 + (5 * corner)) 20 > 90 [
  ;      set pcolor green ] ] ]

  ;;create 10 agents with baseline average speed 2, assigned sync-factors, and variable values of initial move and rest times (with averages of 100), at random starting locations
  create-fishes 10 [
    set size 5
    set bspeed boldness1 + random-normal 0 0.1
    set speed bspeed
    set sync sync-factor
    set move-countdown 100 + random-normal 0 50
    set rest-countdown 100 + random-normal 0 50
    setxy random-xcor random-ycor ]
end 

to go

  if ticks > day * 400 [ set day day + 1 ]  ;;each day is 400 timesteps long

 ;;to alternate colour to represent day and night (daylength is 400, 200:200 day-night)
  ifelse ticks > (day * 400) - 200 and ticks < (day)  * 400
    [ ask patches [ if pcolor = 55 [ set pcolor 52 ] ] ]
    [ ask patches [ if pcolor = 52 [ set pcolor 55 ] ] ]

  ask turtles [

    set neighbor min-one-of other turtles [ distance myself ]  ;;Set the nearest agent as neighbor

    ;;Move with constant speed and variable direction, try to synchronize with neighbors, consume food, have a start-stop motion, and update synchrony factor according to reward.
    move
    synchronize
    eat-grass
    stop-start
    update-sync

    ;;Move towards shelter before dusk and restrict activity at dusk/dawn
    find-shelter
    if ticks = (day * 400) - 200 [ adjust-movement2 ]
    if ticks = (day * 400) [ adjust-movement1 ]

    ;;While moving, shoal with neighbors and bounce off walls; also check whether each individual is in motion or at rest at the end of the procedures
    if speed > 0 [
      interact
      bounce-off-walls ]

    check-move ]

  tick
end 



;;When agent is at half the maximum speed or greater (i.e. is starting motion or slowing down), move at the max speed with slightly variable direction

to move
  ifelse speed > 0.9 [
    rt random 10
    lt random 10
    fd 1 * bspeed ]
  [ fd 1 * speed ]
end 

;;Adjust the move-time and rest-time to synchronize with the neighbour

to synchronize
  if [ movement ] of neighbor = 0 and movement = 1
    [ set move-countdown move-countdown - sync ]
  if [ movement ] of neighbor = 0 and movement = 0
    [ set rest-countdown rest-countdown + sync ]
  if [ movement ] of neighbor = 1 and movement = 0
    [ set rest-countdown rest-countdown - sync ]
  if [ movement ] of neighbor = 1 and movement = 1
    [ set move-countdown move-countdown + sync ]
end 

;;Agent gets reward according to whether neighbor is moving

to eat-grass
  set reward 0

  if pcolor = 55 or pcolor = 52 [ ;;green patches during the day or night
    set pcolor black
    set energy energy + 1
    if [movement] of neighbor = 1 [
      set reward 1 ]
    if [movement] of neighbor = 0 [
      set reward 1 * comp-cost ] ]
end 

;;For cyclic start-stop motion

to stop-start
  ;;While fish is moving, move-time (move-countdown) ticks down, otherwise rest-time ticks down.
  ifelse movement = 1
    [ set move-countdown move-countdown - 1 ]
    [ set rest-countdown rest-countdown - 1 ]

  ;;Accelerate or decelerate (by 0.1) to initiate movement or come to rest when move-time or  ticks down to 0
  if move-countdown < 0 [ set speed speed - 0.1 ]
  if rest-countdown < 0 [ set speed speed + 0.1 ]

  ;;Reset move-time when agent comes to rest, reset rest-time when agent reaches half maximum speed
  if speed < 0 [
    set speed 0
    set move-countdown 200 + random-normal 0 50]
  if speed > 0.9 [
    set rest-countdown 200 + random-normal 0 50]
end 


;;Reinforcement learning of synchronous or asynchronous strategy

to update-sync
  ;;Increase or decrease sync-factor based on whether agent is synchronous or asynchronous with neighbour
  if reward > 0 [
    if movement = 1 and [movement] of neighbor = 1 [
      set sync sync + reward * 0.01 ]
    if movement = 1 and [movement] of neighbor = 0 [
      set sync sync - reward * 0.01 ] ]

  ;;Set maximum and minimum sync-factor as 0.9 and -0.9
  if sync > 0.9 [ set sync 0.9 ]
  if sync < -0.9 [ set sync -0.9 ]
end 



;;Move towards nearest unoccupied shelters 25 steps before dusk

to find-shelter
  if ticks > (day * 400) - 225 and ticks < (day * 400) - 175 [
      set shelters (patches with [pcolor = brown])
    let empty-shelters shelters with [pcolor = brown and not any? turtles-here ]
    set nearest-shelter min-one-of empty-shelters [distance myself]
    if any? empty-shelters [
        set heading towards nearest-shelter ] ]
end 

;;Adjust the move-time and rest-time of individuals at dawn and dusk

to adjust-movement1
  if movement = 1 [ set move-countdown move-countdown + restrict ]
  if movement = 0 [ set rest-countdown rest-countdown - restrict ]
end 

to adjust-movement2
  if movement = 1 [ set move-countdown move-countdown - restrict ]
  if movement = 0 [ set rest-countdown rest-countdown + restrict ]
end 


;;Shoaling rules

to interact
  if distance neighbor < 2
    [ set heading towards neighbor
      set heading heading + random-normal 180 10 ]
  if distance neighbor < 10 and distance neighbor > 2
    [ set heading [heading] of neighbor + random-normal 0 10 ]
  if distance neighbor > 10 and any? other turtles in-cone 15 60 [
    set heading towards neighbor
    set heading heading + random-normal 0 10 ]
end 

;;Bouncing off the walls

to bounce-off-walls
  if abs pxcor = max-pxcor [ set heading (heading + 90) ]
  if abs pycor = max-pycor [ set heading (heading + 90) ]
end 

;;Check whether each individual is moving

to check-move
  ifelse speed > 0
    [ set movement 1 ]
    [ set movement 0 ]
end 

;;Report the number of individuals moving at any given time

to-report active-fish
  report count turtles with [ movement = 1 ]
end 

;;Report the average sync-factor of the 10 individuals in the population

to-report avg-sync
  report mean [sync] of turtles
end 

There is only one version of this model, created about 4 years ago by Vishwanath Varma.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.