Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
NetLogo可高效创建任意度分布的网络_Netlogo - Fatal编程技术网

NetLogo可高效创建任意度分布的网络

NetLogo可高效创建任意度分布的网络,netlogo,Netlogo,这是我们的后续问题。在集中精力避免嵌套的'ask'之后,我现在有了这个代码。它的效率要高得多,但创建的链接太多了。显然是逻辑错误,但我看不出来 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 ne

这是我们的后续问题。在集中精力避免嵌套的'ask'之后,我现在有了这个代码。它的效率要高得多,但创建的链接太多了。显然是逻辑错误,但我看不出来

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

很好的解决方案!请注意,
其他候选者实际上
,因此使用大量代理时速度仍然会变慢,但由于没有这些代理运行代码,因此速度会比中慢。它跑得多快给我留下了深刻的印象

在虫子上。在本部分:

如果我的links=friends[设置候选人其他候选人]

我想你在我的链接前面忘了一个
count

代码最终可能会导致一些代理的好友数少于
,因为在找到他们的时候,世界上可能已经没有候选人了。不知道你有多在乎这个。您可以清除链接,然后重试,直到找到正确的号码。只要
朋友
相当小,这应该没问题

请注意,通过将
设置候选项和其他候选项
放在开头,可以稍微加快代码速度,如下所示:

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 ] ]
]

这样,您就不必多次计算
其他候选对象。

奇怪的是,我发现您的新算法(使用
计数
修复和移动
设置候选对象其他候选对象
更快)~新的为6.5秒,旧的为30秒。我没有包括一些节点的修复,这些节点没有足够的朋友。不过,这两种算法都需要它。你是对的。我不知道我第一次做了什么(可能是引入了一个新的bug),但我的原始方法得了31分,新方法得了9分,有10000只海龟和2个朋友。我已经为原来的问题添加了答案,并将尝试删除该问题,因为提出的问题只是一个bug,对其他人没有用处。这些也是我看到的时间。我建议保留这个问题。关于bug之外的其他讨论可能对人们有用。