我想知道如何计算许多节点内的最短路径到根节点,但我不知道如何以正确的方式做到这一点。节点以某种方式相互连接,因此始终有多条路径通向根节点。JavaScript - 通过图中数百个节点的最短路径
我有所有节点一个js对象,这里是一个片段,如果它:
var nodes = {
11420 : { // no out, but many other nodes have 11420 in their out
out : []
},
18866 : {
out : [11420]
},
739 : {
out : [18866]
},
1957 : {
out : [739]
},
33296 : {
out : [1957, 36774]
},
57264 : {
out : [33296]
},
54447 : { // root
out : [57264]
},
37569 : {
out : [36542, 57264]
}
// ... 1500 nodes more
}
我如何计算的最短路径为让说节点11420根54447? 结果应该是具有节点ID的数组。
谢谢。
[JavaScript中最短路径(HTTP的可能重复:// stackoverflow.com/questions/32527026/shortest-path-in-javascript) –