在过去的24小时左右,我一直在努力解决这个问题。我觉得我在这里错过了一些相对简单的事情。
to setup-scale-free-network
clear-all
;; Make a circle of turtles
set num-nodes (num-children + num-adults + num-toddlers)
create-children num-children
create-adults num-adults
create-toddlers num-toddlers
layout-circle turtles (max-pxcor - 8)
ask turtles[
create-links-with turtles with [self > myself and random-float 5 < probability]
]
setup
end
to-report find-partner
report [one-of both-ends] of one-of links
end
以上代码创建了一系列不同品种的海龟,并在这些品种之间创建了许多链接。
to go
reset-ticks
make-link find-partner
tick
end
在满足所需的学位分布水平之前,将调用这两个程序。
我想要做的是使用find-partner程序转向优先附件来执行此操作我需要修改此代码以创建从节点查找伙伴选择的其中三种类型之一的链接在我的网络中繁殖。
to make-node [old-node]
crt 1
[
set color red
if old-node != nobody
[ create-link-with old-node [ set color green ]
;; position the new node near its partner
move-to old-node
fd 8
]
]
end
我自己的尝试导致无所谓诚实。我知道我要求很多帮助但是我的智慧在这里结束了,谢谢你的帮助和耐心。
答案 0 :(得分:2)
我无法完全理解你的问题。我猜您希望创建另一种类型的链接,您可以在已经是网络一部分的海龟之间调用优先附件(绿色)。
在这种情况下,您可能想要的一件事是您不会选择已经在优惠附件网络中的海龟。 [这只是我的假设]
我修改了你的代码(如下所示)以获得所需的网络,其优先附件显示为绿色链接,添加了一个海龟变量already-attached
,用于排除已经优先附加到其他人的海龟
希望这有帮助!
breed [ children child ]
breed [ adults adult ]
breed [ toddlers toddler ]
children-own [ already-attached ]
adults-own [ already-attached ]
toddlers-own [ already-attached ]
to setup-scale-free-network
clear-all
let num-children 5
let num-adults 5
let num-toddlers 5
let probability 1
;; Make a circle of turtles
create-children num-children [ set color orange ]
create-adults num-adults [ set color green ]
create-toddlers num-toddlers [ set color blue ]
layout-circle turtles (max-pxcor - 8)
ask turtles
[
create-links-with turtles with [self > myself and random-float 5 < probability]
]
end
to go
setup-scale-free-network
ask turtles with [already-attached = 0]
[
attach-to-one-of-each-breed self
]
end
to attach-to-one-of-each-breed [ source-node ]
ask source-node
[
if any? other children with [ already-attached = 0 ]
[
ask one-of other children
[
set already-attached 1
create-link-with source-node [ set color green ]
]
]
if any? other adults with [ already-attached = 0 ]
[
ask one-of other adults
[
set already-attached 1
create-link-with source-node [ set color green ]
]
]
if any? other toddlers with [ already-attached = 0 ]
[
ask one-of other toddlers
[
set already-attached 1
create-link-with source-node [ set color green ]
]
]
]
end