使用netlogo进行随机漫游重新路由问题

时间:2017-05-11 11:33:31

标签: netlogo

我使用以下代码创建了一个小型网络,并实现了随机游走算法。我使用了一些节点作为目标,其中walker最初放在一个节点上。我使用了一个路径(walker-own变量)列表和walker来保存它的位置。

问题:如何防止助行器回到那些已经访问并列在其内存(列表)中的节点。 我是Netlogo的新手,无法实现这种逻辑。

    var noteDelete = document.getElementsByClassName("sticky");
for (var i = 0; i < noteDelete.length; i++) {
  noteDelete[i].onclick = function() {this.parentNode.removeChild(this);}
}

1 个答案:

答案 0 :(得分:0)

你可能想要像let new-location one-of [link-neighbors] of location with [not visited]这样的东西。但是,如果没有,这将产生错误。所以尝试这样的事情。

to go
  ask links [ set thickness 0 ]
  ask walkers [
    let candidate-locations ([link-neighbors] of location) with [not visited?]
    ifelse any? candidate-locations
    [ let new-location one-of candidate-locations
      move-to new-location
      set location new-location
      set path lput location
      ;; This gets turtles to ask their current location 
      ;; to set visited and target to true.
      ask location [
        set visited? true
        if target? = true [ set color red ]
      ]
    ]
    [;;whatever you want to do if all possible paths are blocked
    ]
  ]

  ;; Check for target nodes that have NOT been visited. 
  ;; If there aren't any, stop the model.
  if not any? nodes with [ target? = true and visited? = false ] [
   print ("All target nodes have been visited.")
   stop
  ] 
  tick
end