Social networking v2

寵の児 提交于 2019-12-12 05:30:52

问题


I'm trying to make a network of friends like in this example previous to the final correction of JenB in here, since it is more comprehensible for me and Bryan Head said it would be the way he would do it with fewer agents. I'm planning to use around 200, maybe 300 agents.

My question is... how could I do it without forming pairs? I want the agents to make friends with every agent in radius x during y ticks and with the same color (I'm still working on the tick condition). I tried with if and some conditions before finding the JenB example but it was way too heavy.

I think it isn't necessary to rework the full code. But I'll write it down for you to see my version.

to make-friends
ask agentes [
let new-friendships friends - count my-friendships
if (new-friendships > 0) [
  set possible-friends other agentes in-radius sight-radius with [
    (count my-friendships < friends) and (color = [color] of myself) ]
  create-friendships-with n-of min (list new-friendships count possible-friends) possible-friends]
end

V2 CODE

I started to work in another piece of code since I don't fully know how to do it better. This is the last version. The random-in-range 0 12 condition is in the setup.

to make-friends
  ask agentes [
    let new-friends max-friends - count my-friendships
    let possible-friends other agentes with [color = [color] of myself] in-radius sight-radius
    if new-friends > 0 [
      let chosen n-of min (list new-friends count other possible-friends) other possible-friends
      create-friendships-with chosen ;in-radius sight-radius [ hide-link ]
      set possible-friends other possible-friends
      set friends friendship-neighbors
      ask chosen [
        if my-friendships = friends [ set possible-friends other possible-friends ] ]
    ]
  ]
end

来源:https://stackoverflow.com/questions/45148936/social-networking-v2

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