在下面的补丁中复制链接品种变量 [英] Copy the link breed variable in the patch below
问题描述
我有一个由节点和链接组成的网络.这个数字
I have a network of nodes and links. This figure
是对世界的捕捉.该图表示城市的街道.我已经导入了带有gis扩展名的shapefile.灰线是链接,黑点是节点,红点表示人.人们将前往下一个节点.在街道拐角处,红点通过检查链接拥有的变量popularity
选择下一条街道.
is a capture of the world. The graph represents streets of a city. I have imported a shapefile with the gis extension. The gray lines are links, black dots are nodes and red dots represent people. The people move heading to the next node. In a street corner, the red dot chooses next street by examining the variable popularity
owned by the link.
链接品种具有变量popularity
,我想在下面的补丁中复制其值.
The links breed has a variable, popularity
, whose value I would like to copy in the patches that are below.
例如,如果我尝试访问链接下的补丁,将产生错误
If I try, for example, something like this to access patches under links will produce an error
ask links [show [(list pxcor pycor)] of patch-here]
另一种方法可以是从补丁程序访问变量流行度的链接,但是我不知道该怎么做.
Another approach can be to access links variable popularity from patches, but I do not know how to do it.
之所以这样,是因为我想在文件中写入一个流行度值矩阵,并且其在矩阵中的位置应与链接在世界上的位置相对应.因此,链接下面的补丁会给我矩阵形式.我有一个过程,每个补丁程序将补丁程序的值写入文件中.但是,我不知道如何将popularity
值从链接传递到它下面的补丁.
The reason why I want this is because I want to write in a file a matrix of popularity values and its position in the matrix should correspond with the position of the link in the world. Thus, the patches below the links would give me the matrix form. I have a procedure that for each patch writes the value of the patch in a file. However, I do not know how to pass the popularity
value from the link to the patch below it.
是否可以将链接拥有的变量复制到其补丁?
Is there any way to copy a link owned variable to its patch?
致谢
推荐答案
如果有人有更好的方法(或者可以简化我的代码),请放心.这是一个完整的工作示例.将其复制到一个空的NetLogo模型中,然后运行它以查看其工作.
If someone has a better way of doing this (or can simplify my code), feel free. Here is a complete working example. Copy it into an empty NetLogo model and run it to see it work.
setup
过程仅创建一些具有适当测试值的节点和链接,然后调用transfer-link-values过程,该过程符合我的期望.然后setup
过程将这些值放入补丁标签中以显示它们并查看结果.
The setup
procedure just creates some nodes and links with appropriate test values and then calls the transfer-link-values procedure, which does what I think you want. The setup
procedure then puts the values into the patch labels to display them and see the results.
transfer-link-values过程的工作方式是在链接的一端创建一个乌龟,然后该乌龟移向链接的另一端,从而在传递值的同时进行传递.当到达另一端时,乌龟死亡.
The way the transfer-link-values procedure works is to create a turtle at one end of the link, and that turtle moves toward the other end of the link transferring the value as it goes. When it gets to the other end, the turtle dies.
patches-own [patch-popularity]
links-own [link-popularity]
to setup
clear-all
create-turtles 10 [ setxy random-xcor random-ycor]
while [ any? turtles with [not any? my-links] ]
[ let to-pair turtles with [not any? my-links]
let thisNode one-of to-pair
ask thisNode
[ create-link-with one-of other to-pair
[ set link-popularity 5 + random 5 ]
]
]
transfer-link-values
ask patches [ if patch-popularity != 0 [set plabel patch-popularity ] ]
end
to transfer-link-values
ask links
[ let start-node one-of both-ends
let this-link self
let end-node nobody
ask start-node [ set end-node [other-end] of this-link ]
let transfer-value link-popularity
ask start-node
[ hatch 1
[ face end-node
if transfer-value > patch-popularity
[ ask patch-here [ set patch-popularity transfer-value ] ]
while [ not member? end-node turtles-here ]
[ forward 1
if transfer-value > patch-popularity
[ ask patch-here [ set patch-popularity transfer-value ] ]
]
if transfer-value > patch-popularity
[ ask patch-here [ set patch-popularity transfer-value ] ]
die
]
]
]
end
这篇关于在下面的补丁中复制链接品种变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!