Skip to content

Commit

Permalink
removed SimData class
Browse files Browse the repository at this point in the history
  • Loading branch information
achubaty committed Apr 6, 2014
1 parent 62baf1b commit 41fab21
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 193 deletions.
Empty file modified .Rbuildignore 100644 → 100755
Empty file.
Empty file modified .gitattributes 100644 → 100755
Empty file.
Empty file modified .gitignore 100644 → 100755
Empty file.
63 changes: 0 additions & 63 deletions R/observer.R

This file was deleted.

26 changes: 0 additions & 26 deletions R/simulation-classes.R
Expand Up @@ -49,29 +49,3 @@ setClass("SimList",
slots=list(.loaded="list", modules="list", params="list",
events="data.table", simtime="numeric", debug="logical"
))



#' The \code{SimData} class
#'
#' This class store data used by and generated in a simulation.
#'
#' An object of class SimData contains:
#' agents: custom list of agents used in the simulation;
#' maps: custom list of maps loaded or generated by the simulation;
#' stats: custom list of stats collected during the simulation.
#'
#' @slot agents The list of agents, as an agent class (or subclass).
#'
#' @slot maps The list(s) of maps, as raster class (raster package) or Spatial class (sp package).
#'
#' @slot stats The list(s) of statistics.
#'
#' @note add additional notes here.
#'
#' @name SimData
#' @rdname SimData-class
#' @aliases SimData-class
#' @exportClass SimData
setClass("SimData", slots=list(agents="list", maps="list", stats="list"))
# setClass("SimData", slots=list(agents="AgentsList", maps="MapsList", stats="StatsList"))
70 changes: 0 additions & 70 deletions R/simulation-methods.R
Expand Up @@ -216,74 +216,6 @@ setReplaceMethod("sim.debug",



setGeneric("sim.agents", function(object) {
standardGeneric("sim.agents")
})

setMethod("sim.agents",
signature = "SimData",
definition = function(object) {
return(object@agents)
})

setGeneric("sim.agents<-",
function(object, value) {
standardGeneric("sim.agents<-")
})

setReplaceMethod("sim.agents",
signature="SimData",
function(object, value) {
object@agents <- value
validObject(object)
return(object)
})

setGeneric("sim.maps", function(object) {
standardGeneric("sim.maps")
})

setMethod("sim.maps",
signature = "SimData",
definition = function(object) {
return(object@maps)
})

setGeneric("sim.maps<-",
function(object, value) {
standardGeneric("sim.maps<-")
})

setReplaceMethod("sim.maps",
signature="SimData",
function(object, value) {
object@maps <- value
validObject(object)
return(object)
})

setGeneric("sim.stats", function(object) {
standardGeneric("sim.stats")
})

setMethod("sim.stats",
signature = "SimData",
definition = function(object) {
return(object@stats)
})

setGeneric("sim.stats<-",
function(object, value) {
standardGeneric("sim.stats<-")
})

setReplaceMethod("sim.stats",
signature="SimData",
function(object, value) {
object@stats <- value
validObject(object)
return(object)
})



Expand Down Expand Up @@ -317,7 +249,6 @@ sim.init <- function(params, modules, path) {
path <- check.path(path)

sim <<- new("SimList")
sim.data <<- new("SimData")

# load simulation parameters and modules
sim.params(sim) <<- params
Expand All @@ -328,7 +259,6 @@ sim.init <- function(params, modules, path) {
}
# set up first event(s): all first events should be initialization events e.g. from modules
# schedule.event(EVENT.TIME, "MODULE.NAME", "EVENT.TYPE", list(OPTIONAL.ITEMS))
schedule.event(0.00, "observer", "init") # needs optional flags for plotting, etc.
for (m in modules) {
schedule.event(0.00, m, "init")
}
Expand Down
Empty file modified README.md 100644 → 100755
Empty file.
22 changes: 2 additions & 20 deletions SAMPLE/caribou.R
Expand Up @@ -51,7 +51,6 @@ caribou.init = function() {
pkgs = list("raster") # list required packages here
load.packages(pkgs)

hab = get.habitat.map() # from habitat module
best = max(hab@data@values)
worst = min(hab@data@values)
good = Which(hab>0.8*best)
Expand All @@ -61,24 +60,14 @@ caribou.init = function() {
na = NumAgents(100) # could be specified globally in params

# initialize caribou agents
caribou = new("mobileAgent", agentlocation=al, numagents= na, probinit=pri)
caribou <<- new("mobileAgent", agentlocation=al, numagents= na, probinit=pri)
points(caribou, pch=19, cex=0.1)

### module parameters
# - export module params to global list
sim.agents(sim.data) <<- list(caribou=caribou)

# - export data structure for module stats
# sim.stats(sim.data)[["caribou"]] <<- list()

# last thing to do is add module name to the loaded list
sim.loaded(sim) <<- append(sim.loaded(sim), "caribou")
}

caribou.move = function() {
hab = get.habitat.map() # from habitat module
caribou = get.caribou.population() # see below

ex = hab[position(caribou)] # find out what pixels the individuals are on now
wh = which(!is.na(ex))
if (length(wh)==0) stop(paste("all agents off map at time", sim.time(sim)))
Expand All @@ -88,20 +77,13 @@ caribou.move = function() {
ln = rlnorm(length(ex), sl, 0.02) # log normal step length
dir.sd = 30 # could be specified globally in params

caribou = crw(caribou, step.len=ln , dir.sd=dir.sd)
caribou <<- crw(caribou, step.len=ln , dir.sd=dir.sd)
points(caribou, pch=19, cex = 0.1)

rads = sample(10:30, length(caribou), replace=TRUE)
rings = cir(caribou, radiuses=rads, hab, 1)
points(rings$x, rings$y, col=rings$ids, pch=19, cex=0.1)
dev.flush()

sim.agents(sim.data)["caribou"] <<- caribou
}

### user-defined subroutines

get.caribou.population = function() {
pop = sim.agents(sim.data)$caribou
return(pop)
}
16 changes: 2 additions & 14 deletions SAMPLE/habitat.R
Expand Up @@ -45,26 +45,14 @@ habitat.init = function() {
### initialize habitat
nx = 5e2 # could be specified globally in params
ny = 5e2 # could be specified globally in params
hab <- raster(nrows=ny, ncols=nx, xmn=-nx/2, xmx=nx/2, ymn = -ny/2, ymx = ny/2)
hab <- round(GaussMap(extent(hab), speedup=10), 1)
hab <<- raster(nrows=ny, ncols=nx, xmn=-nx/2, xmx=nx/2, ymn = -ny/2, ymx = ny/2)
hab <<- round(GaussMap(extent(hab), speedup=10), 1)
plot(hab)
dev.flush()

### module parameters
# - export module params to global list
sim.maps(sim.data)[["habitat"]] <<- list(quality=hab)

# - export data structure for module stats
# sim.stats(sim.data)[["habitat"]] <<- list()

# last thing to do is add module name to the loaded list
sim.loaded(sim) <<- append(sim.loaded(sim), "habitat")
}


### user-defined subroutines

get.habitat.map = function() {
map = sim.maps(sim.data)$habitat$quality
return(map)
}
Empty file modified debug.log 100644 → 100755
Empty file.

0 comments on commit 41fab21

Please sign in to comment.