I have a networkx graph in which a cost has been assigned to each edge, and I want to compute the path from source to target nodes that represents broadest bottleneck instead of shortest path. So, highest edge cost should be minimized instead of the sum of individual edge costs. What algorithm should I use?
Related
I need to write the difference between implicit and non-implicit path cost as part of one of my assignments.I know what we mean by an implicit graph but have no idea about what is implicit-path-cost.
The implicit path cost is the sum of the time moving to a vertex plus the cost of calculating the neighborhood of the current vertex which depends on the specific graph (problem) you are working with.
For example in a chess game you have a set of possible moves (future states/vertices) that are connected to the current state/vertex of the board, you need to calculate them before moving to one of them.
"Given a connected undirected weighted graph, find the maximum weight of the edge in the path from s to t where the maximum weight of the edges in the path is the minimum."
This seems like a Floyd–Warshall algorithm problem. Is there an approach faster than O(V^3)?
I submit that a breadth first search (BFS) to determine whether s is connected to t by any path can run in O(V) time, since each vertex need only be visited once.
I propose therefore, that the solution to this problem is to sort the edges by weight, and then
while the BFS succeeds in finding a path from s to t
remove the highest weighted edge from the graph
The last edge to be removed before the BFS fails is the maximum weighted edge that you're looking for.
Total running time is O(E log E) to sort the edges by weight, plus O(VE) to run the BFS until removing an edge disconnects the graph.
Here is my problem: I have a directed weighted graph with a substantial amount of vertices (few thousands), no cycles, in fact, it includes a starting node, a final node and a grid (m*n) between them, where edges can be directed from the left to the right only.
The weights of the edges depend on the path in which they are included (for example, if the path includes v.15, then the weights of several edges change).
I tried to get all possible paths and then calculate their final sum post factum, but that turned out to be very inefficient method due to the number of paths. Is there an effective method which allows to find shortest paths in these kind of graphs? Thanks.
Is it possible to modify A* to return the shortest path with the least number of turns?
One complication: Nodes can no longer be distinguished solely by their location, because their parent node is relevant in determining future turns, so they have to have a direction associated with them as well.
But the main problem I'm having, is how to work number of turns into the partial path cost (g). If I multiply g by the number of turns taken (t), weird things are happening like: A longer path with N turns near the end is favored over a shorter path with N turns near the beginning.
Another less optimal solution I'm considering is: After calculating the shortest path, I could run a second A* iteration (with a different path cost formula), this time bounded within the x/y range of the shortest path, and return the path with the least turns. Any other ideas?
The current "state" of the search is actually represented by two things: The node you're in, and the direction you're facing. What you want is to separate each of those states into different nodes.
So, for each node in the initial graph, split it into E separate nodes, where E is the number of incoming edges. Each of these new nodes represents the old node, but facing in different directions. The outgoing edges of these new nodes will all be the same as the old outgoing edges, but with a different weight. If the old weight was w, then...
If the edge doesn't represent a turn, make the new weight w as well
If the edge does represent a turn, make the new weight w + ε, where ε is some number significantly smaller than the smallest weight.
Then just do a normal A* search. Since none of the weights have decreased, your heuristic will still be admissible, so you can still use the same heuristic.
If you really want to minimize the number of turns (as opposed to finding a nice tradeoff between turns and path length), why not transform your problem space by adding an edge for every pair of nodes connected by an unobstructed straight line; these are the pairs you can travel between without a turn. There are O(n) such edges per node, so the new graph is O(n3) in terms of edges. That makes A* solutions as much as O(n3) in terms of time.
Manhattan distance might be a good heuristic for A*.
Is it possible to modify A* to return the shortest path with the least number of turns?
It is most likely not possible. The reason being that it is an example of the weight-constrained shortest path problem. It is therefore NP-Complete and cannot be solved efficiently.
You can find papers that discuss solving this problem e.g. http://web.stanford.edu/~shushman/math15_report.pdf
I am facing which I believe is a kind of shortest path problem on a graph.
I need to find shortest path from node A to B, considering all edges have positive weight for connected vertexes, ∞ for not connected ones.
Vertexes have variable positive weightes.
The cost of a path is the weight of the vertex with maximum weight considering all vertexes involved in that path.
Should I apply Dijkstra in this situation, and if so how, considering that the weight of each Vertex changes depending on the previous vertexes visited?
Can you point me on how to tackle this problem otherwise?
I cant understand if you should consider the weights of the edges,because you said that you want the path with the max/min weight on a vertice possible,from A to B.
My solution for that is to convert every weight on vertex,to a weight on edge , just like in the image:
now you want to find the path from A to B where the the biggest weight on edge is min/max.
you can use MST algotirhm for this,because you dont care about the path lenght,but only the max/min edge cost.