代理如何在移动时保存路径链接并知道它们已到达其他不同品种的代理



我有两个品种:步行者(动态(和事件(静态(。步行者沿着链接(街道(移动并随机转弯。事件随机放置在一些未知节点上。

每个智能体如何知道他在到达一个事件之前所遵循的路径?我想知道是否可以将其保存在列表甚至矩阵中,其中每一行都是查找不同事件的路径,但我不知道如何收集这些节点/链接。

如果步行者发现一个事件,他如何记录它以及如何保存该数据?

非常感谢您的帮助

下面是对模型库中"链接行走的海龟"代码示例的修改,其中步行者现在有一个路径变量。当步行者移动到下一个节点时,它会使用 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

最新更新