CaneToads

Model to accompany Module 12.4, "Modeling an 'Able' Invader?the 'Cane' Toad," from "Introduction to Computational Science: Modeling and Simulation for the Sciences," 2nd ed., by Angela B. Shiflet and George W. Shiflet, Princeton University Press. Copyright 2013.In the vast parts of arid Australia during the dry season, artificial water points (AWPs), such as troughs or dams for livestock, can serve as invasion hubs for cane toads. Thus, targeting AWPs might help prevent the spread of this invasive species. This model studies the effect of fencing AWPs on adult cane toad invasion.



Agents

Number of agents: 4

Behaviors


BorderBorder

Number of methods: 2


WHEN-CREATING-NEW-AGENT ()

Count number of StartBorder tiles (numStartBorder). Put food and moisture on borders: -1 for both on StartBorder and Border so that Toads do not go there. 2 on FinishBorder so that Toads are attracted there.

Number of rules: 3 

If
SEE ((0 0) , startborder)
Then
SET (food , to , -1), and
SET (moisture , to , -1)

If
SEE ((0 0) , border)
Then
SET (food , to , -1), and
SET (moisture , to , -1)

If
SEE ((0 0) , finishborder)
Then
SET (food , to , 2), and
SET (moisture , to , 2)

ON (createToads)

Create toad with probability INIT_PERCENT_TOADS/100

Number of rules: 1 

If
SEE ((0 0) , startborder), and
%-CHANCE (@INIT_PERCENT_TOADS)
Then
NEW ((0 0) , toad)



DesertDesert

Number of methods: 9


WHEN-CREATING-NEW-AGENT ()

Initialize moisture and food. Make both -1 for FencedAwp so that a toad does not move towards that location.

Number of rules: 6 

If
SEE ((0 0) , desert)
Then
SET (moisture , to , 0), and
SET (food , to , @FOOD_CELL)

If
SEE ((0 0) , awp)
Then
SET (moisture , to , 1), and
SET (food , to , @FOOD_CELL)

If
SEE ((0 0) , fencedawp)
Then
SET (moisture , to , -1), and
SET (food , to , -1)

If
SEE ((0 0) , awpadjacent)
Then
SET (moisture , to , @AMT_AWP_ADJACENT), and
SET (food , to , @FOOD_CELL)

If
SEE ((0 0) , awpover2)
Then
SET (moisture , to , @AMT_AWP_OVER2), and
SET (food , to , @FOOD_CELL)

If
SEE ((0 0) , moistarea)
Then
SET (moisture , to , @AMT_MOIST_AREA), and
SET (food , to , @FOOD_CELL)

ON (initDesert)

Initialize desert color

Number of rules: 1 

If
SEE ((0 0) , desert)
Then
SET (food , to , @FOOD_CELL), and
MAP (food , to Color , between , 15263976 , for , 0 , and , 7368816 , for , @FOOD_CELL)

ON (placeAwps)

Place AWPs, fenced AWPs, and moist areas on desert. Chance of changing a Desert agent to an Awp agent is PERCENT_AWPS/100. Chance of changing a Desert agent to a MoistArea agent is PERCENT_MOIST_AREAS/100.

Number of rules: 1 

If
SEE ((0 0) , desert), and
%-CHANCE (@PERCENT_AWPS)
Then
ERASE ((0 0)), and
NEW ((0 0) , awp)

ON (placeFencedAwps)

Chance of changing an Awp agent to a FencedAwp is PERCENT_AWPS_FENCED/100.

Number of rules: 1 

If
%-CHANCE (@PERCENT_AWPS_FENCED), and
SEE ((0 0) , awp)
Then
ERASE ((0 0)), and
NEW ((0 0) , fencedawp)

ON (initAwp1)

If current agent is a Desert agent that is staced below another desert agent (such as an Awp agent), erase the current agent. If The current agent is a Desert agent that is adjacent to an Awp or a FencedAwp agent, change the current agent to an AwpAdjacent agent.

Number of rules: 2 

If
SEE ((0 0) , desert), and
NEXT-TO (> , 0 , awp)
Then
ERASE ((0 0)), and
NEW ((0 0) , awpadjacent)

If
SEE ((0 0) , desert), and
NEXT-TO (> , 0 , fencedawp)
Then
ERASE ((0 0)), and
NEW ((0 0) , awpadjacent)

ON (initAwp2)

If The current agent is a Desert agent that is adjacent to an AwpAdjacent agent, change the current agent to an AwpOver2 agent.

Number of rules: 1 

If
SEE ((0 0) , desert), and
NEXT-TO (> , 0 , awpadjacent)
Then
ERASE ((0 0)), and
NEW ((0 0) , awpover2)

ON (updateFood)

Update the food for a desert agent after a toad on top of it has eaten.

Number of rules: 4 

If
SEE ((0 0) , desert), and
STACKED-A (immediately below , a , Toad)
Then
SET (food , to , food - amtEat[top]), and
MAP (food , to Color , between , 15263976 , for , 0 , and , 7368816 , for , @FOOD_CELL)

If
SEE ((0 0) , desert), and
STACKED-A (immediately above , a , Toad)
Then
SET (food , to , food - amtEat[top]), and
MAP (food , to Color , between , 15263976 , for , 0 , and , 7368816 , for , @FOOD_CELL)

If
SEE-A ((0 0) , Desert), and
STACKED-A (immediately below , a , Toad)
Then
SET (food , to , food - amtEat[top])

If
SEE-A ((0 0) , Desert), and
STACKED-A (immediately above , a , Toad)
Then
SET (food , to , food - amtEat[top])

ON (makeUnfenced)

Make fenced AWP unfenced

Number of rules: 1 

If
SEE ((0 0) , fencedawp)
Then
ERASE ((0 0)), and
NEW ((0 0) , awp)

ON (makeFenced)

Make unfenced AWP fenced

Number of rules: 1 

If
SEE ((0 0) , awp)
Then
ERASE ((0 0)), and
NEW ((0 0) , fencedawp)



SimulationdriverSimulationdriver

Number of methods: 4


WHILE-RUNNING ()

Simulation. Phase 0: initialization of area aroud AWPs and creation of cane toads on starting boarder. Phase 1: Toads eating and drinking. Phase 2: Toads moving. Phase 3: Toads changing state.

Number of rules: 4 

If
IS (phase , = , 0)
Then
BROADCAST (Border , createToads), and
BROADCAST (Desert , initDesert), and
BROADCAST (Desert , placeAwps), and
BROADCAST (Desert , placeFencedAwps), and
BROADCAST (Desert , initAwp1), and
BROADCAST (Desert , initAwp2), and
SET (phase , to , 1)

If
IS (phase , = , 1)
Then
BROADCAST (Toad , toadMayEat), and
BROADCAST (Toad , toadMayDrink), and
BROADCAST (Desert , updateFood), and
BROADCAST (Toad , showToad), and
SET (phase , to , 2)

If
IS (phase , = , 2)
Then
BROADCAST (Toad , toadMove), and
SET (phase , to , 3)

If
IS (phase , = , 3)
Then
BROADCAST (Toad , changeCounts), and
MAKE ((0 0) , checkTerminate), and
SET (phase , to , 1)

ON (checkTerminate)

Check if the simulation should terminate because no more toads exist on the grid

Number of rules: 1 

If
IS (@numAlive , = , 0)
Then
STOP-SIMULATION ()

ON (makeAllUnfenced)

Procedure to ask all AWPs to become unfenced - for creating a landscape of unfenced AWPs

Number of rules: 1 

If
no condition
Then
BROADCAST (Desert , makeUnfenced)

ON (makeAllFenced)

Procedure to ask all AWPs to become fenced - for creating a landscape of fenced AWPs

Number of rules: 1 

If
no condition
Then
BROADCAST (Desert , makeFenced)



ToadToad

Number of methods: 21


WHEN-CREATING-NEW-AGENT ()

'food' and 'moisture' set to -1 to avoid more than 1 toad in same position

Number of rules: 1 

If
SEE ((0 0) , toad)
Then
SET (@numAlive , to , @numAlive + 1), and
SET (energy , to , @AMT_MIN_INIT + random(@INIT_RANGE)), and
SET (water , to , @AMT_MIN_INIT + random(@INIT_RANGE)), and
SET (availableFood , to , -1), and
SET (availableMoisture , to , -1), and
SET (food , to , -1), and
SET (moisture , to , -1)

ON (toadMayEat)

Toad behavior regarding eating

Number of rules: 2 

If
STACKED-A (somewhere above , a , Desert), and
IS (energy , < , @WOULD_LIKE_EAT)
Then
MAKE ((0 0) , eat)

If
no condition
Then
SET (amtEat , to , 0)

ON (eat)

Function to update a toad's energy and water after it eats

Number of rules: 1 

If
no condition
Then
MAKE ((0 0) , calcAmtEat), and
SET (energy , to , energy + amtEat), and
MAKE ((0 0) , waterFromFood)

ON (calcAmtEat)

Calculate amtEat the minimum of @AMT_EAT, food, and 1 - energy.

Number of rules: 1 

If
no condition
Then
SET (oneMinusEnergy , to , 1-energy), and
SET (minAMTEATAvail , to , min(@AMT_EAT,availableFood)), and
SET (amtEat , to , min(oneMinusEnergy,minAMTEATAvail))

ON (waterFromFood)

Update toad's water obtained from food

Number of rules: 2 

If
IS (water + @FRACTION_WATER * amtEat , < , 1)
Then
SET (water , to , water + @FRACTION_WATER * amtEat)

If
no condition
Then
SET (water , to , 1)

ON (toadMayDrink)

Toad behavior regarding drinlomg

Number of rules: 1 

If
IS (water , < , @WOULD_LIKE_DRINK), and
STACKED (somewhere above , awp)
Then
MAKE ((0 0) , drink)

ON (drink)

Function to update a toad's water after it drinks

Number of rules: 2 

If
IS (water + @AMT_DRINK , <= , 1)
Then
SET (water , to , water + @AMT_DRINK)

If
no condition
Then
SET (water , to , 1)

ON (showToad)

For toad hidden by desert agent, move forward, update availableFood (possibly changed for desert agent), and back so that it shows.

Number of rules: 1 

If
STACKED-A (somewhere below , a , Desert)
Then
SET (availableFood , to , food[bottom])

ON (toadMove)

Possibly move the toad

Number of rules: 4 

If
IS (water , < , @WOULD_LIKE_DRINK)
Then
MAKE ((0 0) , thirsty)

If
IS (energy , < , @WOULD_LIKE_EAT)
Then
MAKE ((0 0) , lookForFood)

If
IS (random(1.0) , < , @MAY_HOP)
Then
MAKE ((0 0) , hopForFun)

If
no condition
Then
MAKE ((0 0) , stayHere)

ON (thirsty)

Function to change the position of a very thirsty toad

Number of rules: 4 

If
STACKED (somewhere above , awp)
Then
MAKE ((0 0) , stayHere)

If
STACKED-A (somewhere above , a , Desert)
Then
SET (maxMoisture , to , max(moisture[up],max(moisture[right],max(moisture[down],moisture[left])))), and
MAKE ((0 0) , lookForMoisture)

If
STACKED (somewhere above , startborder), and
SEE-A ((0 -1) , Desert)
Then
MAKE ((0 0) , moveW)

If
STACKED (somewhere above , startborder)
Then
MAKE ((0 0) , stayHere)

ON (lookForMoisture)

Function to move toad towards maximum moisture when toad was at current location at last time step. Called by lookForMoisture.

Number of rules: 2 

If
IS (maxMoisture , < , 0)
Then
MAKE ((0 0) , stayHere)

If
no condition
Then
HILLCLIMB (moisture , in , Four Directions (Von Neumann neighborhood)), and
MAKE ((0 0) , here), and
MAKE ((0 0) , useWaterEnergyHopping)

ON (here)

Function to update a toad's state when staying in the current location

Number of rules: 1 

If
no condition
Then
SET (availableFood , to , food[bottom]), and
SET (availableMoisture , to , moisture[bottom])

ON (stayHere)

Procedure for toad to stay in current location

Number of rules: 1 

If
no condition
Then
MAKE ((0 0) , here), and
MAKE ((0 0) , useWaterEnergySitting)

ON (hopHere)

Procedure when toad hops to current location

Number of rules: 1 

If
no condition
Then
MAKE ((0 0) , here), and
MAKE ((0 0) , useWaterEnergyHopping)

ON (moveW)

Function to update a toad's state when moving to the west

Number of rules: 1 

If
no condition
Then
MOVE ((0 -1)), and
MAKE ((0 0) , here), and
MAKE ((0 0) , useWaterEnergyHopping)

ON (lookForFood)

Function to have a toad go to/remain at a vacant neighborhood location with the maximum amount of food

Number of rules: 3 

If
STACKED (somewhere above , startborder), and
SEE-A ((0 -1) , Desert)
Then
MAKE ((0 0) , moveW)

If
STACKED (somewhere above , startborder)
Then
MAKE ((0 0) , stayHere)

If
no condition
Then
SET (maxFood , to , max(availableFood,max(food[up],max(food[right],max(food[down],food[left]))))), and
MAKE ((0 0) , goToFood)

ON (goToFood)

Function to update a toad's location to hop in a random "legal" direction with the most amount of food

Number of rules: 2 

If
IS (availableFood , = , maxFood)
Then
MAKE ((0 0) , stayHere)

If
no condition
Then
HILLCLIMB (food , in , Four Directions (Von Neumann neighborhood)), and
MAKE ((0 0) , here), and
MAKE ((0 0) , useWaterEnergyHopping)

ON (useWaterEnergySitting)

Procedure to reduce a toad's energy and water after sitting

Number of rules: 3 

If
STACKED (immediately above , startborder)
Then
SET (energy , to , energy - 0.5*@ENERGY_HOPPING), and
SET (water , to , water - 0.5*@WATER_HOPPING)

If
STACKED (immediately above , desert)
Then
SET (energy , to , energy - 0.5*@ENERGY_HOPPING), and
SET (water , to , water - 0.5*@WATER_HOPPING)

If
no condition
Then
SET (energy , to , energy - 0.5*@ENERGY_HOPPING)

ON (useWaterEnergyHopping)

Procedure to reduce a toad's energy and water after hopping

Number of rules: 3 

If
STACKED (immediately above , startborder)
Then
SET (energy , to , energy - @ENERGY_HOPPING), and
SET (water , to , water - @WATER_HOPPING)

If
STACKED (immediately above , desert)
Then
SET (energy , to , energy - @ENERGY_HOPPING), and
SET (water , to , water - @WATER_HOPPING)

If
no condition
Then
SET (energy , to , energy - @ENERGY_HOPPING)

ON (hopForFun)

Function to update a toad's location to hop in a random "legal" direction if possible

Number of rules: 4 

If
STACKED (somewhere above , startborder), and
SEE-A ((0 -1) , Desert)
Then
MAKE ((0 0) , moveW)

If
STACKED (somewhere above , startborder)
Then
MAKE ((0 0) , stayHere)

If
NEXT-TO (> , 0 , desert)
Then
MOVE-RANDOM-ON (desert), and
MAKE ((0 0) , hopHere)

If
no condition
Then
MAKE ((0 0) , stayHere)

ON (changeCounts)

Method to eliminate a toad that should be dead or migrated

Number of rules: 3 

If
IS (water , < , @DESICCATE)
Then
ERASE ((0 0)), and
SET (@numAlive , to , @numAlive - 1), and
SET (@numDead , to , @numDead + 1)

If
IS (energy , < , @STARVE)
Then
ERASE ((0 0)), and
SET (@numAlive , to , @numAlive - 1), and
SET (@numDead , to , @numDead + 1)

If
STACKED (somewhere above , finishborder)
Then
ERASE ((0 0)), and
SET (@numAlive , to , @numAlive - 1), and
SET (@numMigrated , to , @numMigrated + 1)


This report was generated using AgentSheets Version 4.0.0