Termite Defense
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
Termite Defense is a netLogo project in which termites attempt to defend their queen against an attack from ants.
It is an attempt to model the seemingly complex aggregate behavior exhibited by termites in the physical world.
HOW IT WORKS
There are 4 main species of turtles in this model.
Queen Termite - is pulled to safety during a critical breach by worker termites
Worker Termites - responsible for the rebuilding of the nest, and pulling the queen to safety
Soldier Termites - responsible for defending the nest against intruders, and killing ants
Ants - ants roam the surface of the nest until a breach is found, upon which point in time, they signal to their army the location of the breach, and commence assault.
Given a small enough number of ants, the colony will defend itself, but when the large inner chamber is breached, the termites enter an emergency mode to protect its queen.
The majorBreach switch is for forcing major breach behavior.
The demoMode switch displays the colored queen's pheromone level per inside patch, and the assault signal on the outer patches for the ants.
HOW TO USE IT
Use the top two sliders, startTermiteCount and startAntCount to choose the starting populations of both termites and ants.
As a rule, soldier termites make up 1/5th of the population, and worker termites make up the remaining 4/5ths.
Use the deepBreach slider to determine how far into the nest the ant's must go before the breach is declared a major breach, and the termites go into phase two.
The leftmost value will initiate queen protection mode very soon after the ants enter the nest.
The rightmost value will allow the ants to catch and kill the queen.
The default value of this slider is the approximate value of main chimney vent in the middle of the nest.
After deciding these parameters, click the SETUP BUTTON.
Then click the GO BUTTON.
After allowing the queen's scent (clock based- approx 200 ticks) to permeate through the nest, LEFT-CLICK the outer surface of the termite mound near the ant army to initiate an assault on the termite queen.
THINGS TO NOTICE
If you create a breach away from the army of ants, the termites do a relatively good job in holding them off and rebuilding the nest.
The soldier termites, block the entrance to the nest, killing intruders and protecting the workers.
The worker termites will slowly patch up the breach. Large breaches are patched up using an overspill of dirt, as the way it commonly occurs in the natural world. Dirt is continually piled at the sites of the breaches until the nest has been returned to normal.
THINGS TO TRY
The critical value of ants according to the combat protocols specified is approximately 1.2 times the number of soldier termites, or .24 times the entire termite population.
Even if all the ants eventually get killed by the soldier termites, 1.2 times the number of soldier termites will cause phase 2, the reaction to a serious breach.
It may be of interest to see the method behind the ant navigation and signaling.
This can be seen if the SEMICOLONS are removed from the 7 lines of code following the "@@ DEMO CODE @@" comment in the GO SECTION.
EXTENDING THE MODEL
1. Implement a mode of retreat for the ants.
2. Implement the repopulation of the ant nest including the reopening of the escape chamber as well as the queen producing more young.
3. Implement large soldiers and workers
4. Simulate the respiratory nature and temperature management of the nest.
5. Use the temperature to more accurately simulate breach repair for more severe breaches as well.
NETLOGO FEATURES
Temporary variable declaration as a means of accessing patch variables for use by turtles was used.
In particular,
let class-ahead [class] of patch-ahead 1
let y-ahead [pycor] of patch-ahead 1
is used very frequently.
The distancexy primitive saved much time when attempting to calculate the radius from one patch or turtle to another. This was particularly useful in modelling the assault notice.
The background nest image is a 1:1 ratio 61x75 .bmp image hand drawn in msPaint.
import-pcolors "nest.bmp"
RELATED MODELS
Online Link to this model:
http://modelingcommons.org/browse/one_model/2593
Wilensky, U. (1997). NetLogo Ants model. http://ccl.northwestern.edu/netlogo/models/Ants. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
CREDITS AND REFERENCES
Attenborough, David. "Termites - Life's Ultimate Architects". BBC - YouTube. June 01, 2009 <http://www.youtube.com/watch?v=0m7odGafpQU>.
Maeterlinck, Maurice. The Life of the White Ant. London: George Allen & Unwin LTD, 1927.
Schoning, Caspar, and Mark Moffett. "Driver Ants Invading a Termite Nest: Why Do the Most Catholic Predators of All Seldom Take This Abundant Prey?". University of Copenhagen. June 02, 2009 <http://www1.bio.ku.dk/forskning/oe/cse/media/schoening2007_biotropica.pdf/>.
Turner, Scott . "Structure of Macrotermes mounds". State University of New York College of Environmental Science and Forestry. June 01, 2009 <http://www.esf.edu/efb/turner/termite/termhome.htm>.
"Wars of the Underworld". VidMax - YouTube. June 01, 2009 <http://www.youtube.com/watch?v=mY9LNEJNrZs&feature=related>.
Wilensky, U. (1997). NetLogo Ants model. http://ccl.northwestern.edu/netlogo/models/Ants. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
Comments and Questions
breed [ants ant] ; ants! breed [sWorkers sWorker] ; small workers breed [lWorkers lWorker] ; large workers breed [sSoldiers sSoldier] ; small soldiers breed [queens queen] ; queen breed [qScents qScent] ; queenscent ants-own [breach] sWorkers-own [mud vibration] ; patch in front of the workers' color qScents-own [energy] patches-own [class qLevel sigStr] ; qLevel- queen scent in the air in the nest ; sigStr- breach signal strength globals [ breachx breachy qx qy qMoves] ; qx - queen xcor ; qy - queen ycor ; qMoves - # of times the queen has moved ; class- patch classification system ; 0 for dirt ; 1 for nest air ; 2 for outside air ; 3 for queens nest ; 4 for new dirt ; 5 for emergency exit ;######################################## ; SETUP ;######################################## to setup clear-all set majorBreach false set qMoves 0 set-default-shape turtles "bug" import-pcolors "nest.bmp" ; import of paintbrush .bmp files dimensions 60x75 ; light gray for queens nest ; dark gray for hive air ; black for dirt ; white for outside air ;DIRT PATCHES - 0 ask patches with [pcolor = 0] ; ask dirt patches [ nestDirt ] ;NEST AIR - 4.5 ask patches with [pcolor = 4.5] [ nestAir ] ;OUTSIDE AIR - 9.9 ask patches with [pcolor = 9.9] [ outsideAir ] ;QUEENS NEST - 7.3 ask patches with [pcolor = 7.3] [ queensRoom ] ;POPULATE NEST setupTermites setupAnts ;EMERGENCY EXIT ask patches with [pcolor = 14.9] [ set class 5 ] ;SETUP PLOTS do-plots end ;************************** ;PLOT SETUP to do-plots set-current-plot "Totals" set-current-plot-pen "sSoldiers" plot count sSoldiers set-current-plot-pen "ants" plot count ants set-current-plot-pen "sWorkers" plot count sWorkers end ;************************** ;TERMITE SETUP to setupTermites ;workers and soldiers ask patch 5 11 [ sprout-sWorkers startTermiteCount * .8 [ set color gray set size 1 set mud 0 ] sprout-sSoldiers startTermiteCount * .2 [ set shape "soldier" set color red set size 1 ] ] ;spawn queen ask patch 6 -14 [ sprout-queens 1 [ set shape "queen" set size 10 set heading 270 set color yellow + 4 set qx xcor + 3 set qy ycor ] ] ;setup scent trail ask queens [ ask patch xcor ycor [ sprout-qScents 100 [ set energy 90 set size 0 ] ] ] end ;************************** ; ANT SETUP to setupAnts ask patch -16 8 [ sprout-ants startAntCount [ set color black set size 1 set heading 90 set breach 0 ] ] end ;######################################## ; GO ;######################################## to go tick ;************************** ; STOP CONDITIONS if qx < -23 [ show "Queen escapes safely." stop ] if count queens = 0 [ show "Queen has been slain." stop] ;************************** ; DEMO CODE if demoMode = true [ ask patches with [class = 1 or class = 4 or class = 3 or class = 5] [set pcolor qLevel] ask patches with [class = 2] [ if sigStr > .1 [ set pcolor 20 - sigStr ] ] ] ;************************** ;SMALL WORKER GO ask sWorkers [ ifelse majorBreach = false [ mudWork terMove ] [ evacuateWorkers ;next if statement is simply code if any? neighbors4 with [class = 2] or count neighbors4 with [class = 0] > 3 [ die ] ] ] ;************************** ;SMALL SOLDIER GO ask sSoldiers [ ifelse majorBreach = false [ ifelse count neighbors4 with [class = 2] > 0 ; if the soldier is exposed to outside air [ guardBreach ] [ sSolMove ] ] [ protectTheQueen ;next if statement is simply cleanup code if any? neighbors4 with [class = 2] or count neighbors4 with [class = 0] > 3 [ die ] ] sSFight ] ;************************** ; ANT GO ask ants [ ifelse breach = 0 [antMove] [ ifelse breach = 1 [assault] [ if breach = 2 [ retreat ;next if statement is simply cleanup code if any? neighbors4 with [class = 2] or count neighbors4 with [class = 0] > 3 [ die ] ] ] ] antFight ] ;************************** ; QUEEN SCENT GO if any? qScents [ ask qScents [ qMove ] ] ;************************** ; NEST MAINTENENCE ifelse majorBreach = false [ ;PATCH REPAIR ask patches [ updateNest ] ask patches with [class = 4] ; new dirt [ if count neighbors with [class = 2] < 1 ; if disturbances have been fixed [ ; remove unnecessary new-dirt patches nestAir ;show max-one-of neighbors4 [qLevel] let highQ [qLevel] of max-one-of neighbors4 [qLevel] set qLevel highQ - .1 ] ] ] [ ;else if majorBreach = true ask queens [queenMove] ask patches with [class = 4] ; new dirt [ if pcolor < 32 [ nestDirt ] ] ] ;************************** ; MOUSE ATTACK if mouse-down? ; if the mouse is clicked [ ask patch mouse-xcor mouse-ycor [ if class = 0 ; and the patch that is clicked is dirt [ if any? neighbors with [class = 2] ; and the patch is an outside dirt patch [ outsideAir set qLevel 0 ask neighbors4 with [class = 0] [ outsideAir set qLevel 0 ] ] ] ] ] ;PLOT UPDATE do-plots end ;######################################## ; SMALL WORKER TERMITE COMMANDS ;######################################## ;************************** ; MUDWORK to mudWork ;pickup if mud = 0 ; if not carrying mud [ ifelse ycor < -21 ; if in the cellar of the nest [ if any? neighbors4 with [class = 0] [ ask one-of neighbors4 with [class = 0] [ set pcolor pcolor + .1 ] set mud 1 ] ] [ if random 100 < 10 ; 10% chance to pick up dirt from anywhere [ if any? neighbors4 with [class = 0] [ if mud = 0 [ set mud 1 ask one-of neighbors4 with [class = 0] [ set pcolor pcolor + .05 ] ] ] ] ] ] ;dropoff if mud = 1 [ ifelse any? neighbors4 with [class = 2] ; if you have mud, and any of your neighboring patches are air [ ;drop your mud set mud 0 ask patch-here [ mudDrop ] ] [ if ycor > -21 ; if not in cellar [ nestMaintenence ] ] ] end ;************************** ; GENERAL MAINTENENCE to nestMaintenence ; repair any mound dirt that may have been damaged if any? neighbors4 with [class = 0 and pcolor > 32] [ set mud 0 ask one-of neighbors4 with [class = 0 and pcolor > 32] [ set pcolor pcolor - .1 ] ] ; also, if worker termite is standing on a patch of newdirt, and is holding mud, drop mud ask patch-here [ if class = 4 [ ask sWorkers-here with [mud = 1] [ ;show "DROP HERE" set mud 0; ask patch-here [ set pcolor pcolor - .1 ] ] if pcolor < 32 [ nestDirt ] ] ] end ;************************** ; PROTECT THE QUEEN to queenChain if distancexy qx qy > 4 [ face patch qx qy fd .05 ] end to farQueenChain if distancexy qx qy > 8 [ face patch qx qy set heading heading + random 45 - 22.5 fd .05 if [class] of patch-here = 0 [ set heading heading + 180 fd .25 set heading (heading + random 180) + 90 ] ] end ;######################################## ; SMALL SOLDIER TERMITE COMMANDS ;######################################## ;GUARD BREACH to guardBreach ask patch-here [ ; if the patch being guarded gets restored if class = 0 [ ask sSoldiers-here [ atEase ] ] ] end ;BACK TO NORMAL to atEase facexy 5 -26 ; face middle of the next fd .5 ; move soldiers back in end ;COMBAT to sSFight if any? ants-on neighbors4 [ ask one-of ants-on neighbors4 [ die ] if count ants = 0 [ show "Termites win this round." ask patches with [class = 2 or class = 0] [set sigStr 0] ] ask patch-here ;if the ants have reached the inner chimney of the nest [ if qLevel > deepBreach and count neighbors with [class = 1] > 6 [ set majorBreach true ] ] ] end ;######################################## ; ANT COMMANDS ;######################################## ;REINFORCEMENTS to addAnts ask patch -16 8 [ ifelse sigStr > 0 [ sprout-ants 10 [ set color black set size 1 set heading 90 set breach 1 ] ] [ sprout-ants 10 [ set color black set size 1 set heading 90 set breach 0 ] ] ] end to addMadAnts ask patch -16 8 [ ifelse sigStr > 0 [ sprout-ants 100 [ set color black set size 1 set heading 90 set breach 1 ] ] [ sprout-ants 100 [ set color black set size 1 set heading 90 set breach 0 ] ] ] end ;COMBAT to antFight ; if ants surround termites they can kill them if count ants-on neighbors4 > 30 [ if any? queens-on neighbors4 [ ask one-of queens-on neighbors4 [ die ] ] ] if count ants-on neighbors4 > 3 [ if any? sSoldiers-on neighbors4 [ ask one-of sSoldiers-on neighbors4 [ die ] ] ] if any? sWorkers-on patch-here [ ask one-of sWorkers-on patch-here [ die ] ] end ;SIGNAL TO OTHER ANTS to sendSignal ask ants [ set breach 1 ] ask one-of neighbors4 with [class = 4] [ set breachx pxcor set breachy pycor ] ask patches with [class = 2 or class = 4] [ let howFar 7 / (.1 + (distancexy breachx breachy) * (distancexy breachx breachy)) set sigStr howFar ] end ;######################################## ; PATCH SET COMMANDS ;######################################## ;************************** ;NEST MAINTENENCE to updateNest ; Cellar Update if class = 0 and pcolor > 39.5; if dirt patch has been depleted, change it to nest air [ nestAir ] ; ie in the cellar ; SpillOver ; programs newDirt patch darkening to allow for spillover that one of the neighbors 4 is outer air if class = 4 and pcolor < 38 ; if newdirt patch is dark enough [ ask neighbors with [class = 2] ; ask outer air neighbors [ ifelse pcolor = 9.9 ; if first spillover [ set pcolor 39.5 ; change color to very light brown ] [ ; else, just darken the patch ifelse pcolor > 32 [ set pcolor pcolor - .1 ] [ ; if the patch gets dark enough, change it to nestdirt nestDirt ;ask myself [nestDirt] ] ] ] ; if any of the neighboring patches are new dirt, make sure they get filled completely (through spillover) ; before filling in the parent dirt patch if any? neighbors4 with [class = 4] [ set pcolor 38 ] ] end to outsideAir set class 2 ; change the dirt to outside air set pcolor 9.9 end to nestDirt set class 0 set pcolor 32 end to nestAir set qLevel 0 set class 1 set pcolor 59.5 ; very light green - 55 is darker green end to queensRoom set class 3 set pcolor 7.3 end to newDirt set class 4 set pcolor 39 end to mudDrop ifelse class = 2 or class = 1; if the patch is air [ newDirt ] [ if class = 4 ; if the patch is new dirt [ set pcolor pcolor - .1 ] ] end ;######################################## ; MOVEMENT RULES ;######################################## ;************************** ;DEFAULT WORKER MOVEMENT to terMove let class-ahead [class] of patch-ahead 1 ifelse class-ahead = 1 or class-ahead = 4 or class-ahead = 3 [ fd .25 ] [ set heading heading + ((random 150) - 75)] end ;ASSAULT WORKER MOVEMENT to evacuateWorkers let my-class [class] of patch-here let higherClass any? neighbors4 with [class > my-class] ifelse my-class = 1 ;current location is nest air [ ifelse higherClass = false ;get to the queens chamber [ if any? neighbors with [qLevel > 0] [ face max-one-of neighbors4 [qLevel] fd .3 if [class] of patch-here = 0 [ set heading heading + 180 fd .35 ] ] ] [ ;when you are at the border, enter the queens chamber face one-of neighbors4 with [class > my-class] fd .2 backstep ] ] [ ;current location is queens nest, new dirt, or escape route let class-ahead [class] of patch-ahead 1 ifelse class-ahead = 3 or class-ahead = 5 or class-ahead = 4 [ fd .3 ] [ set heading heading + ((random 150) - 75)] ifelse higherClass = false [ ;not on the border ] [ ifelse qx > -2 [ ;on the border if (count neighbors with [class = 5] >= 2) and (count neighbors with [class = 3] >= 2) [ if mud = 1 [ set mud 0 ask neighbors4 [ newDirt ] ask patch-here [ newDirt ] ] ] ] [ ifelse (count neighbors with [class = 5] >= 2) and (count neighbors with [class = 3] >= 2) [] [ if mud = 1 [ if any? neighbors4 with [class = 4] [ ask one-of neighbors4 with [class = 4] [ set pcolor pcolor - .1 ] ] ] ] ] ] ifelse qx > -2 [queenChain] [ ifelse [class] of patch-here = 3 ;stuck in queens nest [ terMove ] [farQueenChain] ] ] end ;************************** ;DEFAULT SOLDIER MOVEMENT to sSolMove let class-ahead [class] of patch-ahead 1 let y-ahead [pycor] of patch-ahead 1 ifelse (class-ahead = 1 or class-ahead = 4) and y-ahead > -17 [ fd .2 ] [ set heading heading + ((random 150) - 75)] end ;ASSAULT SOLDIER MOVEMENT to protectTheQueen ifelse any? neighbors with [qLevel > 0] ;queens nest [ face max-one-of neighbors4 [qLevel] let class-ahead [class] of patch-ahead 1 ifelse class-ahead = 1 [ fd .2 ] [ ifelse class-ahead = 3 [ ;patrol set heading ((random 3) - 1) * 90 fd .2 backstep ] [set heading heading + ((random 150) - 75)] ] ] [ set heading heading + 180 fd .2 ] end ;************************** ;DEFAULT ANT MOVEMENT to antMove let class-ahead [class] of patch-ahead 1 let x-ahead [pxcor] of patch-ahead 1 let y-ahead [pycor] of patch-ahead 1 let temp false ask patch-ahead 1 [ set temp any? neighbors4 with [class = 0] ] ifelse (class-ahead = 1 or class-ahead = 4 or class-ahead = 2) and (temp = true) [ fd .125 if any? neighbors4 with [class = 4] [ ;signal to other ants of the breach sendSignal ;show "SEND SIGNAL" bk .125 set breachx xcor set breachy ycor fd .125 ] ] [ set heading heading + ((random 150) - 75)] end ;ASSAULT ANT MOVEMENT to assault let fightOrMove any? sSoldiers-on neighbors4 if fightOrMove = false [ ifelse any? neighbors4 with [qLevel > 0] [ face max-one-of neighbors4 [qLevel] let retreatCheck [class] of patch-ahead 1 if retreatCheck = 0 ;termites have escaped [ set breach 2 ] fd .1 if [class] of patch-here = 0 [ set heading heading + 180 fd .125 ] ] [ ifelse any? neighbors with [sigStr > 0] [ face max-one-of neighbors4 [sigStr] fd .1 if [class] of patch-here = 0 [ set heading heading + 180 fd .125 ] if ([class] of patch-here = 2 and [pcolor] of patch-here > 32) [ ask patch-here [set pcolor 39] ] ] [ ;show "NOTHING" set heading heading + 180 fd .125 ] ] ] end ;ANT RETREAT to retreat termove end to backStep if [class] of patch-here = 0 [ set heading heading + 180 fd .25 ] end ;************************** ;QUEEN SCENT MOVEMENT to qMove let class-ahead [class] of patch-ahead 1 ifelse class-ahead = 1 or class-ahead = 4 or class-ahead = 3 or class-ahead = 5 [ fd 1 set energy energy - .1 if energy < 80 [ die ] setQlevel energy if class-ahead = 2 [ set heading random 360 ] ] [ set heading heading + ((random 150) - 75)] end to setQlevel [en] ; keeps only shortest path ask patch-here [ if en > qlevel [ set qLevel en sprout-qScents 4 [ set energy [qLevel] of patch-here set size 0 ] ] ] end ;************************** ;QUEEN MOVEMENT to queenMove set qx xcor + 3 set qy ycor if count sWorkers-on neighbors4 > 25 ;startTermiteCount / 100 [ let yourPatch [class] of patch-here ifelse yourPatch = 3; queens nest [ set heading 255 + random 30 fd .05 set qMoves qMoves + .005 ask patches with [pxcor = [pxcor] of myself and pycor = [pycor] of myself - 3 + random 6 ] [ set qLevel 90 + qMoves ] ] [ let class-ahead [class] of patch-ahead 3 ifelse class-ahead = 5 or class-ahead = 4 or class-ahead = 3 [ fd .05 set qMoves qMoves + .005 ask patches with [pxcor = [pxcor] of myself and pycor = [pycor] of myself - 3 + random 6 ] [ if class != 0 [ set qLevel 90 + qMoves ;show qLevel ] ] ] [ set heading 240 + random 60 ] ] ] end
There are 15 versions of this model.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.