Vertex tour in a weighted undirected graph with the maximum cost? - algorithm

What are the efficient algorithms for finding a vertex tour in a weighted undirected graph with maximum cost if we need to start from a particular vertex?

It's NPC because if you set weights as 1 for all edges, if HC exists it will be your answer, and so In all you can find HC existence from a single source which is NPC by solving this problem so your problem is NPC, but there are some polynomial approximation algorithms.

Since the problem is NP-hard, you are very unlikely to find an efficient algorithm that solves the problem exactly for all possible weighted input graphs.
However, there might be efficient algorithms that are guaranteed to find an answer that is at most a constant times away from the best possible answer, e.g. there might be an efficient algorithm that is guaranteed to find a path that has weight at least 1/2 of the maximum weight path.
If you are interested in searching for such algorithms, you could try Google searches for "weighted hamiltonian path approximation algorithm", which is close to, but not identical to, your problem. It is not the same because Hamiltonian paths are required to include all vertexes. Here is one research paper that might either contain, or have ideas that lead to, an approximation algorithm for your problem:
http://portal.acm.org/citation.cfm?id=139404.139468
"A general approximation technique for constrained forest problems" by Michel X. Goemans and David P. Williams.
Of course, if your graphs are small enough that you can enumerate all possible paths containing your desired vertex "fast enough for your purposes", then you can solve it exactly.

Related

Shortest path in a directed, weighted graph with set number of weights

Lets say there is a graph (V,E) that is directed and weighted.
The weights of every edge in the graph are 1 or 2 or 3.
What would be a quick and efficient algo to find the shortest path? Thanks in advance!!
Dijkstra's algorithm would likely still have near-optimal performance, and has the advantage of being fairly simple.
However, for a graph with small integer weights, you can use more complicated versions of the (fibonacci) heap used in Dijkstra that have better asymptotic performance. Specifically, consider this work by Mikkel Thorup which solves single-source shortest path in O(|E| + |V| log log |C|) where E is the set of edges, V is the set of vertices and C is the largest weight. In your case C is constant, which turns the asymptotic complexity into O(|E| + |V|).
Do note that this is mostly of theoretical interest, and is unlikely to give any significant speedup over a simpler algorithm.
There a list of algorithms for the Shortest path problem:
Dijkstra's algorithm
A* search algorithm
...etc
you can find a list in this Wikipedia page about Shortest path problem Algorithms
you can test and play with this online Dijkstra Shortest Path visualization.
a very interesting Pathfinding-Visualizer to see how some algorithms explore the research space to reach the goal is in github Pathfinding-Visualizer , this will give you a general idea on th differences between algorithms visually. Note: Pathfinding doesn't mean the shortest path; it's depend on the used algorithm.

Is there an efficient algorithm for finding or approximating the shortest walk of a graph which must visit some subset of vertices of the graph?

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.

Hamiltonian paths & social graph algorithm

I have a random undirected social graph.
I want to find a Hamiltonian path if possible. Or if not possible (or not possible to know if possible in polynomial time) a series of paths. In this "series of paths" (where all N nodes are used exactly once), I want to minimize the number of paths and maximize the average length of the paths. (So no trivial solution of N paths of a single node).
I have generated an adjacency matrix for the nodes and edges already.
Any suggestions? Pointers in the right direction? I realize this will require heuristics because of the NP-complete (?) nature of the problem, and I am OK with a "good enough" answer. Also I would like to do this in Java.
Thanks!
If I'm interpreting your question correctly, what you're asking for is still NP-hard, since the best solution to the "multiple paths" problem would be a Hamiltonian path, and determining whether one exists is known to be NP-hard. Moreover, even if you're guaranteed that a Hamiltonian path doesn't exist, solving this problem could still be NP-hard, since I could give you a graph with a single disconnected node floating in space, for which the best solution is a trivial path containing that node and a Hamiltonian path in the remaining graph. As a result, unless P = NP, there isn't going to be a polynomial-time algorithm for your problem.
Hope this helps, and sorry for the negative result!
Angluin and Valiant gave a near linear-time heuristic that works almost always in a sufficiently dense Erdos-Renyi random graph. It's described by Wilf, on page 121. Probably your random graph is not Erdos-Renyi, but the heuristic might work anyway (when it "fails", it still gives you a (hopefully) long path; greedily take this path and run A-V again).
Use a genetic algorithm (without crossover), where each individual is a permutation of the nodes. This gives you "series of paths" at each generation, evolving to a minimal number of paths (1) and a maximal avg. length (N).
As you have realized there is no exact solution in polynomial time. You can try some random search methods though. My recommendation, start with genetic algorithm and try out tabu search.

Is finding a simple path in a weighted undirected graph with maximum cost in polynomial time? Is it NP?

I need to know if it is possible to find a simple path with maximum cost in any weighted undirected graph.
I mean to find THE MOST expensive path of all for any pair of vertex.
Input: Graph G = (V,E)
Output: The cost of the most expensive path in the graph G.
Is this problem NP-Complete?, I think it is. Could you provide any reference to an article where I can review this.
You're not the first to think of this problem. In fact, it was the first link in the google search results.
edit
Guys, un-weighted graph is a special case of weighted graph: all edges have weight 1 :)
This is similar to traveling salesman, except your heuristic is the Max and not Min. Read up on the traveling salesman.
The problem is NP complete because it can be derived from a problem that is already proven to be NP-Complete (Traveling salesman). The answer is checkable in polynomial time, but an answer cannot be found in polynomial time.
Read http://en.wikipedia.org/wiki/Travelling_salesman_problem
Yes, this problem is NP because you are asking for the maximum which means that you'll need to go through all possible paths. The decision version of this problem ("is there a path of length n?") is known NP-complete (as noted above).

Algorithm: shortest path between all points

Suppose I have 10 points. I know the distance between each point.
I need to find the shortest possible route passing through all points.
I have tried a couple of algorithms (Dijkstra, Floyd Warshall,...) and they all give me the shortest path between start and end, but they don't make a route with all points on it.
Permutations work fine, but they are too resource-expensive.
What algorithms can you advise me to look into for this problem? Or is there a documented way to do this with the above-mentioned algorithms?
Have a look at travelling salesman problem.
You may want to look into some of the heuristic solutions. They may not be able to give you 100% exact results, but often they can come up with good enough solutions (2 to 3 % away from optimal solutions) in a reasonable amount of time.
This is obviously Travelling Salesman problem. Specifically for N=10, you can either try the O(N!) naive algorithm, or using Dynamic Programming, you can reduce this to O(n^2 2^n), by trading space.
Beyond that, since this is an NP-hard problem, you can only hope for an approximation or heuristic, given the usual caveats.
As others have mentioned, this is an instance of the TSP. I think Concord, developed at Georgia Tech is the current state-of-the-art solver. It can handle upwards of 10,000 points within a few seconds. It also has an API that's easy to work with.
I think this is what you're looking for, actually:
Floyd Warshall
In computer science, the Floyd–Warshall algorithm (sometimes known as
the WFI Algorithm[clarification needed], Roy–Floyd algorithm or just
Floyd's algorithm) is a graph analysis algorithm for finding shortest
paths in a weighted graph (with positive or negative edge weights). A
single execution of the algorithm will find the lengths (summed
weights) of the shortest paths between all pairs of vertices though it
does not return details of the paths themselves
In the "Path reconstruction" subsection it explains the data structure you'll need to store the "paths" (actually you just store the next node to go to and then trivially reconstruct whichever path is required as needed).

Resources