nlrx
nlrx copied to clipboard
Issue with running Segregation.nl using nlrx
Hello,
I'm very new to the nlrx package. I have made the provided examples of working on the Wolf Sheep Predation model found at https://cran.r-project.org/web/packages/nlrx/vignettes/simdesign-examples.html . However, I'm now trying to use nlrx on a modified version of Schelling's segregation model, and I'm not getting it to work. I've thus instead tried with the unmodified version of the Segregation model found at http://www.netlogoweb.org/launch#http://ccl.northwestern.edu/netlogo/models/models/Sample%20Models/Social%20Science/Segregation.nlogo . That also failed to work. I provide the code I used below.
Perhaps this is a very basic issue. Please could anyone advise on this?
Thanks. Raff
THIS DIDN'T WORK:
library(nlrx) library(here)
https://cran.r-project.org/web/packages/nlrx/vignettes/simdesign-examples.html
#setwd("/Users/rvardava/Downloads/") setwd("D:/USERS/rvardava/Documents/Projects/ComplexityPolicyCourse-RNetlogo") #netlogopath <- file.path("/Applications/NetLogo 6.1.1/") netlogopath <- file.path("C:/Program Files/NetLogo 6.0.2") #C:\Program Files\NetLogo 6.0.2\app\models\Sample Models\System Dynamics modelpath <- paste0(getwd(),"/NL-Models/Segregation.nlogo") outpath <- paste0(getwd(),"/output/")
nl <- nl(nlversion = "6.0.2", nlpath = netlogopath, modelpath = modelpath, jvmmem = 1024)
nl@experiment <- experiment(expname="Segregation", outpath=outpath, repetition=1, tickmetrics="true", idsetup="setup", idgo="go", idfinal=NA_character_, idrunnum=NA_character_, runtime=20, #stopcond= "all? turtles [ happy? ]", evalticks=seq(5,10), metrics=c("percent-similar", "percent-unhappy"), variables = list(), constants = list("density" = 95, "similar-wanted" = 45, # "district-size" = 16, "visualization" = "square-x"))
nl@simdesign <- simdesign_simple(nl=nl, nseeds=1)
results <- run_nl_all(nl)
JAVA_HOME not defined, using java on PATH.
If you encounter errors, set JAVA_HOME or update your PATH to include java.exe.
Exception in thread "main" Expected a literal value. at position 0 in
at org.nlogo.core.Fail$.exception(Fail.scala:27)
at org.nlogo.core.Fail$.exception(Fail.scala:25)
at org.nlogo.core.Fail$.exception(Fail.scala:23)
at org.nlogo.parse.LiteralParser.readLiteralPrefix(LiteralParser.scala:83)
at org.nlogo.parse.LiteralParser.getLiteralValue(LiteralParser.scala:33)
at org.nlogo.parse.CompilerUtilities$.$anonfun$readFromString$3(CompilerUtilities.scala:22)
at org.nlogo.parse.CompilerUtilities$.$anonfun$numberOrElse$1(CompilerUtilities.scala:37)
at scala.util.Either$RightProjection.getOrElse(Either.scala:636)
at org.nlogo.parse.CompilerUtilities$.numberOrElse(CompilerUtilities.scala:36)
at org.nlogo.parse.CompilerUtilities$.readFromString(CompilerUtilities.scala:22)
at org.nlogo.fileformat.LabLoader.$anonfun$readProtocolElement$4(LabLoader.scala:70)
at scala.collection.TraversableLike$WithFilter.$anonfun$map$2(TraversableLike.scala:739)
at scala.collection.Iterator.foreach(Iterator.scala:929)
at scala.collection.Iterator.foreach$(Iterator.scala:929)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1417)
at scala.collection.IterableLike.foreach(IterableLike.scala:71)
at scala.collection.IterableLike.foreach$(IterableLike.scala:70)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.collection.TraversableLike$WithFilter.map(TraversableLike.scala:738)
at org.nlogo.fileformat.LabLoader.readEnumeratedValueSetElement$1(LabLoader.scala:66)
at org.nlogo.fileformat.LabLoader.$anonfun$readProtocolElement$5(LabLoader.scala:77)
at scala.collection.immutable.List.flatMap(List.scala:335)
at org.nlogo.fileformat.LabLoader.valueSets$1(LabLoader.scala:74)
at org.nlogo.fileformat.LabLoader.readProtocolElement(LabLoader.scala:94)
at org.nlogo.fileformat.LabLoader.$anonfun$apply$1(LabLoader.scala:45)
at scala.collection.immutable.List.map(List.scala:283)
at org.nlogo.fileformat.LabLoader.apply(LabLoader.scala:45)
at org.nlogo.fileformat.LabLoader.apply(LabLoader.scala:30)
at org.nlogo.fileformat.LabFormat.load(NLogoLabFormat.scala:37)
at org.nlogo.fileformat.LabFormat.load$(NLogoLabFormat.scala:35)
at org.nlogo.fileformat.NLogoLabFormat.load(NLogoLabFormat.scala:40)
at org.nlogo.headless.BehaviorSpaceCoordinator$.$anonfun$selectProtocol$1(BehaviorSpaceCoordinator.scala:34)
at scala.Option.map(Option.scala:146)
at org.nlogo.headless.BehaviorSpaceCoordinator$.selectProtocol(BehaviorSpaceCoordinator.scala:32)
at org.nlogo.headless.Main$.runExperiment(Main.scala:23)
at org.nlogo.headless.Main$.$anonfun$main$1(Main.scala:12)
at org.nlogo.headless.Main$.$anonfun$main$1$adapted(Main.scala:12)
at scala.Option.foreach(Option.scala:257)
at org.nlogo.headless.Main$.main(Main.scala:12)
at org.nlogo.headless.Main.main(Main.scala)
Error in util_gather_results(nl, outfile, seed, siminputrow) :
Output file is empty - simulation aborted due to a runtime error!
Make sure that parameter value definitions of the experiment are valid and the model code is running properly!
THE FOLLOWING EXAMPLE WORKED:
library(nlrx) library(here)
https://cran.r-project.org/web/packages/nlrx/vignettes/simdesign-examples.html
#setwd("/Users/rvardava/Downloads/") setwd("D:/USERS/rvardava/Documents/Projects/ComplexityPolicyCourse-RNetlogo") #netlogopath <- file.path("/Applications/NetLogo 6.1.1/") netlogopath <- file.path("C:/Program Files/NetLogo 6.0.2") #C:\Program Files\NetLogo 6.0.2\app\models\Sample Models\System Dynamics modelpath <- file.path(netlogopath, "app/models/Sample Models/Biology/Wolf Sheep Predation.nlogo") outpath <- paste0(getwd(),"/output/")
results<-readRDS(paste0(outpath,"wolf-sheep.rds"))
nl <- nl(nlversion = "6.0.2", nlpath = netlogopath, modelpath = modelpath, jvmmem = 1024)
nl@experiment <- experiment(expname="wolf-sheep", outpath=outpath, repetition=5, tickmetrics="true", idsetup="setup", idgo="go", idfinal=NA_character_, idrunnum=NA_character_, runtime=50, evalticks=seq(40,50), metrics=c("count sheep", "count wolves", "count patches with [pcolor = green]"), variables = list(), constants = list("initial-number-sheep" = 20, "initial-number-wolves" = 20, "model-version" = ""sheep-wolves-grass"", "grass-regrowth-time" = 30, "sheep-gain-from-food" = 4, "wolf-gain-from-food" = 20, "sheep-reproduce" = 4, "wolf-reproduce" = 5, "show-energy?" = "false"))
nl@simdesign <- simdesign_simple(nl=nl, nseeds=1)
results <- run_nl_all(nl)