Flocking with Predation

Flocking with Predation preview image

1 collaborator

Photo Héctor Sanchez (Author)

Tags

behaviour 

Tagged by Héctor Sanchez over 11 years ago

boid 

Tagged by Héctor Sanchez over 11 years ago

boids 

Tagged by Héctor Sanchez over 11 years ago

emergent 

Tagged by Héctor Sanchez over 11 years ago

flocking 

Tagged by Héctor Sanchez over 11 years ago

predation 

Tagged by Héctor Sanchez over 11 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 1823 times • Downloaded 103 times • Run 0 times
Download the 'Flocking with Predation' modelDownload this modelEmbed this model

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


Hawk-Dove with Flocking Behaviour :: Hector Manuel Sanchez Castellanos

Brief Description

Hawks chase doves and try to eat them while doves escape and gain a speed and "diversion" advantage out of flocking with other mates.

Overview

Purpose

This model was created as a first approach to simulate the behaviour of agents in a predator-prey relation within a habitat. It is based on Uri Wilensky's flocking model with several extensions to account for the behaviours of the agents.

Entities

Hawks (in red): predators Doves (in other colors): prey

State Variables

Doves

  • dovesPopulation: inital amount of doves in the model
  • dovesVisionAngle: amount of degrees in front of a dove that represent its vision cone
  • dovesVisionRange: amount of patches in front of a dove that represent its vision range
  • dovesDistance: amount of patches of separation doves must conserve with each other
  • maxSeparateTurn: max amount of degrees allowed for a separation turn
  • maxAlignTurn: max amount of degrees allowed for an alignment turn
  • maxCohereTurn: max amount of degrees allowed for a cohesion turn
  • noiseInMovement: degrees allowed as the result of randomness in doves behaviour
  • dovesAvoidanceMin: minimum amount of degrees allowed in an escape situation
  • dovesBaseSpeed: movement speed if no other variables take place
  • dovesSpeedPerFlockmate: speed advantage gained by having one flockmate
  • dovesFlock: determines if the doves show flocking behaviour or not

Hawks

  • hawksPopulation: initial amount of hawks in the model
  • hawksVisionAngle: amount of degrees in front of a hawk that represent its vision cone
  • dovesVisionRange: amount of patches in front of a hawk that represent its vision range
  • hawksKillingRange: amount of patches in which's a hawk can eat its prey
  • hawksFocus: probability of the hawk sticking to the nearest prey between others
  • hawksBaseSpeed: movement speed if no other variables take place

Design Concepts

Basic Principles

  • Flocking: flocking is implemented with the classical rules "separate, align and cohere"
  • Speed Advantage: doves also obtain a speed advantage out of the birds in front of them to simulate the reduction in air resistance
  • Focus: hawks can lose focus in response to multiple targets moving fast in front of them

Emergence

  • Flocking Behaviour: doves tend to flock together according to their flocking rules
  • Non Flocking Attacked: doves that are not part of a flock are killed more easily

Adaptation

Doves

  • Avoidance: doves react to the precence of hawks and try to avoid them by turning by a random amount of degrees within a certain range

Hawks

  • Pursuit: hawks react to the precence of doves by following a target which is prioritized if it is the nearest one

Objectives

  • Obtaining the best doves' behaviour parameters so that most of them escape predaiton
  • Trying to detect anomalies in behaviour

Learning

  • NetLogo capabilites and drawbacks
  • BehaviourSearch capabilities and drawbacks
  • Basic agent-based ecology modelling

Prediction

  • The parameters obtained with BehaviourSearch will tend to favor standard flocking behaviour

Sensing

  • Vision Cone: hawks and doves have a vision cone in front of them to simulate allys and enemies sight

Interaction

  • Predator-Prey

Stochasticity

  • Randomness in Movement: agents allow a certain amount of noise in their movement to simulate randomness in agent's behaviour

Doves

  • Avoidance Angle: doves turn in a random angle within a range in order to avoid a hawk

Hawks

  • Focus: hawks are allowed to probabilistically chase a target that is not the nearest to them as to simulate the confusion that a flock causes on the individual

Collectives

Doves

  • Doves flock with doves

Hawks

  • Hawks move independently from each other

Observation

N/A

Details

Initialization

Input Data

N/A

Submodels

  • Avoidance
  • Flocking
  • Attacking

Author

Hector Manuel Sanchez Castellanos Ph.D. Student in Computer Sciences Instituto Tecnológico y de Estudios Superiores de Monterrey Campus Estado de México chipdelmal@gmail.com

Comments and Questions

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

Click to Run Model

globals[deadTurtles dovesSpeedVariationRange sigmoidScale]
patches-own[]
breed[doves dove]
breed[hawks hawk]
doves-own[flockmates nearest individualSpeed age]
hawks-own[individualSpeed]

;;SetupFunctions---------------------------------------------------------------------------------------------------

to setup
  clear-all
  set dovesSpeedVariationRange 0
  set sigmoidScale .001
  ask patches[]
  createHawks hawksPopulation
  createDoves dovesPopulation  
  reset-ticks
end 

;;Go!!!!!!!!!!!!---------------------------------------------------------------------------------------------------

to go
  preyFlockOrAvoid doves hawks dovesVisionRange dovesVisionAngle dovesAvoidanceMinTurn dovesAvoidanceMaxTurn dovesNoiseInMovement dovesFlock
  predatorHunt hawks doves hawksVisionRange hawksVisionAngle hawksFocus hawksNoiseInMovement hawksKillingRange
  tick
end 

;AttackingFunctions---------------------------------------------------------------------------------------------------

to killIfAnyNear [breedToAttack killingRange]
  ;;If any prey is within killing range of our predator it is forced to die
  if any? breedToAttack in-radius killingRange
  [
    ask breedToAttack in-radius killingRange[die]
    set deadTurtles deadTurtles + 1
  ]  
end 

to headProbabilisticallyTowardsMortal [potentialVictims focus]
  ;;Allows the posibility of the predator to lose focus and head towards another victim
  ifelse(random-float 1 < focus)
  [headTowardsNearestMortal potentialVictims]
  [headTowardsOneMortal potentialVictims]
end 

to headTowardsNearestMortal [potentialVictims]
  ;;Sets heading towards the nearest prey available
  let victim min-one-of potentialVictims [distance myself]
  set heading (towards victim)
end 

to headTowardsOneMortal [potentialVictims]
  ;;Sets heading towards one of the nearest preys available
  let victim one-of potentialVictims
  set heading (towards victim)
end 

;AvoidingFunctions---------------------------------------------------------------------------------------------------

to runaway [avoidableBreed minTurn maxTurn]
  ;;If there is a predator we turn probabilistically within the range of (minTurn, maxTurn)
  set heading (towards min-one-of avoidableBreed [distance myself]) + (minTurn + random (maxTurn - minTurn))
end 

;;CreationFunctions---------------------------------------------------------------------------------------------------

to createHawks [numberOfIndividuals]
  ;;Creates hawks population
  create-hawks hawksPopulation
  [
    set color red
    setxy random-xcor random-ycor
    if hawksPen = true[pen-down] 
    set size 3.5
    set individualSpeed hawksBaseSpeed 
  ]
end 

to createDoves [numberOfIndividuals]
  ;;Creates doves population
  create-doves dovesPopulation 
  [
    set color blue + random 10
    setxy random-xcor random-ycor
    if dovesPen = true[pen-down]
    set size 2
    set flockmates no-turtles
    set individualSpeed (dovesBaseSpeed + random-float dovesSpeedVariationRange)
    set age random 50 
  ]
end 

;;MovementFunctions---------------------------------------------------------------------------------------------------

to predatorHunt [predatorBreed preyBreed predatorVisionRange predatorVisionAngle predatorFocus predatorNoiseInMovement predatorKillingRange]
  ;;If there are preys around then hunt else wander around
  ask predatorBreed
  [
    let preysAround (preyBreed in-cone predatorVisionRange predatorVisionAngle)
    ifelse (any? preysAround)
    [moveProbabillisticallyTowardsMortalAndKill preysAround preyBreed predatorFocus predatorNoiseInMovement predatorKillingRange]
    [wanderAround 10 predatorNoiseInMovement]
    forward individualSpeed
  ]
end 

to preyFlockOrAvoid [preyBreed predatorBreed preyVisionRange preyVisionAngle preyMinAvoidanceTurn preyMaxAvoidanceTurn preyNoiseInMovement flockOrNotBool]
  ;;If there are predators then avoid else try to flock
  ask preyBreed
  [
    ifelse(any? predatorBreed in-cone preyVisionRange preyVisionAngle)
    [runawayWithNoise predatorBreed preyMinAvoidanceTurn preyMaxAvoidanceTurn preyNoiseInMovement]
    [flockOrWander flockOrNotBool preyBreed preyVisionRange preyVisionAngle preyNoiseInMovement]
    forward individualSpeed
  ]
end 

to flockOrWander [flockOrNotBool preyBreed preyVisionRange preyVisionAngle preyAngleNoiseRange]
  set flockmates other preyBreed in-cone preyVisionRange preyVisionAngle
  ifelse (flockOrNotBool and (any? flockmates))
  [flock doves dovesVisionRange dovesVisionAngle dovesBaseSpeed dovesSpeedPerFlockmate dovesNoiseInMovement]
  [wanderAround 10 preyAngleNoiseRange]
end 

to runawayWithNoise [predatorBreed preyMinAvoidanceTurn preyMaxAvoidanceTurn preyNoiseInMovement]
  ;;Escapes from a predator with a certain amount of noise in the movement
  runaway predatorBreed preyMinAvoidanceTurn preyMaxAvoidanceTurn
  right randomAngleRange preyNoiseInMovement
end 

to moveProbabillisticallyTowardsMortalAndKill [preysAround preyBreed predatorFocus predatorNoiseInMovement predatorKillingRange]
  ;;Heads towards one prey in a group and kills if any of them is in range
  headProbabilisticallyTowardsMortal preysAround predatorFocus
  right randomAngleRange predatorNoiseInMovement
  killIfAnyNear preyBreed predatorKillingRange  
end 

to wanderAround [angleWanderRange angleNoiseRange]
  ;;Just take it easy and get around
  right (randomAngleRange angleWanderRange) + (randomAngleRange angleNoiseRange)
end 

to turnWithLimit [desiredTurn maxTurn]
  ;;Performs a turn that allows a certain maximum number of degrees and no more
  ifelse (abs desiredTurn > maxTurn)
  [ifelse (desiredTurn > 0)[right maxTurn][left maxTurn]]
  [ifelse (desiredTurn > 0)[right abs desiredTurn][left abs desiredTurn]]
end  

to-report averageFlockmateHeading
  ;;Averages the headings of the flockmates
  let x-component sum [dx] of flockmates
  let y-component sum [dy] of flockmates
  ifelse (x-component = 0 and y-component = 0)[report heading][report atan x-component y-component]
end 

to-report averageTowardsFlockmatesHeading
  ;;Gets the average of angle between the headings of the flockmates and the current turtle
  let x-component mean [sin (towards myself + 180)] of flockmates
  let y-component mean [cos (towards myself + 180)] of flockmates
  ifelse (x-component = 0 and y-component = 0)[report heading][report atan x-component y-component]
end 

to-report randomAngleRange[range]
  ;;Returns an angle in the range of (-range, range)
  report random range - random range
end 

;;FlockingFunctions---------------------------------------------------------------------------------------------------

to flock [flockingBreed radius angle baseSpeed speedBonusPerFlockmate noiseInMovement]
  ;;Performs the required functions for the turtles to flock (align, cohere and separate)
  set nearest min-one-of flockmates [distance myself]
  ifelse (distance nearest < dovesDistance)[separate][align cohere]
  right randomAngleRange noiseInMovement
  
  ;;Turn on/off one of these behaviours
  ;if(flockSpeed = "BaseSpeed")[set individualSpeed baseSpeed + (speedBonusPerFlockmate * count flockmates)]
  ;if(flockSpeed = "MinOfFlock")[set individualSpeed ((min [individualSpeed] of flockmates) + (speedBonusPerFlockmate * count flockmates))]
  ;if(flockSpeed = "MeanOfFlock")[set individualSpeed ((mean [individualSpeed] of flockmates) + (speedBonusPerFlockmate * count flockmates))]
  ;if(flockSpeed = "MaxOfFlock")[set individualSpeed ((max [individualSpeed] of flockmates) + (speedBonusPerFlockmate * count flockmates))]
  if(flockSpeed = "BaseSpeed")[set individualSpeed baseSpeed + (speedBonusPerFlockmate * count flockmates)]
  if(flockSpeed = "MinOfFlock")[set individualSpeed ((min [individualSpeed] of flockmates) + (sigmoidFunction sigmoidScale 5 1 (count flockmates)))]
  if(flockSpeed = "MeanOfFlock")[set individualSpeed ((mean [individualSpeed] of flockmates) + (sigmoidFunction sigmoidScale 5 1 (count flockmates)))]
  if(flockSpeed = "MaxOfFlock")[set individualSpeed ((max [individualSpeed] of flockmates) + (sigmoidFunction sigmoidScale 5 1 (count flockmates)))]
end 

to separate
  ;;Turn away from a flockmate that is too near to us
  let neighborHeading ([heading] of nearest)
  let differenceInHeadings (subtract-headings heading neighborHeading)
  turnWithLimit differenceInHeadings maxSeparateTurn
end 

to align
  ;;Turns our turtle towards the average direction its flockmates are heading to
  let averageHeading averageFlockmateHeading
  let differenceInHeadings (subtract-headings averageHeading heading)
  turnWithLimit differenceInHeadings maxAlignTurn
end 

to cohere
  ;;Head towards the average position of our flockmates
  let averageHeadingTowards averageTowardsFlockmatesHeading
  let differenceInHeadings (subtract-headings averageHeadingTowards heading)
  turnWithLimit differenceInHeadings maxCohereTurn
end 

to-report sigmoidFunction [scale offset slope x]
  ;;Applies a sigmoid function to the input values
  report scale * (1 / (1 + e ^ (- offset * x + slope)))
end 

There is only one version of this model, created over 11 years ago by Héctor Sanchez.

Attached files

File Type Description Last updated
Flocking with Predation.png preview Preview for 'Flocking with Predation' over 11 years ago, by Héctor Sanchez Download

This model does not have any ancestors.

This model does not have any descendants.