我有两个品种:步行者(动态)和事件(静态)。 步行者沿着链接(街道)移动并随意转弯。 事件随机放置在某些未知节点上。
每个代理人如何知道他到达一个事件之前所遵循的路径? 我想知道是否可以将它保存在列表或甚至矩阵中,其中每一行都是一个路径,然后查找不同的事件,但我不知道如何收集这些节点/链接。
如果助行者发现了一个事件,他怎么能记下它以及如何保存这些数据呢?
非常感谢您的帮助
答案 0 :(得分:1)
以下是对“走路乌龟”的修改'模型库中的代码示例,其中walker现在具有路径变量。当walker移动到下一个节点时,它使用lput
将新节点放在列表的末尾。一旦到达"事件,将由您来管理或清除此列表。在你的模型中。您可能还希望修改此方法以存储多个路径而不是单个路径。
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