NetLogo Efficiently create network with arbitrary degree distribution

二次信任 提交于 2019-12-22 09:09:52

问题


This is a follow up question to NetLogo Efficient way to create fixed number of links. Having focussed on avoiding the nested `ask', I now have this code. It is much more efficient, but is creating too many links. Clearly a logic error but I can't see it.

globals
[ candidates
  friends
]

to setup
  clear-all
  set friends 2
  create-turtles 5000
  set candidates turtles
  make-network
end

to make-network
  ask turtles
  [ let new-links friends - count my-links
    if new-links > 0
    [ let chosen n-of min (list new-links count other candidates) other candidates
      create-links-with chosen [ hide-link ]
      set candidates other candidates
      ask chosen [ if my-links = friends [ set candidates other candidates ] ]
    ]
  ]
end

回答1:


Nice solution! Note that other candidates actually iterates through every agent in the agentset, so it will still get slow with lots of agents, but less so than in your other question since it's not having those agents run code. I'm really impressed by how quickly it runs!

Onto the bug. In this part:

if my-links = friends [ set candidates other candidates ]

I think you forgot a count in front of my-links.

The code can still end up with some agents with less than friends, since the world can be out of candidates by the time it gets to them. Not sure how much you care about this. You could just clear the links and retry until you have the right number. That should be okay as long as friends is pretty small.

Note that you can speed the code up a little bit by putting the set candidates other candidates at the beginning like so:

set candidates other candidates
if new-links > 0
[ let chosen n-of min (list new-links count candidates) candidates
  create-links-with chosen [ hide-link ]
  ask chosen [ if my-links = friends [ set candidates other candidates ] ]
]

That way, you avoid having to calculate other candidates several times.



来源:https://stackoverflow.com/questions/33000956/netlogo-efficiently-create-network-with-arbitrary-degree-distribution

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