I want to find all pair shortest path in a large scale of graph. What can I do? In the mean time, is there any kind of stream algorithm to solve all pair shortest path problem in stream graph?
According to the hint of #sudomakeinstall2, I find something interesting to solve dynamical graph problem. Camil Demetrescu's page A New Approach to Dynamic All Pairs Shortest Paths is great one for this problem. They yield a fully dynamic algorithm for general directed graphs with non-negative real- valued edge weights that supports any sequence of operations in O(n2log3n) amortized time per update and unit worst-case time per distance query, where n is the number of vertices
Related
The title is a mouth-full, but put simply, I have a large, undirected, incomplete graph, and I need to visit some subset of vertices in the (approximately) shortest time possible. Note that this isn't TSP, as I don't need to visit all vertices.
The naive approach would be to simply brute-force the solution by trying every possible walk which includes the required vertices, using A*, for example, to calculate the walks between required vertices. However, this is O(n!) where n is the number of required vertices. This is unfeasible for me, as n > 40 in my average case, and n ≈ 80 in my worst case.
Is there a more efficient algorithm for this, perhaps one that approximates the solution?
This question is similar to the question here, but differs in the fact that my graph is larger than the one in the linked question. There are several other similar questions, but none that I've seen exactly solve my specific problem.
If you allow visiting the same nodes several times, find the shortest path between each pair of mandatory vertices. Then you solve the TSP between the mandatory vertices, using the above shortest path costs. If you disallow multiple visits, the problem is much worse.
I am afraid you cannot escape the TSP.
I'm aware that the number of k-length walks between two vertices can be found by finding the kth power of the adjacency matrix, but walks include the traversal of a single edge multiple times in the calculation.
EDIT: I only want to count them not compute them, preferably using matrix algebra. I could do a modified DFS, but thats less efficient than matrix math.
In general, there is no known way to accomplish this. One way to see this is that if you pick k to be the number of nodes in the graph, then you are asking for the number of Hamiltonian paths in the graph. However, the question of determining whether a graph contains a Hamiltonian path is a canonical NP-complete problem, and unless P = NP there's no polynomial-time algorithm for it.
Stated differently - the Hamiltonian path problem reduces to your problem in polynomial time. That makes your problem NP-hard, which means there's no known polynomial-time algorithm for it.
I am designing a system to find shortest route covering least number of cells. Suppose the plane is divided into rectangular cells. What will be the best suited algorithm for this. I am just looking for the head-start and not the proper code or implementation.
You are dealing with shortest path problem, in an unweighted graph (vertices are the cells in your grid, and edges are possible moves from one cell to the other)
The simplest approach is a simple BFS - that finds the shortest
path from a source to all targets (in unweighted graphs).
This algorithm is fairly simple and is iteratively "discovering" the closest nodes, all nodes of distance 1, then of distance 2, ....
An optimization is using a bi-directional search. Here you can take advantage of having single source and single target by doing BFS from both sides, effectively reducing the number of nodes you need to develop dratically.
One more optimization could be to use A* Search Algorithm with
an admissible heuristic function, such as manhattan distances.
In A* Search, you take advantage that the graph is not some arbitrary graph - but a grid, and you can estimate distance from one node to the other, based on their locations on the grid. The algorithm will uses these estimations to find the optimal path quicker.
Note - all algorithms I suggested find the shortest path, difference is in the time it will take them to find it.
Can DP algorithm for Matrix Chain Multiplication be modeled as shortest path in DAG? I read somewhere that every DP problem is a walk on an implicit DAG but I am unable to visualize those problems in which a transition leads to more than one state ( or sub-state ).
One more example where I fail to visulize the same is UVA 10003. A DP solution of the above is discussed here: Cutting a stick such that cost is minimized.
Imagine that there is a directed edge between two states if we can go from the first state to the second one(of course, a state can consist of several parameters). There are no cycles in this graph, so it is DAG. So visualizing a DAG itself is not hard(you can just write down all states and edges between them). But is not necessary can modeled as a shortest path search. For example, in a problem about cutting a rope the value for a state is a sum of values for two other states, so it is not even a path. Anyway, it might impractical to visualize a solution if the number of parameters is very big. And there is no need to do any visualization to solve a problem and prove the correctness of your solution.
I am trying to do c++ program.I am trying to do problem in which i have numbers of points. Now i need to find the path that goes through all the points. This is not actually TSP because as per my knowledge in TSP it is possible to travel from all points to every other points. But in my case the path network between the points is fixed and i just need to find the suitable path that goes through all the points provided that all points may not have connection to every other point..so what algorithm am i supposed to follow.
It seems you are looking for a way to traverse a graph? If so have you tried Breadth first search http://en.wikipedia.org/wiki/Breadth-first_search or Depth first search http://en.wikipedia.org/wiki/Depth-first_search to traverse your graph.
You want to find a Hamiltonian path for a graph.
In the mathematical field of graph theory, a Hamiltonian path (or
traceable path) is a path in an undirected graph that visits each
vertex exactly once. A Hamiltonian cycle (or Hamiltonian circuit) is a
Hamiltonian path that is a cycle. Determining whether such paths and
cycles exist in graphs is the Hamiltonian path problem, which is
NP-complete.
Some techniques that exist :
There are n! different sequences of vertices that might be Hamiltonian
paths in a given n-vertex graph (and are, in a complete graph), so a
brute force search algorithm that tests all possible sequences would
be very slow. There are several faster approaches. A search procedure
by Frank Rubin divides the edges of the graph into three classes:
those that must be in the path, those that cannot be in the path, and
undecided. As the search proceeds, a set of decision rules classifies
the undecided edges, and determines whether to halt or continue the
search. The algorithm divides the graph into components that can be
solved separately. Also, a dynamic programming algorithm of Bellman,
Held, and Karp can be used to solve the problem in time O(n2 2n). In
this method, one determines, for each set S of vertices and each
vertex v in S, whether there is a path that covers exactly the
vertices in S and ends at v. For each choice of S and v, a path exists
for (S,v) if and only if v has a neighbor w such that a path exists
for (S − v,w), which can be looked up from already-computed
information in the dynamic program.
Andreas Björklund provided an alternative approach using the
inclusion–exclusion principle to reduce the problem of counting the
number of Hamiltonian cycles to a simpler counting problem, of
counting cycle covers, which can be solved by computing certain matrix
determinants. Using this method, he showed how to solve the
Hamiltonian cycle problem in arbitrary n-vertex graphs by a Monte
Carlo algorithm in time O(1.657n); for bipartite graphs this algorithm
can be further improved to time O(1.414n).
For graphs of maximum degree three, a careful backtracking search can
find a Hamiltonian cycle (if one exists) in time O(1.251n).