在Netlogo 6.0.4中创建接收器补丁

时间:2018-11-26 19:04:52

标签: netlogo patch

我想在Netlogo中创建两个表示“接收器”和“源”区域的补丁程序(或网格中的区域,不要与常规的Netlogo补丁程序混淆)。 “接收器”修补程序是可以调整大小的滑块,并且应创建一个圆形区域。 “源”补丁是宿补丁之外的区域。下面是我尝试实现此代码的代码,它来自Netlogo 5.3.1中使用的类似模型:

to setup
clear-all

crt sink-patch-radius

;; create the 'sink'
set sk1x random-pxcor
set sk1y random-pycor
while [abs(sk1x - min-pxcor) < (sink-patch-radius - 1)
or abs(max-pxcor - sk1x) < (sink-patch-radius - 1)
or abs(sk1y - min-pycor) < (sink-patch-radius - 1)
or abs(max-pycor - sk1y) < (sink-patch-radius - 1) ]
[ set sk1y random-pycor
set sk1x random-pxcor ]


set sink-patches patches with
[(round(distancexy sk1x sk1y)) < sink-patch-radius ]
ask sink-patches [ set pcolor brown + 2 ]


;; create the 'source'
ask patches [
set source-patches patches with [pcolor != brown + 2]]
ask source-patches [ set pcolor green ]

执行此操作时,设置按钮会卡住。它不会建立模型。奇怪的是,此代码似乎在Netlogo 5.3.1中有效。任何见解都会有所帮助。谢谢!

1 个答案:

答案 0 :(得分:2)

不确定设置按钮为何卡住。但是您的代码有问题。您有ask patches [ set source-patches ...],这将获得所有补丁。那应该很快,但是可以解释您的粘性问题。

此代码的修订版有效

to setup
  clear-all
  let sink-patch-radius 3
  crt sink-patch-radius

  ;; create the 'sink'
  let sk1x random-pxcor
  let sk1y random-pycor
  while [ abs(sk1x - min-pxcor) < (sink-patch-radius - 1)
          or abs(max-pxcor - sk1x) < (sink-patch-radius - 1)
          or abs(sk1y - min-pycor) < (sink-patch-radius - 1)
          or abs(max-pycor - sk1y) < (sink-patch-radius - 1) ]
  [ set sk1y random-pycor
    set sk1x random-pxcor ]
  let sink-patches patches with [(round(distancexy sk1x sk1y)) < sink-patch-radius ]
  ask sink-patches [ set pcolor brown + 2 ]

  ;; create the 'source'
  let source-patches patches with [pcolor != brown + 2]
  ask source-patches [ set pcolor green ]  
end

但是我不确定为什么您要使用while语句而不是简单地确定已关闭的补丁。尝试使用此版本,以使其易于阅读(请注意,由于没有乌龟,因此您需要对其进行更改以将其重新装上)

globals [ sink-patches source-patches]

to setup
  clear-all
  ;; create the 'sink'
  let sink-patch-radius 3
  let sink-centre one-of patches
  set sink-patches [patches in-radius sink-patch-radius] of sink-centre
  ask sink-patches [ set pcolor brown + 2 ]
  ;; create the 'source'
  set source-patches patches with [pcolor != brown + 2]
  ask source-patches [ set pcolor green ]
end