How to limit the number of links an agent can make in a model?

你。 提交于 2019-12-08 07:06:20

问题


I'm setting up a model with a number of agents who are connected via links as follows:

ask turtles [create-links-with turtles in-radius vision with [self != myself]]

But I want to be able to limit the number of connections that an individual agent can make. I've tried a few things but to no avail.

Hope you can help.


回答1:


You can get a randomly selected subset of turtles to link to using the n-of primitive like this:

ask turtles [create-links-with n-of 3 turtles in-radius vision with [self != myself]]

However, you will need to do something a bit trickier if you want a firm upper limit because this doesn't stop other turtles from creating links to the same turtle(s). If you want a fixed number of links (5 in example below), you can do this:

  ask turtles
  [ let new-links 5 - count my-links
    let candidates other turtles with [ count my-links < 5 ]
    create-links-with n-of min (list new-links count candidates) candidates
    [ ... ]
  ]

If you simply want an upper limit, you could ask any turtles with my-links > limit to randomly select the appropriate number of links to delete. So, after creating links, something like this (not tested):

ask turtles with [count my-links > LIMIT]
[ if count my-links > LIMIT [ask n-of (count my-links - LIMIT) my-links [die]] ]    


来源:https://stackoverflow.com/questions/31007765/how-to-limit-the-number-of-links-an-agent-can-make-in-a-model

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