divide NetLogo world into several random parts

狂风中的少年 提交于 2020-04-17 03:24:28

问题


I am trying to create a number of groups of agents on the NetLogo world. I hope each of the groups is located at a specific area without overlap. As I can think of, the easies way to achieve this might be dividing the world into several parts first. Each part consists of a number of patches (say 100 + random 10, which I can set) and is colored with a unique color. Then ask the newly created turtles to move to patches with different colors. Could anybody tell me how to achieve this or give any suggestion, please? Thanks in advance.


回答1:


One strategy is to grow different regions. For example:

to grow-regions [ num-regions ]
  let region-num 0
  ask n-of num-regions patches [
    set pcolor item region-num base-colors
    set region-num region-num + 1
  ]
  while [ any? patches with [ pcolor = black ] ] [
    ask patches with [ pcolor != black ] [
      ask neighbors with [ pcolor = black ] [ set pcolor [ pcolor ] of myself ]
    ]
  ]
end

Note that this can draw at most 14 different regions (since that's the number of base colors).

This results in regions like so:

Regions

Edit: Misread your comment. Obviously, this doesn't let you control the size of the regions, but the average size will be count patches / num-regions.



来源:https://stackoverflow.com/questions/23698008/divide-netlogo-world-into-several-random-parts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!