Kth shortest path in undirected graph - graph

Is there any way with polynomial complexity(or better than that) to get kth or k shortest path of an undirected graph?
or can Yen's k shortest path algorithm modified for undirected graphs?

Try to find the permutations of paths from source vertex to final vertex (taking all vertex atleast once) upto k permutations but this would also mean if the total permutations of paths from source vertex to final vertex (taking all vertex atleast once) are finite but that wouldnt be the case as in case of NP hard problems. if you can find this heuristic in polynomial time then you can select kth shortest path. so apply brute force dfs bfs then find the shortest path via dynamic programming and compare your permutations with kth case

Related

Updating shortest path tree

Assume we are given a weighted, connected, directed graph G, a vertex s and the shortest path tree for s. So we already know all the shortest distances from s to every other vertex in the graph.
Now the following happens, we add an edge to the graph.
Is there an efficient way to get the new shortest path tree?
How can I calculate the new shortest path tree by encountering the old one?

Shortest Path Function (Dijkstra's Algorithm)

I have a data frame composed of a latitude, longitude, node ID, from NodeID, to Node_ID, length. The from and to node columns are my edges. I can only travel on my edges when trying to find the shortest path. I want to be able to go from a node to another node while minimizing my total length traveled. The output should return every node I have to travel through to get to my destination. I have tried many built in packages like cppRouting and igraph, but I can not get anything to work correctly . Any ideas on how to either create a function or how to use any existing functions to accomplish this? Thank you.
Below are the detailed steps used in Dijkstra’s algorithm to find the shortest path from a single source vertex to all other vertices in the given graph.
Algorithm:
1) Create a set sptSet (shortest path tree set) that keeps track of vertices included in shortest path tree, i.e., whose minimum distance from source is calculated and finalized. Initially, this set is empty.
2) Assign a distance value to all vertices in the input graph. Initialize all distance values as INFINITE. Assign distance value as 0 for the source vertex so that it is picked first.
3) While sptSet doesn’t include all vertices
….a) Pick a vertex u which is not there in sptSet and has minimum distance value.
….b) Include u to sptSet.
….c) Update distance value of all adjacent vertices of u. To update the distance values, iterate through all adjacent vertices. For every adjacent vertex v, if sum of distance value of u (from source) and weight of edge u-v, is less than the distance value of v, then update the distance value of v.
Go through the following link: Printing Paths in Dijkstra’s Shortest Path Algorithm

Most efficient way or algo to find shortest path between any two nodes in a graph?

I have a huge graph of network nodes. I would like to know what is the most efficient algo or technique to obtain the shortest path between any two nodes in the graph?
I have studied an algorithm of "All pair shortest path" but the time complexity is O(V^3) which is worse in my case as the number of nodes is large. How to reduce this complexity?

Dijkstra algorithm with min-priority queue

I'm trying to implement the dijkstra algorithm with priority queue, but I can't understand how it works. I read many guide on the web but I can't understand this algorithm at all.
My questions are: What is the priority for each node? I think that it is the weight of the incoming edge with the minimum value, but I'm not sure. Is this true?
Second question, when I extract the root of the queue, how does it work if this node is not adjacency with no one of the visited nodes?
You should use priority queue where the vertex with the shortest distance from the starting vertex will get the highest priority. Initially, all vertices will have the shortest distance of infinity and the starting vertex will have the shortest distance 0.
Start by inserting of all vertices (with its edges) from the graph inside the PQ. Remove vertex from the PQ and explore all its edges. Compare the shortest distances with all adjacent vertices and if any distance is less than the shortest distance on the current vertex, update adjacent vertex shortest distance inside the PQ. Continue while PQ is not empty. Vertices which got no edges will finish with the shortest distance of infinity because it is not possible 'get to them' from the starting vertex. However, they will be still removed from the PQ.
Pseudocode
initialize graph
initialize pq
pq.insertAll(graph.getVertices())
while (pq is not empty) {
vertex = pq.remove()
edges = vertex.getEdges()
for all edges {
destination = edge.getDestination()
newDistance = edge.getLength() + vertex.getDistance()
if (newDistance < destination.getDistance()) {
destination.setShortestDistance(newDistance)
pq.update(destination)
}
}
}
MIT OpenCourseWare Links:
Path problems overview
Dijkstra

Finding shortest path contaning exactly one negative edge in a graph

I am given a directed graph with a weight function and a vertex s.
My goal is to find for any other vertex v, the shortest path from s to v that goes through exactly one negative edge. The time complexity of the algorithm should be O(|E| + |V|*log|V|), so guess I need to use Dijkstra's algorithm somehow.
I am guessing that I need to translate my given graph somehow to a new graph with non-negative weights that a shortest path from s to v in this graph will be equivalent to the required shortest path in the given graph.. or maybe I need to modify Dijkstra's algorithm somehow??
I tried to think about it a little, don't have any ideas right now... :(

Resources