Random Walker

Download Model
Download the .scn, .sel and .lse files by clicking on the following link:

Model Code Exploration
In the following sections we will examine all of the model files for this model. Note that instead of downloading the zip file above, you could just copy the text in the boxes below into a text editor and save it with the appropriate name (Section title). Opening the resulting .scn file in the SELES simulator would run this model.

RandomWalker.scn
Example 1: Seles Scenario RandomWalker.sel SimPriority Low Priority

Example 2: Scenario Information Habitat = ..\..\outputFiles\cell\Habitat Model Dimensions: Habitat RandomWalker.sel SimPriority Low Priority

RandomWalker.sel
Example 1: Seles Model Model Size: 200, 200 Time Units: Step kiloStep 1000 1000 Landscape Events: RandomWalker.lse DEBUG Global Constants: MaxNumPresent = 100 Spatial Variables: NumPresent[MaxNumPresent] Global Variables: nInitial = MaxNumPresent Output Frequency: 1

Example 2: Seles Model Model Size: 200, 200 Time Units: Step kiloStep 1000 1000 Landscape Events: RandomWalker.lse DEBUG Global Constants: MaxNumPresent = 100 Spatial Variables: NumPresent[MaxNumPresent] Global Variables: nInitial = MaxNumPresent Output Frequency: 1

RandomWalker.lse
Example 1: /* This file contains a landscape agent definition for a random walker */ LSAGENT: RandomWalker DEFINITIONS LAYER: NumPresent GLOBAL VARIABLE: nInitial GLOBAL CONSTANT: MaxNumPresent AGENT VARIABLE: LastDirection, StartLoc ENDDEF MOVELOCATION REGION CENTRED(0,1.5,WRAPPED) ENDML INITIALSTATE INITIALSTATE = 1 //  nInitial = CLAMP(nInitial, 1, MaxNumPresent) ENDIS /* AGENTLOCATION REGION RECT(0,0,0,0) ENDAL */ NUMAGENTS NUMAGENTS = nInitial NumPresent = MIN(NumPresent + 1, MaxNumPresent) // Pick a start direction in one of the cardinal directions LastDirection = 45 * FLOOR(UNIFORM(0,8)) StartLoc = Location ENDNA POPULATIONTIME POPULATIONTIME = 1 PAUSE(50) ENDPT TRANSITIONS TRANSITIONS = TRUE ENDTR MOVEPROB // BEFORE MOVING: These expressions will be evaluated at  // all potential move locations // For a correlated random walk // For the current location, assume direction is the same IF (Location EQ SOURCE Location) dirDiff = 0 // Otherwise, compute the angel between the current direction and direction to this cell ELSE dirDiff = LastDirection - ROUND(DIRECTION(SOURCE Location, Location)) dirDiff = |dirDiff| // Ensure we consider smallest angle between the two directions dirDiff = IF dirDiff > 180 THEN 360 - dirDiff ELSE dirDiff ENDFN //  MOVEPROB = IF dirDiff EQ 0 THEN 1 ELSE (1/dirDiff)^0.5 //  MOVEPROB = 1/MAX(1,DISTANCE(Location, StartLoc)) MOVEPROB = 1 // AFTER MOVING: These expressions will be evaluated only // at the chosen move location SOURCE NumPresent = MAX(0,SOURCE NumPresent - 1) NumPresent = MIN(NumPresent + 1, MaxNumPresent) LastDirection = IF (Location EQ SOURCE Location) THEN LastDirection ELSE ROUND(DIRECTION(SOURCE Location, Location)) ENDMP

Example 2: /* This file contains a landscape agent definition for a random walker */ LSAGENT: RandomWalker DEFINITIONS LAYER: NumPresent, Habitat, Sex GLOBAL VARIABLE: nInitial GLOBAL CONSTANT: MaxNumPresent AGENT VARIABLE: LastDirection, sex ENDDEF INITIALSTATE INITIALSTATE = 1 //  nInitial = CLAMP(nInitial, 1, MaxNumPresent) ENDIS AGENTLOCATION REGION WHOLE MAP DECISION(Habitat EQ 2) ENDAL NUMAGENTS NUMAGENTS = nInitial NumPresent = MIN(NumPresent + 1, MaxNumPresent) sex = IF UNIFORM(0,1) > 0.5 THEN 1 ELSE 2 Sex = MIN(sex, 2) // Pick a start direction in one of the cardinal directions LastDirection = 45 * FLOOR(UNIFORM(0,8)) ENDNA POPULATIONTIME POPULATIONTIME = 1 PAUSE(50) ENDPT TRANSITIONS survival = 0.8 agentSurvives = UNIFORM(0,1) <= survival NumPresent = IF agentSurvives EQ FALSE THEN MAX(NumPresent - 1,0) ELSE NumPresent Sex = 0 TRANSITIONS = agentSurvives ENDTR // Minimally, ensure that there is at least 1 cell they can move to // Otherwise, they will disappear. MOVELOCATION REGION CENTRED(0,6,EUCLIDEAN) //DECISION(Habitat > 0) ENDML MOVEPROB // BEFORE MOVING: These expressions will be evaluated at  // all potential move locations // For a correlated random walk /*   // For the current location, assume direction is the same IF (Location EQ SOURCE Location) dirDiff = 0 // Otherwise, compute the angel between the current direction and direction to this cell ELSE dirDiff = LastDirection - ROUND(DIRECTION(SOURCE Location, Location)) dirDiff = IF (dirDiff < 0) THEN -1 * dirDiff ELSE dirDiff // Ensure we consider smallest angle between the two directions dirDiff = IF dirDiff > 180 THEN 360 - dirDiff ELSE dirDiff ENDFN MOVEPROB = IF dirDiff EQ 0 THEN 1 ELSE (1/dirDiff) */  MOVEPROB = IF Habitat EQ 2 THEN 3 ELSE 1 // AFTER MOVING: These expressions will be evaluated only // at the chosen move location SOURCE NumPresent = MAX(0,SOURCE NumPresent - 1) NumPresent = MIN(NumPresent + 1, MaxNumPresent) LastDirection = IF (Location EQ SOURCE Location) THEN LastDirection ELSE ROUND(DIRECTION(SOURCE Location, Location)) SOURCE Sex = 0 Sex = MIN(sex, 2) ENDMP NUMOFFSPRING fecundity = 0.25 agentReproduces = UNIFORM(0,1) <= fecundity NUMOFFSPRING = agentReproduces sex = IF UNIFORM(0,1) > 0.5 THEN 1 ELSE 2 Sex = MIN(sex, 2) ENDNO

Suggested Experiments
To explore this cellular automata model further, try the following: