NetLogo 海龟链在链接时断开
NetLogo chain of turtles breaks up when linking
我正在制作一些细胞链的模型(作为更大的 DNA 串模型的一部分)。它们在屏幕上摆动,当它们摆动太多时,它们接近同一字符串中同一类型的单元格,它们必须用该单元格创建一个 link。
下面的代码。
有点管用....但是在我介绍了上面描述的 linking 行为之后,字符串很快就断成碎片了。我不明白为什么 :-) 有什么想法吗?
谢谢,
帕勒
breed [cells cell]
cells-own [paired?]
globals [chains]
to setup
clear-all
set chains []
addchain
reset-ticks
end
to go
foreach chains [c -> movechain c]
ask cells [if any? other cells-here with [label = [label] of myself and paired? = false] [
let makker one-of other cells-here with [label = [label] of myself and paired? = false]
create-link-with makker [tie]
set color red
set paired? true
ask makker [set color red set paired? true]
print word label " was found!"
]]
tick
end
to addchain
set chains lput makechain chains
end
to movechain [mylist]
let antalfollowers length mylist - 1
let i antalfollowers
repeat antalfollowers [
ask item i mylist [
move-to (item (i - 1) mylist)
]
set i i - 1
]
ask first mylist [
right random-float wigglefactor
left random-float wigglefactor
fd 1
]
end
to-report makechain
let mylist []
let text "MGIVEQCCTSICSRYQ"
let startx random-xcor / -3
let starty random-ycor / -3
let i 0
repeat length text [
create-cells 1 [
set color green
set shape "circle"
set label item i text
set paired? false
set mylist lput self mylist
setxy startx + i * .75 starty + i * .75
]
set i i + 1
]
report mylist
end
我正在处理您的问题并取得了一些进展 -- 至少我对您的代码进行了修订,增加了一些故障排除,并对界面进行了修订。我不知道如何在此处附加模型,或者当您 运行 时您将看到的视图图像,所以我在 netlogo-users Google Group 中发布了完整的模型和一个 PNG 文件。
这些修订没有完全回答你关于如何解决链断裂的问题,但它们提供了一个可重现的模型版本,你可以肯定它会在第 746 步断裂并且你可以打开密集打印和慢动作,然后观察之后尝试的动作发生了什么。
也许如果我们都看一下它为什么会崩溃。
我认为可能发生的一件事是,一旦两个单元格 link 并打成平手,您的移动算法就不再是打结链应该如何移动的正确逻辑。
这是我所做的更改:
我在设置中添加了一个随机种子命令,这样模型就可以重复运行随机变量的选择完全相同,所以我们都可以看看结果。
我在界面上添加了一个 "verbose?" 开关来打开或关闭正在发生的事情的详细打印。
我添加了一个 "clear-stop" 按钮,允许我放入模型中的 "stop" 命令使用停止请求停止 运行ning?标志,代码设置,此按钮重置,以便 "go" 和 "one step" 在停止后再次工作,滴答计数器继续递增。
我添加了一个 msec-per-tick 滑块以在 go 步骤结束时放置固定的毫秒数,因此模型将 运行 以可用于调试的速度.我不知道其他人是怎么做到的——当我尝试使用界面顶部的内置滑块来控制速度时,要么太慢,要么太快,我做不到似乎能够将其调整到恰到好处。所以我添加了这个kludge。
我猜到您对界面上的 wigglefactor 滑块有什么限制,并制作了一个从 0 到 90(度)的滑块。它工作正常并重现了你的错误。
我添加了一些额外的测试,以防止在您选择的单元格中相邻的两个 C 单元格在发现时相互 linking,因为他们有时会这样做,他们在同一个补丁上。 使用随机种子 23456,例如,您的原始代码在 tick 2 中将其自己的 CC 相邻对连接在一起。
(
这是修改后的代码,关于如何使用它的注释在发布的模型(在 netlogo-users 中)和代码后面。
breed [cells cell]
cells-own [paired?]
globals [
chains
stop-requested? ;;//////////////////////////////////////////////////
]
to setup
clear-all
;; random-seed 12345 ;; /////////////// breaks at either step 35 or 45 ////
;; random-seed 23456 ;; ////////////////// ties its own CC in tick 2 ///
random-seed 34567 ;; /////////////////// ties own cc in tick 84 , ties C at 746 and breaks in 6 steps
;;// wow -- it SNIPS TSIC out of the middle of the chain!! snips out CTIS, turtles 7 8 9 and 10
;; cell 6 C is directly followed by cell 11 -- also C
set chains []
addchain
set stop-requested? FALSE ;; ////////////////////////////////////////
reset-ticks
end
to go
if stop-requested? [ stop ] ;;////////////////////////////////////////////
foreach chains [c -> movechain c]
ask cells [if any? other cells-here with [label = [label] of myself and paired? = false
and who != [who] of myself + 1
and who != [who] of myself - 1
] [
let makker one-of other cells-here with [label = [label] of myself and paired? = false]
create-link-with makker [tie]
set color red
set paired? true
ask makker [set color red set paired? true]
print ( word label " was found at tick " ticks)
set stop-requested? TRUE ;;/////////////////////////////////////////////
]]
wait ( msec-per-tick / 1000 ) ;;////////////////////////////////////////
tick
end
to addchain
set chains lput makechain chains
end
to movechain [mylist]
if verbose? [print ( word "\n\nin code at tick " ticks " starting movechain") ];;//////////////
;;if verbose? [ show mylist ]
let antalfollowers length mylist - 1
let i antalfollowers
repeat antalfollowers [
ask item i mylist [
if verbose? [
;;print (word " asking item " i " on mylist to move to item " (i - 1) )
let mover [label] of item i mylist
let moveto [label] of item (i - 1) mylist
let mover-color [color] of item i mylist
let moveto-color [color] of item (i - 1) mylist
;; BLUE one moves TO the YELLOW ONE at the end of this second
print (word " move " mover " to " moveto )
ask item i mylist [set color blue set shape "square" set size 2]
ask item (i - 1) mylist [set color yellow set shape "square" set size 2]
display
wait 4
ask item i mylist [set color mover-color set shape "circle" set size 1]
ask item (i - 1) mylist [set color moveto-color set shape "circle" set size 1]
display
]
move-to (item (i - 1) mylist)
;;print word "just moved follower " i ;;//////////////////////////
;; wait 0.1 ;;////////////////////////////////////////////////////
]
set i i - 1
]
ask first mylist [
right random-float wigglefactor
left random-float wigglefactor
fd 1
]
end
to-report makechain
let mylist []
let text "MGIVEQCCTSICSRYQ" ;; NOTE - this has a repeat of CC in it which SOMETIMES gets tied (23456 tick 2)
let startx random-xcor / -3
let starty random-ycor / -3
let i 0
repeat length text [
create-cells 1 [
set color green
set shape "circle"
set label item i text
set paired? false
set mylist lput self mylist
setxy startx + i * .75 starty + i * .75
]
set i i + 1
]
report mylist
end
to clear-stop ;;////////////////////////////////
set stop-requested? FALSE ;;////////////////////////////////
end ;;////////////////////////////////
Anyway, here's how to run it to reproduce the problem and examine it
in fine detail very closely.
WHAT IS IT?
model of DNA in motion modified for troubleshooting. When a "C" cell
touches another "C" cell in step 746, and sets a link between the two
C cells and ties them to move as one, the algorithm for motion
breaks somehow. This may help figure out why,
HOW IT WORKS
This has added to it a msec-per-tick slider, default 50, to set the
display speed about right if you leave the usual speed slider at the
very top in the middle (normal).
I also added a button ("clear stop") and a switch ( verbose?)
normally off. With verbose? ON, the model runs very very slowly and
color codes which cell is about to move to which cell ( blue is moving
to yellow ) and they both temporarily change to squares.
HOW TO USE IT
1) set msecs-per-tick to 50 2) shut off verbose?, click SETUP, click
GO. The model will run 746 ticks. ( thats with the random-seed set to
a value of 34567 in globals. )
3) After it stops at tick 746. click clear-stop.
NOTICE the CTI group at the upper right. This is logically BETWEEN the
two C-cells which have linked up. This group will be snipped-out of
the moving DNA It has who numbers 7, 8, 9 and 10 as you can see by
inspecting it.
4) click one-step 6 times to advance to where you can see more clearly
that the two groups have become separate. Then turn on verbose? and
click one-step once to watch the gory details with a 4 second pause
between cell-moves and the running commentary in the Command Center
telling which cells are about to move.
好的 - 我终于明白是怎么回事了。这很难看出。我用过的技巧
为了看到它列在 post.
的底部
在合成 DNA 单链 的情况下,
当两个相同类型的细胞碰撞并粘在一起时,此时会有
是 在移动单元格和 之间的所有单元格的循环
运行 进入单元格序列列表的单元格。
您需要做的是:
(a) 将刚刚 运行 进入的单元格和 link 并将其绑定到移动
单元格,使移动单元格成为 link [领带] 的主控单元格。你做吧
已经.
(b) 从您的代码的单元格列表中删除您刚刚创建为 SLAVE 的单元格
必须移动,因为它现在会在主单元格时自动移动
移动。
而且……重要的是……
(c) 对列表中位置介于两者之间的每个单元格重复步骤 (a) 和 (b)
刚刚碰撞并卡住的两个细胞。**
这将有效地冻结整个循环的配置并使之
变成一个大单元,当主单元被移动时,它将作为一个单元移动
被你的代码打动了。
用户手册在链接部分的 TIE 小节中指出:
When the root turtle turns right or left, the leaf turtle rotates
around the root turtle the same amount as if a stiff were attaching
the turtles. When tie-mode is set to “fixed” the heading of the leaf
turtle changes by the same amount.
我认为您确实希望将连接模式设置为 FIXED,这样当主单元旋转时整个集群也会旋转。
我认为,但没有研究过,即使 linked 单元格是链上的第一个或最后一个单元格,该算法也能正常工作。不过最好检查一下。也许应该是 MASTER 的单元格是被击中的单元格,而不是移动的单元格。
在两条不同的DNA链相交的情况下,
基本上形成一个 X,或更复杂的情况......我让你自己决定你想要更大的连接结构做什么,以及 hit 应该如何移动。每条链的两个前导细胞是否同时拉动它?您是否需要关闭其中一个以便只有一个单元移动人群?您是否需要更改移动链的代码以将其中一条链完全插入列表中按顺序移动它们的另一条链的中间?我不知道!
顺便说一句,为了解决这个问题,我必须:
- 放慢动作
- 将单元格的颜色设置为[0 255 0 125],即半透明的绿色
所以我可以看穿它们,看穿它们重叠,
- 使用 Inspector 的 "watch" 功能跟踪我认识的其中一个单元格
本来要 link 起来,
- 使用检查器中的滑块尽可能放大,然后
- 将 500 毫秒 "wait" 放在最内层的动作循环中。
我正在制作一些细胞链的模型(作为更大的 DNA 串模型的一部分)。它们在屏幕上摆动,当它们摆动太多时,它们接近同一字符串中同一类型的单元格,它们必须用该单元格创建一个 link。
下面的代码。
有点管用....但是在我介绍了上面描述的 linking 行为之后,字符串很快就断成碎片了。我不明白为什么 :-) 有什么想法吗?
谢谢,
帕勒
breed [cells cell]
cells-own [paired?]
globals [chains]
to setup
clear-all
set chains []
addchain
reset-ticks
end
to go
foreach chains [c -> movechain c]
ask cells [if any? other cells-here with [label = [label] of myself and paired? = false] [
let makker one-of other cells-here with [label = [label] of myself and paired? = false]
create-link-with makker [tie]
set color red
set paired? true
ask makker [set color red set paired? true]
print word label " was found!"
]]
tick
end
to addchain
set chains lput makechain chains
end
to movechain [mylist]
let antalfollowers length mylist - 1
let i antalfollowers
repeat antalfollowers [
ask item i mylist [
move-to (item (i - 1) mylist)
]
set i i - 1
]
ask first mylist [
right random-float wigglefactor
left random-float wigglefactor
fd 1
]
end
to-report makechain
let mylist []
let text "MGIVEQCCTSICSRYQ"
let startx random-xcor / -3
let starty random-ycor / -3
let i 0
repeat length text [
create-cells 1 [
set color green
set shape "circle"
set label item i text
set paired? false
set mylist lput self mylist
setxy startx + i * .75 starty + i * .75
]
set i i + 1
]
report mylist
end
我正在处理您的问题并取得了一些进展 -- 至少我对您的代码进行了修订,增加了一些故障排除,并对界面进行了修订。我不知道如何在此处附加模型,或者当您 运行 时您将看到的视图图像,所以我在 netlogo-users Google Group 中发布了完整的模型和一个 PNG 文件。
这些修订没有完全回答你关于如何解决链断裂的问题,但它们提供了一个可重现的模型版本,你可以肯定它会在第 746 步断裂并且你可以打开密集打印和慢动作,然后观察之后尝试的动作发生了什么。
也许如果我们都看一下它为什么会崩溃。
我认为可能发生的一件事是,一旦两个单元格 link 并打成平手,您的移动算法就不再是打结链应该如何移动的正确逻辑。
这是我所做的更改:
我在设置中添加了一个随机种子命令,这样模型就可以重复运行随机变量的选择完全相同,所以我们都可以看看结果。
我在界面上添加了一个 "verbose?" 开关来打开或关闭正在发生的事情的详细打印。
我添加了一个 "clear-stop" 按钮,允许我放入模型中的 "stop" 命令使用停止请求停止 运行ning?标志,代码设置,此按钮重置,以便 "go" 和 "one step" 在停止后再次工作,滴答计数器继续递增。
我添加了一个 msec-per-tick 滑块以在 go 步骤结束时放置固定的毫秒数,因此模型将 运行 以可用于调试的速度.我不知道其他人是怎么做到的——当我尝试使用界面顶部的内置滑块来控制速度时,要么太慢,要么太快,我做不到似乎能够将其调整到恰到好处。所以我添加了这个kludge。
我猜到您对界面上的 wigglefactor 滑块有什么限制,并制作了一个从 0 到 90(度)的滑块。它工作正常并重现了你的错误。
我添加了一些额外的测试,以防止在您选择的单元格中相邻的两个 C 单元格在发现时相互 linking,因为他们有时会这样做,他们在同一个补丁上。 使用随机种子 23456,例如,您的原始代码在 tick 2 中将其自己的 CC 相邻对连接在一起。
(
这是修改后的代码,关于如何使用它的注释在发布的模型(在 netlogo-users 中)和代码后面。
breed [cells cell]
cells-own [paired?]
globals [
chains
stop-requested? ;;//////////////////////////////////////////////////
]
to setup
clear-all
;; random-seed 12345 ;; /////////////// breaks at either step 35 or 45 ////
;; random-seed 23456 ;; ////////////////// ties its own CC in tick 2 ///
random-seed 34567 ;; /////////////////// ties own cc in tick 84 , ties C at 746 and breaks in 6 steps
;;// wow -- it SNIPS TSIC out of the middle of the chain!! snips out CTIS, turtles 7 8 9 and 10
;; cell 6 C is directly followed by cell 11 -- also C
set chains []
addchain
set stop-requested? FALSE ;; ////////////////////////////////////////
reset-ticks
end
to go
if stop-requested? [ stop ] ;;////////////////////////////////////////////
foreach chains [c -> movechain c]
ask cells [if any? other cells-here with [label = [label] of myself and paired? = false
and who != [who] of myself + 1
and who != [who] of myself - 1
] [
let makker one-of other cells-here with [label = [label] of myself and paired? = false]
create-link-with makker [tie]
set color red
set paired? true
ask makker [set color red set paired? true]
print ( word label " was found at tick " ticks)
set stop-requested? TRUE ;;/////////////////////////////////////////////
]]
wait ( msec-per-tick / 1000 ) ;;////////////////////////////////////////
tick
end
to addchain
set chains lput makechain chains
end
to movechain [mylist]
if verbose? [print ( word "\n\nin code at tick " ticks " starting movechain") ];;//////////////
;;if verbose? [ show mylist ]
let antalfollowers length mylist - 1
let i antalfollowers
repeat antalfollowers [
ask item i mylist [
if verbose? [
;;print (word " asking item " i " on mylist to move to item " (i - 1) )
let mover [label] of item i mylist
let moveto [label] of item (i - 1) mylist
let mover-color [color] of item i mylist
let moveto-color [color] of item (i - 1) mylist
;; BLUE one moves TO the YELLOW ONE at the end of this second
print (word " move " mover " to " moveto )
ask item i mylist [set color blue set shape "square" set size 2]
ask item (i - 1) mylist [set color yellow set shape "square" set size 2]
display
wait 4
ask item i mylist [set color mover-color set shape "circle" set size 1]
ask item (i - 1) mylist [set color moveto-color set shape "circle" set size 1]
display
]
move-to (item (i - 1) mylist)
;;print word "just moved follower " i ;;//////////////////////////
;; wait 0.1 ;;////////////////////////////////////////////////////
]
set i i - 1
]
ask first mylist [
right random-float wigglefactor
left random-float wigglefactor
fd 1
]
end
to-report makechain
let mylist []
let text "MGIVEQCCTSICSRYQ" ;; NOTE - this has a repeat of CC in it which SOMETIMES gets tied (23456 tick 2)
let startx random-xcor / -3
let starty random-ycor / -3
let i 0
repeat length text [
create-cells 1 [
set color green
set shape "circle"
set label item i text
set paired? false
set mylist lput self mylist
setxy startx + i * .75 starty + i * .75
]
set i i + 1
]
report mylist
end
to clear-stop ;;////////////////////////////////
set stop-requested? FALSE ;;////////////////////////////////
end ;;////////////////////////////////
Anyway, here's how to run it to reproduce the problem and examine it in fine detail very closely.
WHAT IS IT?
model of DNA in motion modified for troubleshooting. When a "C" cell touches another "C" cell in step 746, and sets a link between the two C cells and ties them to move as one, the algorithm for motion breaks somehow. This may help figure out why,
HOW IT WORKS
This has added to it a msec-per-tick slider, default 50, to set the display speed about right if you leave the usual speed slider at the very top in the middle (normal).
I also added a button ("clear stop") and a switch ( verbose?) normally off. With verbose? ON, the model runs very very slowly and color codes which cell is about to move to which cell ( blue is moving to yellow ) and they both temporarily change to squares.
HOW TO USE IT
1) set msecs-per-tick to 50 2) shut off verbose?, click SETUP, click GO. The model will run 746 ticks. ( thats with the random-seed set to a value of 34567 in globals. )
3) After it stops at tick 746. click clear-stop.
NOTICE the CTI group at the upper right. This is logically BETWEEN the two C-cells which have linked up. This group will be snipped-out of the moving DNA It has who numbers 7, 8, 9 and 10 as you can see by inspecting it.
4) click one-step 6 times to advance to where you can see more clearly that the two groups have become separate. Then turn on verbose? and click one-step once to watch the gory details with a 4 second pause between cell-moves and the running commentary in the Command Center telling which cells are about to move.
好的 - 我终于明白是怎么回事了。这很难看出。我用过的技巧 为了看到它列在 post.
的底部在合成 DNA 单链 的情况下, 当两个相同类型的细胞碰撞并粘在一起时,此时会有 是 在移动单元格和 之间的所有单元格的循环 运行 进入单元格序列列表的单元格。
您需要做的是:
(a) 将刚刚 运行 进入的单元格和 link 并将其绑定到移动 单元格,使移动单元格成为 link [领带] 的主控单元格。你做吧 已经.
(b) 从您的代码的单元格列表中删除您刚刚创建为 SLAVE 的单元格 必须移动,因为它现在会在主单元格时自动移动 移动。
而且……重要的是……
(c) 对列表中位置介于两者之间的每个单元格重复步骤 (a) 和 (b) 刚刚碰撞并卡住的两个细胞。**
这将有效地冻结整个循环的配置并使之 变成一个大单元,当主单元被移动时,它将作为一个单元移动 被你的代码打动了。
用户手册在链接部分的 TIE 小节中指出:
When the root turtle turns right or left, the leaf turtle rotates around the root turtle the same amount as if a stiff were attaching the turtles. When tie-mode is set to “fixed” the heading of the leaf turtle changes by the same amount.
我认为您确实希望将连接模式设置为 FIXED,这样当主单元旋转时整个集群也会旋转。
我认为,但没有研究过,即使 linked 单元格是链上的第一个或最后一个单元格,该算法也能正常工作。不过最好检查一下。也许应该是 MASTER 的单元格是被击中的单元格,而不是移动的单元格。
在两条不同的DNA链相交的情况下, 基本上形成一个 X,或更复杂的情况......我让你自己决定你想要更大的连接结构做什么,以及 hit 应该如何移动。每条链的两个前导细胞是否同时拉动它?您是否需要关闭其中一个以便只有一个单元移动人群?您是否需要更改移动链的代码以将其中一条链完全插入列表中按顺序移动它们的另一条链的中间?我不知道!
顺便说一句,为了解决这个问题,我必须:
- 放慢动作
- 将单元格的颜色设置为[0 255 0 125],即半透明的绿色 所以我可以看穿它们,看穿它们重叠,
- 使用 Inspector 的 "watch" 功能跟踪我认识的其中一个单元格 本来要 link 起来,
- 使用检查器中的滑块尽可能放大,然后
- 将 500 毫秒 "wait" 放在最内层的动作循环中。