Netlogo,将“链接至"更改为“链接至" [英] Netlogo, changing link-with to link-to

查看:223
本文介绍了Netlogo,将“链接至"更改为“链接至"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的海龟创建一个影响力网络.每只乌龟都有一个AD变量,其随机设置在0到1之间.每只乌龟都会创建5个无向链接.现在,如果他们的AD偏低(低于0.3),那么他们应该在网络中寻找AD偏高的人(高于0.7)并创建与该人的链接(成为关注者).

I am trying to create a network of influence for my turtles on my setup. Each turtle has an AD variable randomly set between 0 and 1.Each of them will create 5 undirected links. Now if they have AD low (below 0.3), they should look for someone with high AD in their network (above 0.7) and create a link to that person (to become a follower).

我尝试使用此代码不起作用,因为某些网络不会有AD> 0.7的任何人,因此在尝试终止链接时会得到运行时.有人知道绕过它的方法吗? (特别是如果我们可以避免两步过程,并且在满足条件时直接创建指向的链接).

I have tried with this code which doesn't work because some networks will not have anyone with AD > 0.7 and so when trying to kill the link I get runtime. Would anyone know a way around it? (Specially if we can avoid the two-step process and directly create links-to when the condition is met).

to setup
  ask turtles [
    create-links-with n-of 5 other turtles 
    if (AD < 0.3) [
      let target one-of (other turtles with [link-neighbor? myself and (AD > 0.7)])
    ask link-with target [die]
      create-link-to target
    ]
    ]

谢谢!

推荐答案

从您的代码中,我认为您希望(1)每个代理都与5个其他代理建立链接(因此平均而言,它们将全部具有10个,因为它们还将获得来自他人的链接). (2)如果自己的AD较低,则至少其中一条链路具有较高的AD节点.下面的代码创建一个链接(如果需要,与AD链接),然后创建另一个4.

From your code I think you want (1) every agent to make links with 5 others (so on average they will all have 10, since they will also get links from others). (2) if own AD is low, then at least one of the links is with a high value AD node. The following code creates one link (with the AD if needed) and then another 4.

to setup
  ask turtles
  [ ifelse AD < 0.3
    [ create-links with one-of other turtles with [AD > 0.7] ]
    [ create-links-with one-of 5 other turtles ]
    create-links with n-of 4 other turtles
  ]
end

由于更具体的问题而更新.避免错误的通常方法是创建一个可能的代理集,然后测试是否有成员.看起来像这样:

UPDATE due to more specific question. The normal way to avoid errors is to create an agentset of possibles and then test if there's any members. Looks a bit like this:

...
let candidates turtles with [AD > 0.7]
if any? candidates
[ create-links-with one-of candidates
]
...

这篇关于Netlogo,将“链接至"更改为“链接至"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆