Jump to content

Random Walker: Difference between revisions

From SELESwiki
No edit summary
 
Line 91: Line 91:
   LastDirection = IF (Location EQ SOURCE Location) THEN LastDirection ELSE ROUND(DIRECTION(SOURCE Location, Location))
   LastDirection = IF (Location EQ SOURCE Location) THEN LastDirection ELSE ROUND(DIRECTION(SOURCE Location, Location))
  ENDMP
  ENDMP
===producer.lse===
// Process based definiton of producer  behaviour in producer/consumer model
LSEVENT: Producer
DEFINITIONS
  LAYER: LSState, PrevLSState
  GLOBAL CONSTANT: Uncolonised, Producer,  Consumer
  GLOBAL VARIABLE: pInitialProducer,  pSpreadProducer, pDeathProducer //,  SpreadRateProducer
ENDDEF
// Just start once
RETURNTIME = 0
// Initialize in an empty cell
PROBINIT = IF LSState EQ Uncolonised THEN  pInitialProducer ELSE 0
TRANSITIONS
  // Decide if this cell survives
  Dies = UNIFORM(0,1) < pDeathProducer
  // If the producer is dying
  IF Dies
      LSState = Uncolonised
  ENDFN
  TRANSITIONS = (!Dies)
  LSState = Producer
ENDTR
SPREADTIMESTEP = 1 //SpreadRateProducer
SPREADLOCATION
  notEaten = PrevLSState EQ Producer //  check that the producer wasn't eaten  during the last step
  REGION CENTRED(0, 1, WRAPPED)
      DECISION notEaten // don't spread if  eaten (i.e. stop process)
ENDSL
SPREADPROB
  // Always spread to the same cell  (self), and spread probabilistically to  empty neighbouring cells
  SPREADPROB = IF Location EQ (SOURCE  Location) THEN 1 // spread to same cell
              ELSE IF PrevLSState EQ  Uncolonised THEN pSpreadProducer
              ELSE 0
ENDSP
===update.lse===
// Event to update time step
LSEVENT: Update
DEFINITIONS
  LAYER: LSState, PrevLSState
ENDDEF
RETURNTIME
  RETURNTIME = 1
  PrevLSState = LSState
ENDRT
NUMCLUSTERS = 0


==Suggested Experiments==
==Suggested Experiments==


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

Latest revision as of 17:41, 14 November 2006

Summary

Screenshot

Download Model

Download the .scn, .sel and .lse files by clicking on the following link: File:RandomWalker.zip

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

Seles Scenario
RandomWalker.sel
SimPriority Low Priority

RandomWalker.sel

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

/* 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

Suggested Experiments

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