Loading a Netlogo model with extension from RNetLogo

杀马特。学长 韩版系。学妹 提交于 2019-12-06 10:04:30

Responding to your comment- that's too bad, but it was worth a shot. Maybe that approach only works with running headless from the command line. I also just clued in that it looks like you're on Mac- I'm running Windows so my solutions most likely won't work for you. Did you read the "Note for MAC users" in the RNetlogo documentation?

Anyway, I got a simple version of this working on Windows so I thought I'd show you my setup and see if that helps at all. This is the folder with my model, as well as the app folder containing the netlogo-6.0.1.jar and the extensions folder containing all the extensions and their folders (copied whole from within the app folder):

test_rnd.nlogo is as follows:

extensions [ rnd ]

globals [ pcolor-list ]

to setup
  ca
  reset-ticks
  ask patches [
    set pcolor random 10 + 50
  ]
end

to go
  check
  tick
end


to check
  set pcolor-list []
  repeat 10 [
    ask rnd:weighted-one-of patches [ pcolor ] [
      set pcolor-list lput pcolor pcolor-list
    ]
  ]
end

Then, in R:

library(RNetLogo)

nl.path <- "C:/test_rnetlogo/app"

model.path <- "C:/test_rnetlogo/test_rnd.nlogo"

NLStart(nl.path, gui = FALSE, nl.jarname = "netlogo-6.0.1.jar")

NLLoadModel(model.path)

NLCommand("setup")
NLCommand("Go")
test <- NLReport("pcolor-list")

> print(test)
 [1] 53 53 50 57 50 53 50 58 58 51

So in this example, at least in Windows, just having the extensions folder, the app folder, and the model file itself all in the same location seems to have worked. Sorry I don't know a fix for the Mac, hopefully someone else has a proper solution.

I made this work (using the CSV extension) by copying the contents of the CSV extension folder directly into the app folder.

I'm working under GNU/Linux. This method may work better for OSx users, too. I'm guessing that this isn't working as expected because there is no "installation" of RNetLogo that sets the classpaths for us. We explicitly tell R where to find netlogo-x.x.x.jar, but not any of the extensions.

On Mac, this issue can be fixed as follows:

For each NetLogo extension in use, copy and paste that folder into the directory containing the .nlogo model you are attempting to run.

For example, for the rnd extension, copy the folder /Applications/NetLogo 6.0.4/extensions/nw to the enclosing folder set in model.path. NLLoadModel(model.path) should now execute without this error.

This solution is based on the Extensions Guide of the NetLogo 6.0.4 User Manual (emphasis added):

NetLogo will look for extensions in several places:

  1. In the folder of the current model.
  2. The extensions folder located with the NetLogo installation. For typical NetLogo installations:
    • On Mac OS X: /Applications/NetLogo 6.0.4/extensions
    • On 64-bit Windows with 64-bit NetLogo or 32-bit Windows with 32-bit NetLogo: C:\Program Files\NetLogo 6.0.4\app\extensions
    • On 64-bit Windows with 32-bit NetLogo: C:\Program Files (x86)\NetLogo 6.0.4\app\extensions
    • On Linux: the app/extensions subdirectory of the NetLogo directory extracted from the installation .tgz

It's unclear to me why the check to /Applications/NetLogo 6.0.4/extensions doesn't work, but at least there's a solution!

I encountered the same issue with the nw extension in NetLogo, receiving a nearly identical error:

> NLLoadModel(model.path)
[1] "Java-Object{Can't find extension: nw at position 13 in }"
Error in NLLoadModel(model.path) :

So the issue seems to apply to all extensions.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!