in d3.js I am using a fuction called path
to get the shortest path between 2 nodes. The API says this:
在d3.js我使用一个名为path的函数来获取2个节点之间的最短路径。 API说:
node.path(target) <>
Returns the shortest path through the hierarchy from this node to the specified target node. The path starts at this node, ascends to the least common ancestor of this node and the target node, and then descends to the target node.
返回层次结构中从此节点到指定目标节点的最短路径。路径从此节点开始,上升到此节点和目标节点的最不常见的祖先,然后下降到目标节点。
With this definition i created a new array to save the data between 2 nodes. I am able to click on a first node called beginNode
and on a second node, which is d
. It works very good and the shortest path between them is saved in the array shortest_path
:
通过这个定义,我创建了一个新数组来保存2个节点之间的数据。我能够点击名为beginNode的第一个节点和第二个节点,即d。它工作得非常好,它们之间的最短路径保存在数组shortest_path中:
.on("click", function(d, i) //Hier beginnt große "click"-Funktion
{
shortest_path = beginNode && beginNode.path(d) || [];.....
Sometimes there are many ways to get the path between 2 nodes, not only the shortest paths, also longer paths. Now, my goal is to store more paths between the 2 clicked nodes into that array or another array. But unfortunally, d3,js only offer that shortest path function. I hope some of you can help. Would be Djikstra a right solution for this problem? Thanks
有时,有很多方法可以获得2个节点之间的路径,不仅是最短路径,还有更长路径。现在,我的目标是在2个单击的节点之间存储更多路径到该阵列或另一个阵列。但不幸的是,d3,js只提供最短的路径功能。我希望你们中的一些人能提供帮助。 Djikstra是解决这个问题的正确方法吗?谢谢
1 个解决方案
#1
2
This is called the k shortest paths problem. You can solve it using a variant of Dijkstra's algorithm called Eppstein's Algorithm
这称为k最短路径问题。您可以使用称为Eppstein算法的Dijkstra算法变体来解决它
#1
2
This is called the k shortest paths problem. You can solve it using a variant of Dijkstra's algorithm called Eppstein's Algorithm
这称为k最短路径问题。您可以使用称为Eppstein算法的Dijkstra算法变体来解决它