Shortest path through node group sets
Ältere Kommentare anzeigen
I am trying to find the maximum path through a series of nodes. I have forumulated the problem as a shortest path problem using negative weights for distances between nodes. Node sets are grouped and I want to find a path that only passes through one node of each group. For example, nodes are labeled as start (s) and end (e) and A1, A2, B1, B2, C1, and C2. If a path passes through A1, it cannot pass back through A2. The node groups represent a task that is to be accomplished (letter indicator) while the numeric value indicates a time. This means that task A can be accomplished at two different times but not both. The figure is included for additional information.

I originally started using the 'shortestpath' function in matlab but realized it was revisiting tasks. Are there any algorithms out there that I should look into?
Akzeptierte Antwort
Weitere Antworten (2)
Walter Roberson
am 9 Nov. 2019
0 Stimmen
shortest path with negative weights is subject to looping.
You should instead use weights that are the maximum weight plus 1, minus the existing weights.
2 Kommentare
Skylar Cox
am 9 Nov. 2019
Walter Roberson
am 11 Nov. 2019
Sorry, I did not notice the groups of nodes part before.
For situations like this, you need to work incrementally creating augmented directed graphs.
When you are at S, you have a choice of going to A1. You find the subgraph of all of the places you can get to from A1, and you clone that subgraph into new nodes but with the links back to other members of A deleted, and replace the S -> A1 link with a link from S to that cloned graph. And you do similar things for the other groups, recursively. This can lead to a bunch of branching.
So instead of S -> A1 -> {B1, B2, C3, C4} you would have S -> newA1 -> {A1B1, A1B2, A1C3, A1C4} where A1B1 is like B1 but there is no A1B1 -> A2 link, just A1B1 -> {A1C3, A1C4}
Once S has traversed to newA1 that is disconnected from the previous A1 subtree, then because it is a directed graph, there is no cross-link possible to reach something that could get to a different member of the A group.
Yes, the number of nodes can increase by a fair bit. There might be ways to reduce the branching in some cases.
This approach might perhaps sound too made-up-on-the-spot, but it is similar to the approach that is used to convert Non-Deterministic Finite Automata (NDFA) into Deterministic Finite Automata (DFA), by following all of the paths "simultaneously". A cross-product of states ends up being created, which is the sort of thing that is a nuisance if you are trying to work everything out by hand, but which you can hand over to computers to compute all of.
Thiago Henrique Gomes Lobato
am 10 Nov. 2019
0 Stimmen
If you have negative weightings an Algorithm that would work to find the shortest path is the Bellman-Ford. You can find some information for it (as well as some example implementations) here https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/ . There's also some matlab implementations in file exchange https://de.mathworks.com/matlabcentral/fileexchange/38129-the-bellman-ford-moore-shortest-path-algorithm
1 Kommentar
Skylar Cox
am 10 Nov. 2019
Kategorien
Mehr zu Graph and Network Algorithms finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!