代理人如何在移动时保存路径链接并知道他们已经到达其他不同品种的代理人?
How can agents save path links while moving and know they have reached other different breed agents?
我有两个品种:步行者(动态)和事件(静态)。
步行者沿着链接(街道)移动并随机转弯。
事件随机放置在一些未知节点上。
每个代理如何知道他在到达一个事件之前所遵循的路径?
我想知道是否可以将它保存在列表甚至矩阵中,其中每一行都是一条路径,用于查找不同的事件,但我不知道如何收集这些 nodes/links.
如果步行者发现一个事件,他如何记录它以及如何保存该数据?
非常感谢您的帮助
这是对模型库中 'link-walking turtles' 代码示例的修改,其中步行者现在有一个路径变量。当 walker 移动到下一个节点时,它使用 lput
将新节点放在列表的末尾。一旦它在您的模型中达到 "event",您就可以管理或清除此列表。您可能还想修改此方法以存储多个路径而不是单个路径。
breed [nodes node]
breed [walkers walker]
walkers-own [
location
path ; <-- add a path variable
]
to setup
clear-all
set-default-shape nodes "circle"
;; create a random network
create-nodes 30 [ set color blue ]
ask nodes [ create-link-with one-of other nodes ]
;; lay it out so links are not overlapping
repeat 500 [ layout ]
;; leave space around the edges
ask nodes [ setxy 0.95 * xcor 0.95 * ycor ]
;; put some "walker" turtles on the network
create-walkers 1 [
set color red
set location one-of nodes
move-to location
set path (list location) ; <-- setup a path with the first node
]
reset-ticks
end
to layout
layout-spring nodes links 0.5 2 1
end
to go
ask links [ set thickness 0 ]
ask walkers [
let new-location one-of [link-neighbors] of location
;; change the thickness of the link I just crossed over
ask [link-with new-location] of location [ set thickness 0.5 ]
face new-location
move-to new-location
set location new-location
set path lput location path ; <--- add node to end of path list
]
tick
end
我有两个品种:步行者(动态)和事件(静态)。 步行者沿着链接(街道)移动并随机转弯。 事件随机放置在一些未知节点上。
每个代理如何知道他在到达一个事件之前所遵循的路径? 我想知道是否可以将它保存在列表甚至矩阵中,其中每一行都是一条路径,用于查找不同的事件,但我不知道如何收集这些 nodes/links.
如果步行者发现一个事件,他如何记录它以及如何保存该数据?
非常感谢您的帮助
这是对模型库中 'link-walking turtles' 代码示例的修改,其中步行者现在有一个路径变量。当 walker 移动到下一个节点时,它使用 lput
将新节点放在列表的末尾。一旦它在您的模型中达到 "event",您就可以管理或清除此列表。您可能还想修改此方法以存储多个路径而不是单个路径。
breed [nodes node]
breed [walkers walker]
walkers-own [
location
path ; <-- add a path variable
]
to setup
clear-all
set-default-shape nodes "circle"
;; create a random network
create-nodes 30 [ set color blue ]
ask nodes [ create-link-with one-of other nodes ]
;; lay it out so links are not overlapping
repeat 500 [ layout ]
;; leave space around the edges
ask nodes [ setxy 0.95 * xcor 0.95 * ycor ]
;; put some "walker" turtles on the network
create-walkers 1 [
set color red
set location one-of nodes
move-to location
set path (list location) ; <-- setup a path with the first node
]
reset-ticks
end
to layout
layout-spring nodes links 0.5 2 1
end
to go
ask links [ set thickness 0 ]
ask walkers [
let new-location one-of [link-neighbors] of location
;; change the thickness of the link I just crossed over
ask [link-with new-location] of location [ set thickness 0.5 ]
face new-location
move-to new-location
set location new-location
set path lput location path ; <--- add node to end of path list
]
tick
end