【问题标题】:Asking patches with pycor = range to sprout turtles使用 pycor = range 询问补丁以使海龟发芽
【发布时间】:2019-12-16 20:17:07
【问题描述】:

一个。我正在尝试在 netlogo 中建立供应链结构。每层的元素(即 DistributionCenters)具有相同的 xcor,我希望它们在 ycor 上均匀分布(注意 DistrubutionCenters 的数量是可变的,并且使用滑块导入)。我尝试了很多方法并得出了以下想法,但是补丁并没有使海龟发芽


breed [Producers Producer]
breed [DistributionCenters DistributionCenter]

to setup

  clear-all

  set-default-shape DistributionCenters "house ranch"
  let DCR1 (- floor ( n_DistributionCenters / 2 ))
  let DCR2 (  floor ( n_DistributionCenters / 2 ))
  let DistRange (range DCR1 DCR2 1)
  ask patches with [ pxcor = 0 and pycor = DistRange][sprout-DistributionCenters 1]

【问题讨论】:

    标签: netlogo


    【解决方案1】:

    你的问题是你在问一个数字(pycor)是否等于一个列表。这些是不同类型的数据。因此,您的示例等效于这个完整的模型(打印出列表):

    to testme
      clear-all
      let selected (range 0 15 3)
      print selected
      ask patches with [pxcor = 0 and pycor = selected] [set pcolor blue]
    end
    

    一种方法是使用foreachask 分别使用适当的补丁来遍历列表:

    to testme2
      clear-all
      let selected (range 0 15 3)
      print selected
      foreach selected
      [ here -> ask patch 0 here [set pcolor blue]
      ]
    end
    

    另外,我认为这在概念上与您尝试做的类似 - 它使用 member? 来测试列表的成员资格:

    to testme3
      clear-all
      let selected (range 0 15 3)
      print selected
      ask patches with [pxcor = 0 and member? pycor selected] [set pcolor blue]
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多