我试图创建一个在环境中作为“静态”单元移动的网络,即除了整体的位置和方向之外,模拟中没有任何变化,各个乌龟相对于彼此的位置和方向由它们固定。链接。海龟通过无向链接连接,这些链接被绑定并设置为连接模式“固定”。
问题是在某些情况下链接无法保持固定并且链接长度开始变化。最初我注意到,在平均网络程度相对较低或网络是完整图形的情况下,tie原语起作用。但是,当创建链接以生成适度连接的图形时,海龟之间的链接长度开始变化。在进一步的实验中,我可以创建具有相同数量的链路和海龟但具有不同配置的网络,即网络结构不同,有时保持位置和链路长度,但在其他情况下不能这样做。
无论网络连接如何或网络配置如何,我如何让网络作为一个单元移动?请参阅下面的示例代码,我在末尾添加了代码,您可以在其中运行具有6个海龟和6个链接的网络的多个配置,以便自己查看问题,尝试运行至少半打迭代。谢谢!
这会产生一个作为一个整体移动的网络
to setup
create-turtles 10
ask turtles [fd 2]
ask turtles [create-links-with other turtles [tie] ]
ask links [set tie-mode "fixed"]
reset-ticks
create-turtles 10
ask turtles [fd 2]
ask turtles [create-links-with other turtles [tie] ]
ask links [set tie-mode "fixed"]
reset-ticks
end
to go
ask turtles [lt 1 fd 1]
end
这会产生一个网络,其链接仍然绑定并设置为绑定模式“固定”,但更改其链接长度。要求死的链接越多,链接长度的变化就越大。
to setup
clear-all
create-turtles 10
ask turtles [fd 2]
ask turtles [create-links-with other turtles [tie] ]
ask links [set tie-mode "fixed"]
ask one-of links [die]
reset-ticks
end
to go
ask turtles [lt 1 fd 1]
end
以下是显示链接长度更改的特定实例的其他代码。当按钮“use-seed-from-user”提示时,请输入种子659269695。如果代码很笨,请先道歉,第一次使用随机种子。 “打印长度”按钮用于确认长度发生变化。
;USE seed: 659269695
to use-new-seed
let my-seed new-seed ;; generate a new seed
output-print word "Generated seed: " my-seed ;; print it out
random-seed my-seed ;; use the new seed
reset-ticks
end
;; Use a seed entered by the user
to use-seed-from-user
loop [
let my-seed user-input "Enter a random seed (an integer):"
carefully [ set my-seed read-from-string my-seed ] [ ]
ifelse is-number? my-seed and round my-seed = my-seed [
random-seed my-seed ;; use the new seed
output-print word "User-entered seed: " my-seed ;; print it out
reset-ticks
stop
] [
user-message "Please enter an integer."
]
]
end
to setup
clear-all
create-turtles 6
ask turtles [
fd 5
set shape "circle"
set size 1
set color yellow
if count links < 7 [ask one-of turtles [create-link-with one-of other turtles
[tie]]]]
reset-ticks
end
to go
ask turtles [lt 1 fd 1]
end
to print-lengths
print sort-by < [precision link-length 2] of links
end
我略微修改了你的代码,以便go程序包括断开链接。我也摆脱了tie-mode
的明确设置,因为这是通过设置tie
的链接并添加了tick
所以我可以绘制。所以代码看起来像这样:
to setup
clear-all
create-turtles 10 [fd 2]
ask turtles [create-links-with other turtles [tie] ]
reset-ticks
end
to go
ask one-of links [die]
ask turtles [lt 1 fd 1]
tick
end
据我所知,海龟作为一个整体移动,直到它因链接丢失而碎裂。
我为mean [link-length] of links
添加了一个显示器,这是我认为你要问的,也是一个相同计算的图。是的,平均链接长度确实发生变化,但请记住链接的长度不一样。如果较长的一个死亡,则平均长度将减少,如果较短的一个死亡,则平均值将增加。情节有点徘徊,但在碎片化之前它基本上是平的。