I want to find the next shortest path between 2 vertices in a graph and the path has a positive cost.The next shortest path is allowed to share edges of the shortest path .W
This is assuming you can reuse edges and nodes:
A straightfoward solution is do make an extension of the Djikstra Algorithm.
Instead of storing for each node the smallest cost and its respective parent, store the two smallest costs (and their respective parents).
For the priority queue, intead of storing nodes, store (node, i) pairs, so you know wether to use the 1st or 2nd path during propagation.
Take care during the propagation phases to keep the multiple path values correctly updated.
(I might be missing some important details but the basic idea is here...)
When you prefer a practical solution to an academic one, here is one.
I solved this by setting a penalty to the shortest path edges and running the search again.
E.g. shortest path has length 1000, penalty is 10%, so I search for a 2nd shortest path with 1000<=length<=1100.
In the worst case I find the previous shortest path.
In the best case I find a disjunct path with the same length.
In most cases I find a path sharing some locally optimal subpaths.
Increasing the penalty forces the algorithm to find alternative routes, while decreasing makes it sharing tolerant.
When I find the 2nd shortest path, I have to subtract the sum of penalties on shared edges from the computed length to get the real length.
For k-th shortest path I set the penalty to all edges used in previous k-1 shortest paths.