Netlogo nw:加权路径到,nw:加权路径到和多个等权路径上的海龟

Netlogo nw:加权路径到,nw:加权路径到和多个等权路径上的海龟,netlogo,Netlogo,如果这是一个愚蠢的问题,我先道歉 当调用链接列表的nw:weightedpath时,返回描述起始和目标海龟之间最短路径的路径 类似地,调用nw:turtles on weighted path返回起点和终点之间最短路径上的海龟列表 我的理解是,如果在原点和目标之间有两条加权相等的路径,则两个函数都会随机返回其中一条路径。这是独立发生的,因此一组链接可以产生最短路径,但另一组海龟。这可以使用以下代码进行复制: extensions [nw] links-own [ weight ] to go

如果这是一个愚蠢的问题,我先道歉

当调用链接列表的nw:weightedpath时,返回描述起始和目标海龟之间最短路径的路径

类似地,调用nw:turtles on weighted path返回起点和终点之间最短路径上的海龟列表

我的理解是,如果在原点和目标之间有两条加权相等的路径,则两个函数都会随机返回其中一条路径。这是独立发生的,因此一组链接可以产生最短路径,但另一组海龟。这可以使用以下代码进行复制:

extensions [nw]

links-own [ weight ]

to go
   clear-all
   create-turtles 4

   ask turtle 0 [ create-link-with turtle 1 [ set weight 2 ] ]
   ask turtle 0 [ create-link-with turtle 2 [ set weight 2 ] ]

   ask turtle 1 [ create-link-with turtle 3 [ set weight 2] ]
   ask turtle 2 [ create-link-with turtle 3 [ set weight 2] ]


   ask turtle 0 
   [
        let pathLinks nw:weighted-path-to turtle 3 "weight"
        let pathNodes nw:turtles-on-weighted-path-to turtle 3 "weight" 
        let pathUtility nw:weighted-distance-to turtle 3 "weight" 

        show pathLinks
        show pathNodes
        show pathUtility
   ]

end 
这将愉快地产生:

(turtle 0): [(link 0 2) (link 2 3)]
(turtle 0): [(turtle 0) (turtle 1) (turtle 3)]
(turtle 0): 4
显然,这不是一个错误,但不幸的是,它把我绊倒了

我的问题是——将这两个过程链接起来,生成链接列表和海龟列表,组成一条随机选择的最短路径,最明智的方法是什么

我假设最好返回带有nw:weighted path to的链接,然后要求链接返回两端,并执行某种独特的操作以在该路径上生成一组海龟,如果是这种情况,我不确定如何保持海龟的顺序。这有意义吗?你会这样做吗

一如既往,感谢您的阅读


编辑:这也适用于具有多条等长路径的拓扑网络中的路径到和路径到上的海龟。

好问题!您可以从另一个列表生成任意一个列表,但我认为从海龟路径到链接路径更容易:

;; Construct the turtle path, putting the current turtle on the front:
let turtle-path fput self nw:turtles-on-weight-path-to turtle 3 "weight"

;; Iterate through pairs of turtles, getting the link connecting them
let link-path (map [[link-with ?2] of ?1] but-last turtle-path but-first turtle-path)
编辑:

尼古拉斯关于“链接路径到海龟路径”的说法绝对正确。然而,他的评论让我意识到你可以使用万能的
reduce
和非常有用的
另一端来做这件事

reduce [ lput [[other-end] of ?2] of (last ?1) ?1 ] fput (list self) nw:weighted-path-to turtle 3 "weight"
Edit2:“链接路径到海龟路径”代码非常不透明。下面是一个澄清的尝试:

to-report add-link-to-turtle-path [ turtle-path next-link ]
  let last-turtle last turtle-path
  report lput [[other-end] of next-link] of last-turtle
end

;; turtle-procedure - Assumes the current turtle is the starting point of the path
to-report link-path-to-turtle-path [ link-path ]
  let start-of-path (list self)
  report reduce add-link-to-turtle-path fput start-of-path link-path
end

是的,事实上,“链接路径到海龟路径”是非常困难的,至少对于无向链接来说是如此,因为
end1
end2
不一定是“路径顺序”。如果你有一条很长的路,除非你一直抓住海龟的起点或终点,否则没有办法知道顺序应该是什么。很好的答案!非常感谢。而且,也许更重要的是,我已经了解了
reduce
——这似乎是我几年前就应该知道的。再次感谢。这在某个时候被考虑作为扩展原语包含:。