我正在尝试创建一个生成器,该生成器使用(已更正的)Barabasi-Albert 算法来生成 NetLogo 中的优先连接网络。有两个参数:(最终)节点数和每个节点添加的边数。网络扩展有一个版本,但仅限于每个节点添加 1 条边的情况。
简化的完整模型:
extensions [rnd]
to makeNW-BA
clear-all
let new-edges 4
let popn 25
create-turtles new-edges [ setxy random-xcor random-ycor ]
ask turtles [ create-links-with other turtles with [not link-neighbor? myself] ]
repeat popn - count turtles
[ let targets rnd:weighted-n-of new-edges turtles [ count my-links ]
create-turtles 1
[ setxy random-xcor random-ycor
create-links-with targets
]
]
end
行 let targets rnd:weighted-n-of degree turtles [count my-links]
在观察者运行 _asm_proceduremakenwba_setprocedurevariable_11 时创建了一个 java 错误 (ClassCastException)。这是我第一次使用
rnd
扩展,所以我不知道问题是我的编码问题,还是实际上有一个错误导致了 java 错误。
更新
我现在已经为度数设置了一个海龟自己的变量(即计算我的链接数)并尝试做 let targets rnd:weighted-n-of new-edges turtles [ degree ]
。这反而给我带来了一个 NetLogo 错误,观察者无法在不指定哪只海龟的情况下访问海龟变量
。但是,尝试添加 of self
没有帮助。
最佳答案
这会产生所需的网络吗?
let targets rnd:weighted-n-of new-edges turtles [ [count my-links] of ? ]
将 new-eges 设置为 4 时,我很难注意到它。当我将它设置为 1 时,它似乎建立了一个优先附件网络。 看起来(让上帝的声音不同意我)[rnd:weighted-n-of] 被设计为与列表一起工作,并且其中有一个隐藏的 foreach 或 map 导致它在给定代理集时在转换时出错。
关于NetLogo rnd :weighted-n-of by turtle variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34802274/