使用BehaviorSpace多次运行模型

时间:2014-10-13 01:45:57

标签: netlogo

从BehaviorSpace,我想通过改变两个变量来运行模型100次,如下所示:

["x-area" 1 ] and ["y-area" [1 1 100]]. 

模型构建如下:

  • 创建风景
  • 附加龟
  • 去模拟

通过使用这两个变量,我希望我的100个模型运行如下:

;;; Model 1 ;;
"x-area" = 1
"y-area" = 1
clear-all
create landscape
add-turtles
go-simulation

;;; Model 2 ;;
"x-area" = 1
"y-area" = 2
add-turtles
go-simulation

;;; Model 3 ;;
"x-area" = 1
"y-area" = 3
add-turtles
go-simulation

 ....

;;; Model 100 ;;
"x-area" = 1
"y-area" = 100
add-turtles
go-simulation

为此,我构建了100个实验并且这种方法有效。有没有更快的方式自动运行100个模型而不进行100次实验?我试着像这样构建1个实验

enter image description here

但是我有这样的错误信息:

预期输入为海龟代理集或补丁代理集或海龟或补丁,但取而代之的是NOBODY。

 org.nlogo.nvm.ArgumentTypeException: OF expected input to be a turtle agentset or patch agentset  or turtle or patch but got NOBODY instead.
 at org.nlogo.prim._asm_proceduremovewithinpolygon_ifelse_86.perform(:4)
 at org.nlogo.nvm.Context.runExclusive(Context.java:119)
 at org.nlogo.nvm.ExclusiveJob.run(ExclusiveJob.java:57)
at org.nlogo.nvm.Context.runExclusiveJob(Context.java:162)
at org.nlogo.prim._asm_procedurestartsimulation_ask_69.perform(:1)
at org.nlogo.nvm.Context.stepConcurrent(Context.java:91)
at org.nlogo.nvm.ConcurrentJob.step(ConcurrentJob.java:82)
at org.nlogo.job.JobThread.org$nlogo$job$JobThread$$runPrimaryJobs(JobThread.scala:143)
at org.nlogo.job.JobThread$$anonfun$run$1.apply$mcV$sp(JobThread.scala:78)
at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
at org.nlogo.job.JobThread$$anonfun$run$1.apply(JobThread.scala:76)
at scala.util.control.Exception$Catch.apply(Exception.scala:88)
at org.nlogo.util.Exceptions$.handling(Exceptions.scala:41)
at org.nlogo.job.JobThread.run(JobThread.scala:75)

问题是我的模型继续运行此错误。所以很难看出问题出在哪里。给出以下消息:

"at org.nlogo.prim._asm_proceduremovewithinpolygon_ifelse_86.perform(:4)" in the error message, 

也许问题出在过程"移动多边形"。

这是我的程序"在多边形内移动"对于给定颜色的多边形:

 if [pcolor] of patch-here = green [

  set list-angles-in-green item 0 table-angles

loop [

  let angle-in-green one-of list-angles-in-green 

  ifelse [pxcor] of (patch-right-and-ahead angle-in-green 1) = max-pxcor or [pycor] of (patch-right-and-ahead angle-in-green 1) = max-pycor [
      print "die"
      die
      stop ]

  [ ifelse (patch-right-and-ahead angle-in-green 1) != nobody and [pcolor] of (patch-right-and-ahead angle-in-green 1) = green [
    print "move"
    move-to patch-right-and-ahead angle-in-green 1

  [ if not any? neighbors with [pcolor = green] [
      print "no neighbors"
      move-to patch-here
      stop ] ] ] ] ]

感谢您的帮助。

2 个答案:

答案 0 :(得分:4)

如果乌龟最终落在世界的边缘,那么patch-right-and-ahead angle-in-green 1可能指向世界之外(取决于angle-in-green是什么),[pxcor] of [pxcor] of (patch-right-and-ahead angle-in-green 1) = max-pxcor会要求nobody的坐标。同一行中pycor可能会发生同样的事情。

问题:乌龟能否在你的模型中到达世界的边缘?在我看来,您显示的代码可能会导致该结果。

如果是这样,那么防止错误的一种方法是替换

[pxcor] of (patch-right-and-ahead angle-in-green 1) = max-pxcor 

xcor = max-pxcor

当乌龟到达最后一列补丁时,这是真的。如果你也希望海龟在接近边缘时死亡,你可以在if-else中使用这两种表达式:

(xcor = max-pxcor) or ([pxcor] of (patch-right-and-ahead angle-in-green 1) = max-pxcor)

(为了清楚起见,我添加了括号。)

但是,我想知道这是否会起到同样的作用:

xcor = max-pxcor or xcor = max-pxcor - 1

如果这些方法中的任何一种适合您的应用程序,那么您显然可以对y坐标执行相同的操作。

答案 1 :(得分:3)

您的实验设置对我来说是正确的,除了您应该删除TRUE的“停止条件”,因为如果停止条件始终为真,您的运行将永远不会运行go命令。

您收到的错误来自您未向我们展示的代码,因此我无法帮助您。您需要向我们展示发生错误的代码。

此外,在发生错误时,x-areay-area的值是多少?如果将x-areay-area设置为BehaviorSpace之外的相同值,是否会发生同样的错误?如果是这样,那么错误与BehaviorSpace没有任何关系。

最后,关于术语的说明:此处只有一个模型,而不是100个,此处只有一个实验,而不是100个。您尝试在模型上运行一个实验,该实验包含100个模型运行。使用标准术语将帮助您清楚地传达您的问题。