I've been trying to find a way to efficiently solve the k-shortest path problem. There is a code online that implements Yen's algorithm, but it takes input as an adjacently matrix with inf to mark disconnected nodes. I have over 10^6 nodes, so this requires a dense matrix with 10^12 entries, which is impractical. I tried implementing Yen's algorithm myself using the graph class, but it is very slow because of all the time spent removing edges from the graph. I then thought maybe a method based on the shortestpathtree would be more efficient. I can compute this tree in 0.3s but a single traveral of the tree takes 5s.
Is there an efficient way to traverse the tree? It's not much use to generate the tree if I can't actually use it for anything. It seems like in general the functions that actually find and operate on nodes and edges are very slow. I traversed the tree by invoking predecessor repeatedly. Is there another approach that is faster?
Alternatively, is there a better way to solve the k-shortest path problem?