Find the second maximum weighed matching in a complete bipartite graph - algorithm

Given a weighed complete bipartite graph G=(V, U, E), the maximum weighted bipartite matching problem, i.e., the assignment problem, aims to find a matching in G where the sum of edge weights is maximized. I know there are some methods (e.g., Hungarian algorithm) can solve this problem. Now, I want to solve a slightly different problem:
Given a weighed complete bipartite graph G=(V, U, E), I would like to find the maximum weighted bipartite matching and the second maximum weighted bipartite matching in G at the same time. Any ideas would be much appreciated.

There is a general algorithm called Lawler-Murty which allows you to find the top K answers to combinatorial algorithms (including matching) in successive calls. It is described at https://core.ac.uk/download/pdf/82129717.pdf in the context of matching.
Basically, after finding the best answer, you add constraints to the problem which create a number of sub-problems such that the answers found so far are ruled out, but all other answers will still turn up as the answer to one of the sub-problems. The second best answer will turn up as the best answer to one of the sub-problems. When you do this repeatedly you end up with a large tree of sub-problems to solve. For matching problems, you can reduce the time take to solve a sub-problem by making use of some of the work from previous problems.

Related

Minimum number of non-intersecting simple cycles in unweighted directed graph

I decided to try implement some assignment problem algorithms. I already did some, but I got stuck on the problem described below:
To put it simply, I need to cover all its vertices with the minimum number of non-intersecting simple cycles.
But I don't understand how, does anyone have any ideas? I would be especially glad to see an explanation.
This problem is NP-hard via a reduction from the Hamiltonian cycle problem. More specifically, if a graph has a Hamiltonian cycle, then you can cover all the vertices with a single simple cycle, namely the Hamiltonian cycle, and otherwise the graph requires multiple cycles to cover its nodes (if it can even be done at all).
As a result, unless P = NP, there are no polynomial-time algorithms for this problem. You can still solve it using either heuristic searches or brute force, but those approaches won’t necessarily be fast on all inputs.

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.

Is there an efficient algorithm to find the number of k-length paths (NOT walks) in an undirected and unweighted graph in adjacency matrix form?

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.

Minimal cost cyclic path in a graph - A variant of TSP

For example, we have a graph consisting of vertices (cities) and edges (roads) and each edge(road) has a particular cost, find the minimal cost to visit all cities ATLEAST ONCE. Cost is the sum of the edge costs of the edges traversed.
The part "ATLEAST ONCE" caught me. In a TSP we can visit a node only once according to Wiki. Consider the graph,
A-B 11
A-C 5
B-C 2
B-E 4
C-E 3
C-D 20
D-E 100
In a TSP, The cyclic path would be A-B-E-D-C-A cost- 140 (or) A-C-D-E-B-A cost- 140. Where as from my problem description we can visit each vertex ATLEAST ONCE so we can have a cyclic path A-C-D-C-E-B-A cost- 63 which is << a TSP. This is where I had a problem. Any specific algorithm here? I'm pretty sure TSP wont work well here.
Pointers or pseudo code will be very helpful.
For each pair of nodes, you can apply the shortest path algorithm and calculate the shortest distance. This will be the new cost matrix for each pair.
Now it is reduced to Travelling Salesman Problem.
Then you can apply TSP solving technique.
Given that you are allowing a vertex to be visited multiple times, this effectively turns your incomplete graph into a complete graph (all vertices connected), which is what TSP requires. Solving your problem in the general case is exactly the same as solving the metric TSP. The good news is that this is a heavily researched topic. The bad news is that you aren't able to sidestep the TSP - since your problem is identical to a form of the TSP.
As pointed out by others, you complete the graph by computing the shortest cost between each pair of vertices and adding those edges where missing. You also need to replace any existing direct edge for which you've found a lower indirect path cost so that you have a Metric TSP. You can store with the new synthetic edges their actual paths (through intermediate vertices) so you can recover those for your final answer, or you can recompute those paths as needed upon receiving the result of the TSP.
Now you can solve this as a TSP. However, solving TSP optimally is too expensive in the general case, so you'll likely want to use an approximate solution algorithm. A variety of these (e.g. Christofides algorithm, Lin–Kernighan heuristic) are available which make differing tradeoffs between guaranteed levels of optimality and performance of the algorithm.
If you actually don't care about completing the cycle, and just want a minimum path that visits all vertices, starting and ending at any vertex, this is a somewhat different problem. For this, read my answer here: https://stackoverflow.com/a/33601043/5237297

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

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.

Resources