在netlogo中使用“检查点”

时间:2018-03-08 09:57:41

标签: netlogo

我正在设计一个程序,飞机将在我的“空域”两点之间旅行。然而,在这两点之间,我有5个“检查站”,飞机每次通过每个检查站时都会做出决定。我为检查点编写的代码如下:

to setup-areas
  ask patches [
    ifelse pxcor >= 14 
    [  set nonedist? true ]
    [  set nonedist? false  ]
    ifelse pxcor > 10.8 and pxcor < 14 and pycor <= -2.5 and pycor > -4.5
    [  set twelvedist? true  ]
    [  set twelvedist? false  ]
    ifelse pxcor > 7.6 and pxcor <= 10.8 and pycor <= -4.5 and pycor >= -7.5
    [  set ninedist? true  ]
    [  set ninedist? false  ]
    ifelse pxcor > 4.4 and pxcor <= 7.6 and pycor < -7.5 and pycor >= -8.5
    [  set sixdist? true  ]
    [  set sixdist? false  ]
    ifelse pxcor > 1.2 and pxcor <= 4.4 and pycor < -10.5 and pycor >= -11.5
    [  set threedist? true  ]
    [  set threedist? false  ]
    ifelse pxcor >= -2 and pxcor <= 1.2 and pycor < -12.5 and pycor >= -13
    [  set onedist? true  ]
    [  set onedist? false  ]
    ifelse pxcor < -2 and pycor < -13.5
    [  set zerodist? true  ]
    [  set zerodist? false  ]
  ]
end

飞机似乎正在追踪它所在的区域。非常感谢任何帮助!

让飞机在进入特定区域时执行某些操作的代码如下:

to go
  ask aircrafts
  [
    while [nonedist? = true]   [ pre-twelve ]
    while [twelvedist? = true] [ twelve-to-nine ]
  ]
  tick
end

1 个答案:

答案 0 :(得分:1)

我没有答案,但我确实有诊断建议。

首先,更改您的设置区域过程以使事情更加明显。以下将标记飞机应该做什么的补丁。

to setup-areas
  ask patches [
    ifelse pxcor >= 14 
    [  set nonedist? true set pcolor red]
    [  set nonedist? false  ]
    ifelse pxcor > 10.8 and pxcor < 14 and pycor <= -2.5 and pycor > -4.5
    [  set twelvedist? true  set pcolor red]
    [  set twelvedist? false  ]
    ifelse pxcor > 7.6 and pxcor <= 10.8 and pycor <= -4.5 and pycor >= -7.5
    [  set ninedist? true  set pcolor red]
    [  set ninedist? false  ]
    ifelse pxcor > 4.4 and pxcor <= 7.6 and pycor < -7.5 and pycor >= -8.5
    [  set sixdist? true  set pcolor red]
    [  set sixdist? false  ]
    ifelse pxcor > 1.2 and pxcor <= 4.4 and pycor < -10.5 and pycor >= -11.5
    [  set threedist? true  set pcolor red]
    [  set threedist? false  ]
    ifelse pxcor >= -2 and pxcor <= 1.2 and pycor < -12.5 and pycor >= -13
    [  set onedist? true  set pcolor red]
    [  set onedist? false  ]
    ifelse pxcor < -2 and pycor < -13.5
    [  set zerodist? true  set pcolor red]
    [  set zerodist? false  ]
  ]
end

然后改变他们到达检查站时应该做的事情。

to go
  ask aircrafts
  [
    if [nonedist? = true] [ set color blue ]
    if [twelvedist? = true] [ set color blue ]
  ]
  tick
end

这将让您查看是否按预期进行了交互。然后更改您的go代码并修改您的操作代码,例如:

to pre-twelve
  set color blue
  type "My height is " print varname   ; where varname is whatever is being changed
  < then all the code you already have in the pre-twelve procedure>
end

关键是要弄清楚哪个程序没有发生,并从那里,找出它为什么没有发生。在您的问题中,根本没有足够的信息来解决问题。