从RNetLogo加载具有扩展名的Netlogo模型 [英] Loading a Netlogo model with extension from RNetLogo

查看:293
本文介绍了从RNetLogo加载具有扩展名的Netlogo模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用RNetLogo在无头模式下加载Netlogo模型.模型使用rnd扩展名,该扩展名由extensions [rnd]添加到模型中.如果尝试使用NLLoad(model.path)加载模型,则会出现此错误:

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

很遗憾,我在NLLoad的文档中找不到任何内容.

我尝试将工作目录设置为Netlogo目录:setwd("/Applications/Netlogo 6.0.1").这会将错误更改为

[1] "Java-Object{There was a problem while reading extension rnd at position 79 in }"
Fehler in NLLoadModel(model.path) : 

rnd扩展名是安全且可靠的,位于extensions文件夹中:/Applications/Netlogo 6.0.1/extensions/rnd.jar.

解决方案

回复您的评论-太糟糕了,但是值得一试.也许这种方法仅适用于从命令行无头运行.我也只是暗示您好像在Mac上-我正在运行Windows,所以我的解决方案很可能对您不起作用.您是否阅读了 RNetlogo文档中的"MAC用户注意事项" a>?

无论如何,我在Windows上有一个简单的版本,因此我想向您展示我的设置,看看是否有帮助.这是带有我的模型的文件夹,以及包含netlogo-6.0.1.jarapp文件夹和包含所有扩展名及其文件夹的完整文件夹(从app文件夹中完整复制):

test_rnd.nlogo如下:

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

然后,在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

因此,在此示例中,至少在Windows中,仅将extensions文件夹,app文件夹和模型文件本身都放在同一位置似乎有效.抱歉,我不知道Mac的修复程序,希望其他人有合适的解决方案.

I am trying to load a Netlogo model in headless mode with RNetLogo. The model uses the rnd extension which is added to the model by extensions [rnd]. If I try to load the model with NLLoad(model.path) I get this error:

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

Unfortunately, I cannot find anything in the documentation of NLLoad.

I tried setting the the working directory to the Netlogo directory: setwd("/Applications/Netlogo 6.0.1"). This changes the error to

[1] "Java-Object{There was a problem while reading extension rnd at position 79 in }"
Fehler in NLLoadModel(model.path) : 

The rnd extension is safe and sound in the extensions folder: /Applications/Netlogo 6.0.1/extensions/rnd.jar.

解决方案

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.

这篇关于从RNetLogo加载具有扩展名的Netlogo模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆