Jump to content

The IBM2 model: Difference between revisions

From SELESwiki
No edit summary
 
No edit summary
 
Line 25: Line 25:
   Producer.lse DEBUG
   Producer.lse DEBUG
   Consumer.lse DEBUG
   Consumer.lse DEBUG
  Update.lse DEBUG
  Spatial Variables:
  Spatial Variables:
   LSState[3]
   LSState[3]
  PrevLSState[3]
  Legends:
  Legends:
   LSStateTypes = {0:Uncolonised,   1:Producer, 2:Consumer}
   LSStateTypes = {0:Uncolonised, 1:Producer, 2:Consumer}
  Global Variables:
  Global Variables:
   pInitialProducer = 0.01
   pInitialProducer = 0.01
Line 38: Line 36:
   pDeathProducer = 0.01
   pDeathProducer = 0.01
   pDeathConsumer = 0.05
   pDeathConsumer = 0.05
//  SpreadRateProducer = 1
//  SpreadRateConsumer = 1
  Output Frequency: 1
  Output Frequency: 1


===consumer.lse===
===consumer.lse===
   // Process based definition for consumber behaviour in producer/consumer model
   // Process based definition for consumber behaviour in producer/consumer model
  LSEVENT: Consumder
  LSAGENT: Consumer
  DEFINITIONS
  DEFINITIONS
   LAYER: LSState, PrevLSState
   LAYER: LSState
   GLOBAL CONSTANT: Uncolonised, Producer, Consumer
   GLOBAL CONSTANT: Uncolonised, Producer, Consumer
   GLOBAL VARIABLE: pInitialConsumer,   pSpreadConsumer, pDeathConsumer //, SpreadRateConsumer
   GLOBAL VARIABLE: pInitialConsumer, pSpreadConsumer, pDeathConsumer //, SpreadRateConsumer
  AGENT VARIABLE: isParent
  ENDDEF
  ENDDEF
  // Just start once
  // Just immigrate once
  RETURNTIME = 0
  IMMIGRATIONTIME = 0
NUMAGENTS = NUMCELLS * pInitialConsumer
  // Initialize in an empty cell
  // Initialize in an empty cell
  PROBINIT = IF LSState EQ Uncolonised THEN pInitialConsumer ELSE 0
  PROBINIT
  PROBINIT = LSState EQ Uncolonised
  LSState = Consumer
  isParent = TRUE
  ENDPI
  TRANSITIONS
  TRANSITIONS
   // Decide if this cell survives
   // Decide if this cell survives
Line 62: Line 64:
   ENDFN
   ENDFN
   TRANSITIONS = !Dies
   TRANSITIONS = !Dies
  LSState = Consumer
  ENDTR
  ENDTR
  SPREADTIMESTEP = 1 //SpreadRateConsumer
  POPULATIONTIME = 1
  SPREADLOCATION
  MOVELOCATION
   REGION CENTRED(0,1, WRAPPED)
  d = IF isParent THEN 0 ELSE 1
  ENDSL
   REGION CENTRED(d, 1, WRAPPED)
  SPREADPROB
  ENDML
   // Always spread to the same cell  (self), and spread probabilistical to neighbouring producer cells
  MOVEPROB
   SPREADPROB = IF Location EQ (SOURCE Location) THEN 1
   // Parent can stay, move to an unoccupied neigbhour or move to a producer
              ELSE IF PrevLSState EQ   Producer THEN pSpreadConsumer
  // Children must move onto a producer
              ELSE 0
   MOVEPROB = IF isParent THEN (Location EQ SOURCE Location) OR (LSState NEQ Consumer)
  ENDSP
            ELSE LSState EQ Producer
  IF isParent
    SOURCE LSState = Uncolonised
  ENDFN
  isParent = TRUE
   LSState = Consumer
ENDMP
  NUMOFFSPRING
  n = 0
  OVER REGION CENTRED(1,1,WRAPPED)
      DECISION LSState EQ Uncolonised
      n = n + (UNIFORM(0,1) < pSpreadConsumer)
  ENDFN
  NUMOFFSPRING = n
  isParent = FALSE
  ENDNO


===producer.lse===
===producer.lse===
  // Process based definiton of producer behaviour in producer/consumer model
  // Agent based definiton of producer behaviour in producer/consumer model
  LSEVENT: Producer
  LSAGENT: Producer
  DEFINITIONS
  DEFINITIONS
   LAYER: LSState, PrevLSState
   LAYER: LSState
   GLOBAL CONSTANT: Uncolonised, Producer, Consumer
   GLOBAL CONSTANT: Uncolonised, Producer, Consumer
   GLOBAL VARIABLE: pInitialProducer, pSpreadProducer, pDeathProducer //,  SpreadRateProducer
   GLOBAL VARIABLE: pInitialProducer, pSpreadProducer, pDeathProducer
  AGENT VARIABLE: isParent
  ENDDEF
  ENDDEF
  // Just start once
  // Just immigrate once
  RETURNTIME = 0
  IMMIGRATIONTIME = 0
NUMAGENTS = NUMCELLS * pInitialProducer
  // Initialize in an empty cell
  // Initialize in an empty cell
  PROBINIT = IF LSState EQ Uncolonised THEN pInitialProducer ELSE 0
  PROBINIT
  PROBINIT = LSState EQ Uncolonised
  LSState = Producer
  isParent = TRUE
  ENDPI
  TRANSITIONS
  TRANSITIONS
   // Decide if this cell survives
   // Decide if this cell survives
   Dies = UNIFORM(0,1) < pDeathProducer
   Dies = (UNIFORM(0,1) < pDeathProducer) OR (LSState NEQ Producer)
   // If the producer is dying
   // If the producer is dying
   IF Dies
   IF Dies
Line 95: Line 117:
   ENDFN
   ENDFN
   TRANSITIONS = (!Dies)
   TRANSITIONS = (!Dies)
  LSState = Producer
  ENDTR
  ENDTR
  SPREADTIMESTEP = 1 //SpreadRateProducer
  POPULATIONTIME = 1
  SPREADLOCATION
  MOVELOCATION
   notEaten = PrevLSState EQ Producer //  check that the producer wasn't eaten  during the last step
   d = IF isParent THEN 0 ELSE 1
   REGION CENTRED(0, 1, WRAPPED)
   REGION CENTRED(d, 1, WRAPPED)
      DECISION notEaten // don't spread if eaten (i.e. stop process)
  ENDML
  ENDSL
  MOVEPROB
SPREADPROB
  // Parent can stay or move to an unoccupied neighbour
   // Always spread to the same cell  (self), and spread probabilistically to  empty neighbouring cells
   // Children must move onto an unnoccupied neighbour
   SPREADPROB = IF Location EQ (SOURCE Location) THEN 1 // spread to same cell
   MOVEPROB = (Location EQ SOURCE Location) OR (LSState EQ Uncolonised)
              ELSE IF PrevLSState EQ Uncolonised THEN pSpreadProducer
  IF isParent
              ELSE 0
    SOURCE LSState = Uncolonised
ENDSP
  ENDFN
 
  isParent = TRUE
===update.lse===
  LSState = Producer
  // Event to update time step
  ENDMP
  LSEVENT: Update
  NUMOFFSPRING
DEFINITIONS
  n = 0
   LAYER: LSState, PrevLSState
   OVER REGION CENTRED(1,1,WRAPPED)
ENDDEF
      DECISION LSState EQ Uncolonised
RETURNTIME
      n = n + (UNIFORM(0,1) < pSpreadProducer)
   RETURNTIME = 1
  ENDFN
   PrevLSState = LSState
   NUMOFFSPRING = n
ENDRT
   isParent = FALSE
  NUMCLUSTERS = 0
  ENDNO


==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 21:20, 15 November 2006

Summary

Screenshot

Download Model

Download the .scn, .sel and .lse files by clicking on the following link: File:ProducerConsumer.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.

Consume.scn

Seles Scenario
Model.sel
SimPriority Low Priority

Model.sel

Seles Model
Time Units: Step kiloStep 1000 1000
Landscape Events:
 Producer.lse DEBUG
 Consumer.lse DEBUG
Spatial Variables:
 LSState[3]
Legends:
 LSStateTypes = {0:Uncolonised, 1:Producer, 2:Consumer}
Global Variables:
 pInitialProducer = 0.01
 pInitialConsumer = 0.01
 pSpreadProducer = 0.1
 pSpreadConsumer = 0.2
 pDeathProducer = 0.01
 pDeathConsumer = 0.05
Output Frequency: 1

consumer.lse

 // Process based definition for consumber behaviour in producer/consumer model
LSAGENT: Consumer
DEFINITIONS
  LAYER: LSState
  GLOBAL CONSTANT: Uncolonised, Producer, Consumer
  GLOBAL VARIABLE: pInitialConsumer, pSpreadConsumer, pDeathConsumer //, SpreadRateConsumer
  AGENT VARIABLE: isParent
ENDDEF
// Just immigrate once
IMMIGRATIONTIME = 0
NUMAGENTS = NUMCELLS * pInitialConsumer
// Initialize in an empty cell
PROBINIT
  PROBINIT = LSState EQ Uncolonised
  LSState = Consumer
  isParent = TRUE
ENDPI
TRANSITIONS
  // Decide if this cell survives
  Dies = UNIFORM(0,1) < pDeathConsumer
  // If the consumer is dying
  IF Dies
      LSState = Uncolonised
  ENDFN
  TRANSITIONS = !Dies
ENDTR
POPULATIONTIME = 1
MOVELOCATION
  d = IF isParent THEN 0 ELSE 1
  REGION CENTRED(d, 1, WRAPPED)
ENDML
MOVEPROB
  // Parent can stay, move to an unoccupied neigbhour or move to a producer
  // Children must move onto a producer
 MOVEPROB = IF isParent THEN (Location EQ SOURCE Location) OR (LSState NEQ Consumer)
            ELSE LSState EQ Producer
 IF isParent
    SOURCE LSState = Uncolonised
 ENDFN
 isParent = TRUE
 LSState = Consumer
ENDMP
NUMOFFSPRING
  n = 0
  OVER REGION CENTRED(1,1,WRAPPED)
     DECISION LSState EQ Uncolonised
     n = n + (UNIFORM(0,1) < pSpreadConsumer)
  ENDFN
  NUMOFFSPRING = n
  isParent = FALSE
ENDNO

producer.lse

// Agent based definiton of producer behaviour in producer/consumer model
LSAGENT: Producer
DEFINITIONS
  LAYER: LSState
  GLOBAL CONSTANT: Uncolonised, Producer, Consumer
  GLOBAL VARIABLE: pInitialProducer, pSpreadProducer, pDeathProducer
  AGENT VARIABLE: isParent
ENDDEF
// Just immigrate once
IMMIGRATIONTIME = 0
NUMAGENTS = NUMCELLS * pInitialProducer 
// Initialize in an empty cell
PROBINIT
  PROBINIT = LSState EQ Uncolonised
  LSState = Producer
  isParent = TRUE
ENDPI
TRANSITIONS
  // Decide if this cell survives
  Dies = (UNIFORM(0,1) < pDeathProducer) OR (LSState NEQ Producer)
  // If the producer is dying
  IF Dies
     LSState = Uncolonised
  ENDFN
  TRANSITIONS = (!Dies)
ENDTR
POPULATIONTIME = 1
MOVELOCATION
  d = IF isParent THEN 0 ELSE 1
  REGION CENTRED(d, 1, WRAPPED)
ENDML
MOVEPROB
  // Parent can stay or move to an unoccupied neighbour
  // Children must move onto an unnoccupied neighbour
 MOVEPROB = (Location EQ SOURCE Location) OR (LSState EQ Uncolonised)
 IF isParent
    SOURCE LSState = Uncolonised
 ENDFN
 isParent = TRUE
 LSState = Producer
ENDMP
NUMOFFSPRING
  n = 0
  OVER REGION CENTRED(1,1,WRAPPED)
     DECISION LSState EQ Uncolonised
     n = n + (UNIFORM(0,1) < pSpreadProducer)
  ENDFN
  NUMOFFSPRING = n
  isParent = FALSE
ENDNO

Suggested Experiments

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