Jump to content

Distance Surface: Difference between revisions

From SELESwiki
No edit summary
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 4: Line 4:
==Screenshot==
==Screenshot==


[[Image:ConvexHull.gif]]
[[Image:DistanceSurface.gif]]


==Download Model==
==Download Model==


Download the .scn, .sel and .lse files by clicking on the following link: [[Image:ConvexHull.zip]]
Download the .scn, .sel and .lse files by clicking on the following link: [[Image:DistanceSurface.zip]]


==Model Code Exploration==
==Model Code Exploration==
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.


===MLM.scn===
===Dist2Roads.scn===
 
SELES Scenario
$gisData$ = ..\..\CaseStudy\gisData\cell
StudyArea = $gisData$\StudyArea
SrcLayer = $gisData$\roads
Model Dimensions: StudyArea
Model.sel
SimPriority Low Priority
SimStart 100000 1
===Dist2Streams.scn===
  SELES Scenario
  SELES Scenario
  $gisData$ = ..\..\CaseStudy_Morice\gisData\cell
  $gisData$ = ..\..\CaseStudy\gisData\cell
  StudyArea = $gisData$\BEC
  StudyArea = $gisData$\StudyArea
SrcLayer = $gisData$\water
  Model Dimensions: StudyArea  
  Model Dimensions: StudyArea  
  Model.sel
  Model.sel
  SimPriority Low Priority
  SimPriority Low Priority
  //SimStart 100000 1
  SimStart 100000 1
 
===Model.sel===


===Model.lse===
  Seles Model
  Seles Model
Time Units: Step kiloStep 1000 100000
  Landscape Events:
  Landscape Events:
ConvexHull.lse
  Distance.lse DEBUG
  Spatial Constants:
  Spatial Constants:
  StudyArea
  StudyArea
  SrcLayer
  Global Constants:
  CellWidth = CELL WIDTH(StudyArea)
  Spatial Variables:
  Spatial Variables:
ConvexHullPoints[1] <= 0
  DistanceFromSrc[CellWidth*(NumRows^2 + NumCols^2)^0.5 + 1] <= 0
ConvexHull[1] <= 0
  NearestSrcLoc[-1] <= 0
Global Variables:
TRLoc = 0
Output Frequency: 1
 
===ConvexHull.lse===


// Sweep-line approach to identifying convex hull using a worker agent
===Distance.lse===
  LSAGENT: ConvexHull
  LSEVENT: DistanceSurface
  DEFINITIONS
  DEFINITIONS
   LAYER: StudyArea, ConvexHull, ConvexHullPoints
   LAYER: StudyArea, SrcLayer
   GLOBAL VARIABLE: TRLoc
  LAYER: DistanceFromSrc, NearestSrcLoc
   LOCAL VARIABLE: EndingPivotLoc
   GLOBAL CONSTANT: CellWidth
   AGENT VARIABLE: PivotLocation, EdgeLocation, EdgeRow, EdgeCol
   CLUSTER VARIABLE: StartLocation
   CELL VARIABLE: distInc, d
  ENDDEF
  ENDDEF
  INITIALSTATE
  INITIALSTATE
  INITIALSTATE = 1
// Find the top-right-most point
  TRLoc = 0
   OVER REGION WHOLE MAP
   OVER REGION WHOLE MAP
       DECISION StudyArea > 0
       DECISION (StudyArea > 0)
       TRLoc = MAX(TRLoc, Location)
       DistanceFromSrc = CellWidth*(NUMROWS^2 + NUMCOLS^2)^0.5 + 1
   ENDFN
   ENDFN
  ConvexHull = 1 // Initialize convex hull layer to all ones (will erase areas outside hull)
  //   DistanceFromSrc = IF (StudyArea > 0) THEN CellWidth*DISTANCE(LOCATION(0,0),  LOCATION(NUMROWS-1, NUMCOLS-1)) ELSE 0
  INITIALSTATE = 1
  ENDIS
  ENDIS
  NUMAGENTS = 1 // Only need a single worker
  RETURNTIME = 0
  // Start on the first pivot vertex on convex hull
  EVENTLOCATION
AGENTLOCATION
   REGION WHOLE MAP
   REGION LOCATION(TRLoc)
      DECISION (StudyArea > 0) AND (SrcLayer > 0)
  ENDAL
  ENDEL
  PROBINIT
  PROBINIT
   PROBINIT = 1
   PROBINIT = 1
// Set up first pivot vertex, and first raster boundary location
   StartLocation = Location
  PivotLocation = Location
   distInc = 0
  EdgeRow = NUMROWS-1
   d = 0
   EdgeCol = COL(Location)
   EdgeLocation = LOCATION(EdgeRow, EdgeCol)
   EndingPivotLoc = -1
  ENDPI
  ENDPI
  TRANSITIONS
  TRANSITIONS
  // Continue until we reach the ending pivot location (which is actually second time we hit the second pivot          vertex,
   TRANSITIONS = (d < DistanceFromSrc)
  // since the first pivot vertex gets only partially processed on first pass)
   DistanceFromSrc = d
   TRANSITIONS = (PivotLocation NEQ EndingPivotLoc)
   NearestSrcLoc = StartLocation
ConvexHullPoints = 1
// Walk line from boundary to vertex and erase until a new pivot vertex is hit (then move there)
  oldPivot = PivotLocation
  hitPivot = FALSE
  OVER REGION VECTOR(EdgeLocation, PivotLocation)
    DECISION !hitPivot
  IF (StudyArea > 0) // hit new vertex
        hitPivot = TRUE
        IF (EndingPivotLoc EQ -1) AND (Location NEQ PivotLocation)
          EndingPivotLoc = PivotLocation
        ENDFN
        PivotLocation = Location
    ELSE
        ConvexHull = 0 // erase
    ENDFN
  ENDFN
// Move boundary location clockwise around outside edge of raster
  IF (EdgeRow EQ NUMROWS-1) AND (EdgeCol < NUMCOLS-1)
    EdgeCol = EdgeCol + 1
   ELSE IF (EdgeCol EQ NUMCOLS-1) AND (EdgeRow > 0)
    EdgeRow = EdgeRow - 1
  ELSE IF (EdgeRow EQ 0) AND (EdgeCol > 0)
    EdgeCol = EdgeCol - 1
   ELSE
    EdgeRow = EdgeRow + 1
  ENDFN
  EdgeLocation = LOCATION(EdgeRow, EdgeCol)
  ENDTR
  ENDTR
  POPULATIONTIME = 1
  SPREADTIME = distInc
  // Move to current/new pivot location
  // Spread to the four cardinal neighbours
  MOVELOCATION
  SPREADLOCATION
  REGION LOCATION(PivotLocation)
  REGION CENTRED(1, 1)
  ENDML
      DECISION (StudyArea > 0) AND (SrcLayer <= 0) AND (DistanceFromSrc > (CellWidth *  DISTANCE(StartLocation, Location)))
ENDSL
SPREADPROB
  SPREADPROB = 1
  d = ROUND(CellWidth*DISTANCE(StartLocation, Location))
  distInc = MAX(0,d - SOURCE d)
  ENDSP


==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 16:56, 14 November 2006

Summary

Screenshot

File:DistanceSurface.gif

Download Model

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

Dist2Roads.scn

SELES Scenario
$gisData$ = ..\..\CaseStudy\gisData\cell
StudyArea = $gisData$\StudyArea
SrcLayer = $gisData$\roads
Model Dimensions: StudyArea 
Model.sel
SimPriority Low Priority
SimStart 100000 1

Dist2Streams.scn

SELES Scenario
$gisData$ = ..\..\CaseStudy\gisData\cell
StudyArea = $gisData$\StudyArea
SrcLayer = $gisData$\water
Model Dimensions: StudyArea 
Model.sel
SimPriority Low Priority
SimStart 100000 1

Model.lse

Seles Model
Landscape Events:
  Distance.lse DEBUG
Spatial Constants:
  StudyArea
  SrcLayer
Global Constants:
 CellWidth = CELL WIDTH(StudyArea)
Spatial Variables:
  DistanceFromSrc[CellWidth*(NumRows^2 + NumCols^2)^0.5 + 1] <= 0
  NearestSrcLoc[-1] <= 0

Distance.lse

LSEVENT: DistanceSurface
DEFINITIONS
 LAYER: StudyArea, SrcLayer
 LAYER: DistanceFromSrc, NearestSrcLoc
 GLOBAL CONSTANT: CellWidth
 CLUSTER VARIABLE: StartLocation
 CELL VARIABLE: distInc, d
ENDDEF
INITIALSTATE
  OVER REGION WHOLE MAP
     DECISION (StudyArea > 0)
     DistanceFromSrc = CellWidth*(NUMROWS^2 + NUMCOLS^2)^0.5 + 1
  ENDFN
//   DistanceFromSrc = IF (StudyArea > 0) THEN CellWidth*DISTANCE(LOCATION(0,0),   LOCATION(NUMROWS-1, NUMCOLS-1)) ELSE 0
  INITIALSTATE = 1
ENDIS
RETURNTIME = 0
EVENTLOCATION
  REGION WHOLE MAP
     DECISION (StudyArea > 0) AND (SrcLayer > 0)
ENDEL
PROBINIT
 PROBINIT = 1
 StartLocation = Location
 distInc = 0
 d = 0
ENDPI
TRANSITIONS
 TRANSITIONS = (d < DistanceFromSrc)
 DistanceFromSrc = d
 NearestSrcLoc = StartLocation
ENDTR
SPREADTIME = distInc
// Spread to the four cardinal neighbours
SPREADLOCATION
  REGION CENTRED(1, 1)
     DECISION (StudyArea > 0) AND (SrcLayer <= 0) AND (DistanceFromSrc > (CellWidth *  DISTANCE(StartLocation, Location)))
ENDSL
SPREADPROB
  SPREADPROB = 1
  d = ROUND(CellWidth*DISTANCE(StartLocation, Location))
  distInc = MAX(0,d - SOURCE d)
ENDSP

Suggested Experiments

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