Follow and Avoid NetLogo Model
Produced for the book series "Artificial Intelligence";
Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.
powered by NetLogo
view/download model file: Follow-and-Avoid.nlogo
WHAT IS IT?
This model attempts to simulate the seeking and fleeing steering behaviours for boids (as devised by Craig Reynolds).
HOW IT WORKS
It does this by generating random Wanderer turtles (boid) that simply wander. Followers (seeking), on detecting Wanderers within their radius, turn to face the nearest Wanderer and move forward. Avoiders (fleeing) do the same action but reverse their direction by 180 degrees, thus moving away from the nearest Wanderer.
HOW TO USE IT
Setup the initial world. Then use the speed bars during operation to adjust the speed of all the turtles.
The buttons in the Interface are defined as follows:
- Setup: This clears the environment and creates new Wanderer, Follower and Avoider agents.
- Go: This starts the simulation.
- Follow Wanderer: This will follow one of the Wanderer agents.
- Follow Follower: This will follow one of the Follower agents.
- Follow Avoider: This will follow one of the Avoider agents.
The sliders and monitor in the Interface are defined as follows:
- radius-detection: This adjusts the vision of the boids.
- boid-speed: This adjusts the forward step value of each boid per iteration.
- speed-factor: This reduces the speed of both the Follower and Avoider agents.
- boid-random-heading: This adds a bit of randomness to the boids' movements.
- number-of-agents, number-of-wanderers, number-of-followers, number-of-avoiders: These are the number of agents in each respective category.
THINGS TO NOTICE
Adjusting the radius bar alters the distance at which both Followers and Avoiders can see. This alters the way they behave, such as the distance that the Avoider stays away from Wanderers.
The Avoider sometimes appears to move towards a Wanderer; this is an affect resulting from an environment that wraps around.
THINGS TO TRY
Try changing the number of Wanderers, Followers and Avoiders.
Try adjusting the scale bar to see what happens to the Follower.
Try changing the shape of the Avoider to be rotatable (if they are not already); this highlights the affects of the wrap around problem.
EXTENDING THE MODEL
The model could be extended to add gradual acceleration and deceleration. This would enhance the boids simulation.
The model uses the command in-radius to implement the boidsÕ cone of vision.
Another boid related model is the Biology/Flocking model.
CREDITS AND REFERENCES
This model was created by Thomas Christy, Bangor University 2009.
; Follow and Avoid model. ; ; Demonstrates Seeking and Fleeing behaviour in boids. ; ; Written by Thomas Christy (2009) ; Modified by William John Teahan (2009) ; ; Copyright 2010 Thomas Christy and William John Teahan. All Rights Reserved. breed [wanderers wanderer] ; wanders around breed [followers follower] ; tries to follow the wanderer breed [avoiders avoider] ; tries to avoid the wanderer to setup clear-all ; set shapes for the breeds set-default-shape wanderers "directional-circle" set-default-shape followers "directional-circle" set-default-shape avoiders "directional-circle" ; create a wanderer, follower and an avoider at random locations create-wanderers number-of-wanderers [ default red ] create-followers number-of-followers [ default green ] create-avoiders number-of-avoiders [ default yellow ] end to-report number-of-agents ; used to show that number of turtle agents is constant even when ; all the followers clump on top of each other report count turtles end to default [colour] ; creates default settings for boid set color colour ; sets colour using passed parameter setxy random-xcor random-ycor ; sets an initial random position set size 3 ; default turtle size end to go ; deployed on selection of go button ask wanderers ; wanderer's instructions [ lt random 30 ; randomly turn to the left rt 15 fd boid-speed ; variable user defined speed ] ask followers ; follower's instructions [ fd boid-speed / speed-factor ; moves forward continuously at user defined speed if any? wanderers in-radius radius-detection ; follower searches for wanderer in its radius [ set heading (towards min-one-of wanderers [distance myself]) - random boid-random-heading + random boid-random-heading ] ; adjusts heading to point towards wanderer ] ask avoiders ; avoiders' instructions [ fd boid-speed / speed-factor ; moves forward continiously at user defined speed if any? wanderers in-radius radius-detection ; avoider searches for wanderer in its radius [ set heading (towards min-one-of wanderers [distance myself]) + 180 - random boid-random-heading + random boid-random-heading ] ; adjusts heading to point away from wanderer ] end ; ; Copyright 2010 by William John Teahan. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from William John Teahan. ; Contact William John Teahan for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in publications, please use: ; ; Teahan, W. J. (2010). Follow and Avoid NetLogo model. ; Artificial Intelligence. Ventus Publishing Aps ;