简体   繁体   中英

How to get more paths than the shortest path between nodes?

in d3.js I am using a fuction called path to get the shortest path between 2 nodes. The API says this:

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 :

 .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

This is called the k shortest paths problem . You can solve it using a variant of Dijkstra's algorithm called Eppstein's Algorithm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM