【问题标题】:Netlogo - Divide world equally between n agentsNetlogo - 在 n 个代理之间平均分配世界
【发布时间】:2018-02-11 15:11:10
【问题描述】:

我正在 Netlogo 中创建一个检查模型,每个检查员负责 n 个补丁。也就是说,我需要将世界划分为每个检查员专属的区域。

我试过了 设置范围(世界宽度 * 世界高度 / 检查员)^ 0.5

但他们的范围比预期的要高,并且允许一名检查员“侵入”其他检查员的区域,这是不可取的。

【问题讨论】:

  • 如何给你的补丁一个my-inspector属性初始化为nobody,然后let _n int (count patches / count inspectors) ask inspectors [ask n-of _n patches with [my-inspector = nobody] [set my-inspector myself]
  • 您还可以查看 NetLogo 模型库中的“多区域示例”。

标签: range netlogo


【解决方案1】:

这种方法可能过于复杂,但可以满足您的需求 - 它将世界分割成甚至是垂直的“领土”带。请注意,只有在世界最小 xcor 为 0 并且世界宽度可以被 inspectors 的数量整除时,它才能正常工作-否则一个检查员的检查区域将与其他检查员不同。例如,使用此设置:

breed [ inspectors inspector ]
inspectors-own [ my-territory ]

to setup
  ca
  resize-world  0 29 0 29
  create-inspectors ninspectors [
    set my-territory nobody
  ]
  split
  reset-ticks
end

制作列表以存储最小和最大 xcor 值,然后使用这些列表划分补丁以将其作为区域分配给不同的检查员。 cmets中的更多解释:

to split 
  ; get a count of the inspectors
  let n count inspectors

  ; get section widths
  let n-xcor ( max-pxcor - min-pxcor ) / n

  ; build lists to define min-maxes of sections
  let n-min ( range min-pxcor max-pxcor n-xcor )
  let n-max lput ( max-pxcor + 1 ) n-min
  set n-max but-first n-max

  ; Foreach of the min-max pairs, set patches within 
  ; the min-max boundary be set to the territory of one
  ; of the inspectors that currently has no territory
  ( foreach n-min n-max [
    [ _min _max ] -> 
    set _min ceiling _min
    set _max ceiling _max
    let cur_inspector one-of inspectors with [ my-territory = nobody ]
    ask patches with [ pxcor >= _min and pxcor < _max ] [
      ask cur_inspector [
        ifelse my-territory = nobody [
          set my-territory myself
        ] [
          set my-territory ( patch-set my-territory myself )
        ]
      ]
      set pcolor ( [color] of cur_inspector ) - 2
    ]
  ]) 

  ; Move inspectors to their territory
  ask inspectors [
    setxy ( mean [pxcor] of my-territory ) ( mean [pycor] of my-territory )
    show my-territory
    pd
  ] 
end

要检查它是否正常工作,您可以让您的检查员四处走动:

to go 
  ask inspectors [
    face one-of neighbors with [ member? self [my-territory] of myself ]
    fd 1
  ]
  tick
end

【讨论】:

    猜你喜欢
    • 2014-07-05
    • 2016-01-05
    • 2016-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-07
    相关资源
    最近更新 更多