Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Netlogo Api控制器-获取表视图_Java_Api_Spring Boot_Controller_Netlogo - Fatal编程技术网

Java Netlogo Api控制器-获取表视图

Java Netlogo Api控制器-获取表视图,java,api,spring-boot,controller,netlogo,Java,Api,Spring Boot,Controller,Netlogo,我正在使用带有spring boot的Netlogo Api控制器 这是我的代码(我从中获得) 我在控制台中得到了这个结果: 但我想获取表视图并保存到数据库。我可以使用哪个命令来获取表视图 表视图: 有什么帮助吗?如果您能解释一下为什么要用这种方式生成数据,我或其他人可能会给出更好的建议 没有单个NetLogo命令或NetLogo API方法来生成该表,您必须使用BehaviorSpace来获取它。以下是一些选项,按最简单到最难的大致顺序列出 选项1 如果可能,我建议从命令行运行Behavi

我正在使用带有spring boot的Netlogo Api控制器 这是我的代码(我从中获得)

我在控制台中得到了这个结果:

但我想获取表视图并保存到数据库。我可以使用哪个命令来获取表视图

表视图:


有什么帮助吗?

如果您能解释一下为什么要用这种方式生成数据,我或其他人可能会给出更好的建议

没有单个NetLogo命令或NetLogo API方法来生成该表,您必须使用BehaviorSpace来获取它。以下是一些选项,按最简单到最难的大致顺序列出

选项1

如果可能,我建议从命令行运行BehaviorSpace实验来生成表。这将使您获得与所需的完全相同的输出。您可以在中找到有关如何执行此操作的信息。如果需要,您可以在Java程序中从命令行运行NetLogo headless,只需查找有关从Java调用外部程序的资源,可以使用
ProcessBuilder

如果您是从Java内部运行的,以便以程序内部无法实现的方式设置和更改BehaviorSpace实验的参数,则可以使用Java生成实验XML文件,并通过命令行传递给NetLogo。看

选项2

您可以在模型中使用CSV扩展重新创建表的内容,并添加一些其他命令来生成数据。这不会创建完全相同的表,但会以计算机和人类可读的格式输出数据

在纯NetLogo代码中,您可能需要以下内容。请注意,在Java代码中运行
setup
go
之前,可以通过运行其他实验前命令来控制更多行为(如文件名或所需变量)。您还可以使用控制API从Java运行特定于CSV的文件代码,并保持模型不变,但您需要编写自己的NetLogo代码版本的
CSV:to row
原语

globals [
  ;; your model globals here

  output-variables
]

to setup
  clear-all

  ;;; your model setup code here

  file-open "my-output.csv"
  ; the given variables should be valid reporters for the NetLogo model
  set output-variables [ "ticks" "current-price" "number-of-residences" "count-years-simulated" "solar-PV-cost" "%-lows" "k" ]
  file-print csv:to-row output-variables

  reset-ticks
end

to go
  ;;; the rest of your model code here

  file-print csv:to-row map [ v -> runresult v ] output-variables
  file-flush
  tick
end
选项3

如果确实需要精确地复制BehaviorSpace表导出,可以尝试直接从Java运行BehaviorSpace实验。该表是生成的,但正如您所看到的,它与
LabProtocol
类绑定在一起,这意味着您必须通过BehaviorSpace来设置和运行模型,而不是像在示例代码中那样一步一步地使用工作区


一个很好的例子可能是,它从预期的命令行参数中提取一些实验设置,然后将它们与
lab.run()
方法一起使用,以运行BehaviorSpace实验并生成输出。这是Scala代码,而不是Java,但希望它不太难翻译。类似地,您必须设置一个
org.nlogo.nvm.LabInterface.Settings
实例,并将其传递到
HeadlessWorkspace.newLab.run()
以使事情顺利进行。

您显示的“表视图”是运行行为空间实验的结果。除非您试图做一些不寻常的事情,否则这不是您将使用控制API生成的东西:直接使用BehaviorSpace即可。如果你想做一些不寻常的事情,也许有必要解释一下你的问题,这样我们才能更好地帮助你…@NicolasPayette是的,我必须直接使用BehaviorSpace。有帮助的链接吗?我想在web应用程序上获得结果。谢谢
globals [
  ;; your model globals here

  output-variables
]

to setup
  clear-all

  ;;; your model setup code here

  file-open "my-output.csv"
  ; the given variables should be valid reporters for the NetLogo model
  set output-variables [ "ticks" "current-price" "number-of-residences" "count-years-simulated" "solar-PV-cost" "%-lows" "k" ]
  file-print csv:to-row output-variables

  reset-ticks
end

to go
  ;;; the rest of your model code here

  file-print csv:to-row map [ v -> runresult v ] output-variables
  file-flush
  tick
end