Jump to content

Random Walker: Difference between revisions

From SELESwiki
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 14: Line 14:
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.
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.


===Consume.scn===
===RandomWalker.scn===
  Seles Scenario
  Seles Scenario
  Model.sel
  RandomWalker.sel
  SimPriority Low Priority
  SimPriority Low Priority


===Model.sel===
===RandomWalker.sel===
  Seles Model
  Seles Model
Model Size: 200, 200
  Time Units: Step kiloStep 1000 1000
  Time Units: Step kiloStep 1000 1000
  Landscape Events:
  Landscape Events:
   Producer.lse DEBUG
   RandomWalker.lse DEBUG
  Consumer.lse DEBUG
Global Constants:
   Update.lse DEBUG
   MaxNumPresent = 100
  Spatial Variables:
  Spatial Variables:
   LSState[3]
   NumPresent[MaxNumPresent]
  PrevLSState[3]
Legends:
  LSStateTypes = {0:Uncolonised,    1:Producer, 2:Consumer}
  Global Variables:
  Global Variables:
   pInitialProducer = 0.01
   nInitial = MaxNumPresent
  pInitialConsumer = 0.01
  pSpreadProducer = 0.1
  pSpreadConsumer = 0.2
  pDeathProducer = 0.01
  pDeathConsumer = 0.05
//  SpreadRateProducer = 1
//  SpreadRateConsumer = 1
  Output Frequency: 1
  Output Frequency: 1


===consumer.lse===
===RandomWalker.lse===
  // Process based definition for consumber behaviour in producer/consumer  model
/* This file contains a landscape agent definition for a random walker */
  LSEVENT: Consumder
  LSAGENT: RandomWalker
  DEFINITIONS
  DEFINITIONS
   LAYER: LSState, PrevLSState
   LAYER: NumPresent
   GLOBAL CONSTANT: Uncolonised, Producer,  Consumer
  GLOBAL VARIABLE: nInitial
   GLOBAL VARIABLE: pInitialConsumer,  pSpreadConsumer, pDeathConsumer //, SpreadRateConsumer
   GLOBAL CONSTANT: MaxNumPresent
   AGENT VARIABLE: LastDirection, StartLoc
  ENDDEF
  ENDDEF
  // Just start once
  MOVELOCATION
  RETURNTIME = 0
  REGION CENTRED(0,1.5,WRAPPED)
  // Initialize in an empty cell
ENDML
  PROBINIT = IF LSState EQ Uncolonised THEN pInitialConsumer ELSE 0
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
  // Decide if this cell survives
   TRANSITIONS = TRUE
  Dies = UNIFORM(0,1) < pDeathConsumer
  // If the consumer is dying
  IF Dies
      LSState = Uncolonised
  ENDFN
   TRANSITIONS = !Dies
  LSState = Consumer
  ENDTR
  ENDTR
  SPREADTIMESTEP = 1 //SpreadRateConsumer
  MOVEPROB
SPREADLOCATION
  // BEFORE MOVING: These expressions will be evaluated at
   REGION CENTRED(0,1, WRAPPED)
  // all potential move locations
ENDSL
   // For a correlated random walk
SPREADPROB
   // For the current location, assume direction is the same
   // Always spread to the same cell  (self), and spread probabilistical to  neighbouring producer cells
  IF (Location EQ SOURCE Location)
  SPREADPROB = IF Location EQ (SOURCE Location) THEN 1
      dirDiff = 0
              ELSE IF PrevLSState EQ  Producer  THEN pSpreadConsumer
   // Otherwise, compute the angel between the current direction and direction to this cell
              ELSE 0
  ELSE
ENDSP
      dirDiff = LastDirection - ROUND(DIRECTION(SOURCE Location, Location))
 
      dirDiff = |dirDiff|
===producer.lse===
      // Ensure we consider smallest angle between the two directions
// Process based definiton of producer  behaviour in producer/consumer model
       dirDiff = IF dirDiff > 180 THEN 360 - dirDiff ELSE dirDiff
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
   ENDFN
  TRANSITIONS = (!Dies)
//  MOVEPROB = IF dirDiff EQ 0 THEN 1 ELSE (1/dirDiff)^0.5
  LSState = Producer
//  MOVEPROB = 1/MAX(1,DISTANCE(Location, StartLoc))
ENDTR
  MOVEPROB = 1
SPREADTIMESTEP = 1 //SpreadRateProducer
  // AFTER MOVING: These expressions will be evaluated only
SPREADLOCATION
   // at the chosen move location
   notEaten = PrevLSState EQ Producer // check that the producer wasn't eaten  during the last step
   SOURCE NumPresent = MAX(0,SOURCE NumPresent - 1)
   REGION CENTRED(0, 1, WRAPPED)
  NumPresent = MIN(NumPresent + 1, MaxNumPresent)
      DECISION notEaten // don't spread if  eaten (i.e. stop process)
   LastDirection = IF (Location EQ SOURCE Location) THEN LastDirection ELSE ROUND(DIRECTION(SOURCE Location, Location))
ENDSL
  ENDMP
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: