Finding shortest path in the dynamic graph - 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.

Related

Is there a decent algorithm for finding the shortest spanning walk in a weighted directed graph?

I have a weighted directed graph. I'm defining a "spanning walk" here as a walk through the graph that visits each vertex at least once, with no limitations on what edges need to be traversed. I'm trying to find the shortest of such walks, if one exists.
Here's an image of an example graph, whose shortest spanning walk is c->d->b->a, with a length of 6
I tried looking into Hamiltonian paths and the Traveling Salesman Problem and such, but as I'm allowed to visit a vertex multiple times in my problem, I don't know if I can make much use of it. I'm almost completely convinced the problem is NP-hard, but wondering if there's anything to make a search not take centuries for larger graphs.

Can we use Bellman-ford algorithm for a graph containing multiple sources?

we know that we can use Dijkstra Algorithm for graph containing multiple sources for example this problem can be solved by using multiple Dijkstra's algorithm for multiple sources. Similarly, can we implement
Bellman-ford algorithm ? If possible share pseudo code.
Assume that the graph contains negative weight edges and no negative cycles.
Sure! One simple way to do this is to turn the original graph, which has multiple sources, into a new graph with exactly one source. Just add in a new node s that has zero-cost directed edges to each of the sources from the original graph. Running Bellman-Ford starting at this new node s then effectively simulates finding shortest paths starting from each of the sources.

Pathfinding: broadest path

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?

algorithm for 'generalized' matching in complete graphs

My problem is a generalization of a task solved by [Blossom algorithm] by Edmonds. The original task is the following: given a complete graph with weighted undirected edges, find a set of edges such that
1) every vertex of the graph is adjacent to only one edge from this set (i.e. vertices are grouped into pairs)
2) sum over weights of edges in this set is minimal.
Now, I would like to modify the first goal into
1') vertices are grouped into sets of 3 vertices (or in general, d vertices), and leave condition 2) unchanged.
My questions:
Do you know if this 'generalised' problem has a name?
Do you know about an algorithm solving it in number of steps being polynomial of number of vertices (like Blossom algorithm for an original problem)? I don't see a straightforward generalisation of Blossom algorithm, as it is based on looking for augmenting paths on a graph compressed to a bipartite graph (and uses here Hungarian algorithm). But augmenting paths do not seem to point to groups of vertices different than pairs.
Best regards,
Paweł

Pathfinding - A* with least turns

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

Resources