Undirected weighted graph in polytime - algorithm

I'm attending a master course in Algorithm for Bioinformatics, and I'm trying to solve some exercise in order to pass the exam. I'm stuck in this problem and I don't understand in which way I have to solve it. Could you help?
Thanks the next few lines are the exercise:
Argue whether you believe that the following problem has a polynomial time algorithm
Input: A complete undirected graph G with non-negative weights on the edges, and a weight bound W.
Solution: A simple path with the maximum possible number of vertices among all paths in G of weight < W.

This is NP-Hard, and thus there is no known polynomial solution to it.
It is easy to reduce this problem from the Hamiltonian Path problem1.
Given a graph G=(V, E), create:
G' = (V, E', w)
Where:
E' = VxV (all edges)
w(u,v) = 1 if (u,v) is in E
2 otherwise
Now, G' has a valid solution with |V| maximal weight if and only if G is hamiltonian.
(->) If 'G' is hamiltonian, then there is a path v1->v2->...->vn. Weights of all these edges is 1, so total weight in G' is |V|-1, making it maximal and valid.
(<-) If there is a path in G' with value<|V|, and we know it is maximal - so if it goes through all vertices - it cannot have edges with w(u,v)=2 (otherwise it will exceed the maximal weight). Then, this path is hamiltonian in G.
(1) A hamiltonian path is a simple path that goes through all vertices in the graph. If a graph has such a path, we call it a hamiltonian graph. The Hamiltonian Path Problem is finding if a graph is hamiltonian or not.

Related

Show np-completeness of Disjoint Hamiltonian Path

Consider the problem of Disjoint Hamiltonian Path:
Input: A graph which may be directed or undirected
Output: Does this graph exist at least 2 Hamiltonian Paths that are edge-disjoint?
Edge-disjoint means that no single edge is shared by two paths.
Show that Disjoint Hamiltonian Path is np-complete.
I have been told that this problem is np-complete, but I couldn't prove it is np-hard. I tried reducing the original Hamiltonian Path and Hamiltonian Cycle to this problem but I couldn't think of a solution.
I came up with the following reduction, not sure if it's the simplest but it is simple.
Suppose G is an undirected graph corresponding to an instance of HP.
Now construct a new graph G' in the following way:
Keep every vertex from G.
For every edge (u,v) in G, create 4 additional vertices and connect them in the following way :
Now it is easy to see that if G has a Hamiltonian path, G' will have two edge-disjoint Hamiltonian paths, because every edge was replaced by some subgraph which itself has two edge-disjoint Hamiltonian paths (go straight or take the curvy edges). And if G' has a HP, then so does G because once you enter the subgraph corresponding to one of the original edges you have no choice but to get out of it on the other end, which corresponds to taking the original edge in G. The only "problem" that could occur is if the path were to start or end inside one of these subgraphs, but then we can just ignore the small part of the path which is inside and still get a HP for G.
And notice that G' has a HP => G has a HP => G' has two edge-disjoint HPs. Thus, G has a HP <=> G' has two edge-disjoint HPs.
The transformation can obviously be done in poly-time, thus your problem is NP-Hard.
The directed case is similar, just direct the edges in the transformed graph accordingly.

Shortest path to visit all nodes in a complete directed graph

Note: This is almost the same questions as this: Shortest path to visit all nodes
But I have a complete graph.
Problem: Consider a complete undirected graph with nonnegative edge lengths. Question: Compute the shortest path that visits every node at least once.
NB: This is NOT the TSP problem. The path does not have an ending node and the path can pass through nodes more than once.
Other notes:
The number of nodes is small (less than 20).
Problem is still NP-Complete (for decision variant), with reduction from Hamiltonian Path Problem.
Given Hamiltonian Path Problem instance G=(V,E), reduce it to your problem with: G'=(V, E', w) and path length |V| - 1.
Where:
E' = VxV
w(u,v) = 1 if (u,v) is in E
w(u,v) = 2 otherwise
If there is a hamiltonian path in G, then there is a path in G' that costs |V| - 1.
If there is a path in G' that costs |V| - 1, then by following these edges in G, we get a Hamiltonian Paht.
Thus, the above is a polynomial reduction from Hamiltonian Path Problem to this TSP variant, and since Hamiltonian Path Problem is NP-Hard, so is this problem.
Claim
Allowing nodes to be revisited does not make the problem substantially easier.
Explanation
Suppose we wish to find a Hamiltonian path in a graph G. We can turn this into an instance of your problem by setting the edge weights to 1 for edges in G, and edge weights to 10 for edges not in G.
We now have a complete graph H with non-negative edges.
Graph G has a Hamiltonian path if and only if we find the shortest path in H is of length n-1.
Recommendation
Therefore your modified problem is NP-hard, so it seems unlikely that you can do better than simply adapting standard TSP techniques (such as the Held-Karp algorithm ) to solve it.

Minimal spanning tree with degree constraint

I have to solve this problem:
Given a weighted connected undirected graph G=(V,E) and vertex u in V.
Describe an algorithm that finds MST for G such that the degree of u
is minimal; the output T of the algorithm is MST and for each another
minimal spanning tree T' being the degree of u in T less than or
equal to the degree of u in T'.
I thought about this algorithm (after some googling I found this solution for similar problem here):
Temporarily delete vertex u.
For each of the resulting connected components C1,…,Cm find a MST using e.g. Kruskal's or Prim's algorithm.
Re-add vertex u and for each Ci add the cheapest edge between 1 and Ci.
EDIT:
I understood that this algorithm may get a wrong MST (see #AndyG comment) so I thought about another one:
let k be the minimal increment between each two weights in G and add 0 < x < k to each adjacent edge of u. (e.g. if all the weights are natural numbers so k=1 and x is fraction).
find a MST using Kruskal's algorithm.
This solution is based on the fact that Kruskal's algorithm iterate the edges
ordered by weigh, so the difference between all the MSTs of G is each edge was chosen from among all edges of the same weight. Therefore, if we increase the degree of the adjacent edges of u, the algorithm will choose the others edges in the same degree and not the adjacent of u unless this edge is necessary for the MST and the degree of u will be the minimal in all the MSTs of G.
I still don't know if it works and how to prove the correctness of this algorithm.
I will appreciate any help.
To summarize the suggested algorithm [with tightened requirements on epsilon (which you called x)]:
Pick a tiny epsilon (such that epsilon * deg(u) is less than d, the smallest non-zero weight difference between any pair of subgraphs). In the case all the original weights are natural numbers, epsilon = 1/(deg(u)+1) suffices.
Add the epsilon to the weights of all edges incident to u
Find a minimal spanning tree.
We'll prove that this procedure finds an MST of the original graph that minimizes the number of edges incident to u.
Let W be the weight of any minimal spanning tree in the original graph.
First, we'll show every MST of the new graph is an MST of the original graph. Any non-MST in the original graph must have weight at least W + d. Any MST in the new graph must have weight at most W + deg(u)*epsilon (since any MST in the original graph has at most this weight in the new graph). Since we chose epsilon such that deg(u)*epsilon < d, we conclude that any MST in the new graph is also an MST in the original graph.
Second, we'll show that the MST of the new graph is the MST of the original graph that minimizes the number of edges incident to u. An MST, T, of the original graph has weight W + k * epsilon in the new graph, where k is the number of edges of T incident to u. We've already shown that every MST of the new graph is also an MST of the original graph. Therefore, the MST of the new graph is the MST of the original graph that minimizes k (the number of edges incident to u).

Shortest path visiting all nodes without going back to start

Let's say that we have an arbitrary set of nodes and we want the shortest path between the nodes AND we have to visit all the nodes in the graph. It's sort of Travelling Salesman Problem but without going back to the start node again. Assume that we can start from any arbitrary node and end at any arbitrary node (except the starting node), but we have to visit all the nodes in the graph. Is the complexity the same as the Travelling Salesman Problem i.e NP-hard? Is there any known algorithm to solves this problem?
This is still TSP, and is NP-Hard. The algorithms that work on TSP will work on this one as well. Note that the fact that you "do not care" what is the starting node is insignificant, because by trying all possibilities, you multiply the complexity by n.
The reduction from Hamiltonian Path Problem to this problem is fairly trivial:
Given a graph G=(V,E), create a new weighted graph with G'=(V,E',w), where:
E' = V x V (all edges are there)
w(u,v) = 1 if (u,v) is in E
w(u,v) = 2 else
Now, the original graph G has a Hamiltonian Path if and only if shortest path that goes through all vertices is of length |V|.

Directed maximum weighted bipartite matching allowing sharing of start/end vertices

Let G (U u V, E) be a weighted directed bipartite graph (i.e. U and V are the two sets of nodes of the bipartite graph and E contains directed weighted edges from U to V or from V to U). Here is an example:
In this case:
U = {A,B,C}
V = {D,E,F}
E = {(A->E,7), (B->D,1), (C->E,3), (F->A,9)}
Definition: DirectionalMatching (I made up this term just to make things clearer): set of directed edges that may share the start or end vertices. That is, if U->V and U'->V' both belong to a DirectionalMatching then V /= U' and V' /= U but it may be that U = U' or V = V'.
My question: How to efficiently find a DirectionalMatching, as defined above, for a bipartite directional weighted graph which maximizes the sum of the weights of its edges?
By efficiently, I mean polynomial complexity or faster, I already know how to implement a naive brute force approach.
In the example above the maximum weighted DirectionalMatching is: {F->A,C->E,B->D}, with a value of 13.
Formally demonstrating the equivalence of this problem to any other well known problem in graph theory would also be valuable.
Thanks!
Note 1: This question is based on Maximum weighted bipartite matching _with_ directed edges but with the extra relaxation that it is allowed for edges in the matching to share the origin or destination. Since that relaxation makes a big difference, I created an independent question.
Note 2: This is a maximum weight matching. Cardinality (how many edges are present) and the number of vertices covered by the matching is irrelevant for a correct result. Only the maximum weight matters.
Note 2: During my research to solve the problem I found this paper, I think it would be helpful to others trying to find a solution: Alternating cycles and paths in edge-coloured
multigraphs: a survey
Note 3: In case it helps, you can also think of the graph as its equivalent 2-edge coloured undirected bipartite multigraph. The problem formulation would then turn into: Find the set of edges without colour-alternating paths or cycles which has maximum weight sum.
Note 4: I suspect that the problem might be NP-hard, but I am not that experienced with reductions so I haven't managed to prove it yet.
Yet another example:
Imagine you had
4 vertices: {u1, u2} {v1, v2}
4 edges: {u1->v1, u1->v2, u2->v1, v2->u2}
Then, regardless of their weights, u1->v2 and v2->u2 cannot be in the same DirectionalMatching, neither can v2->u2 and u2->v1. However u1->v1 and u1->v2 can, and so can u1->v1 and u2->v1.
Define a new undirected graph G' from G as follows.
G' has a node (A, B) with weight w for each directed edge (A, B) with weight w in G
G' has undirected edge ((A, B),(B, C)) if (A, B) and (B, C) are both directed edges in G
http://en.wikipedia.org/wiki/Line_graph#Line_digraphs
Now find a maximal (weighted) independent vertex set in G'.
http://en.wikipedia.org/wiki/Vertex_independent_set
Edit: stuff after this point only works if all of the edge weights are the same - when the edge weights have different values its a more difficult problem (google "maximum weight independent vertex set" for possible algorithms)
Typically this would be an NP-hard problem. However, G' is a bipartite graph -- it contains only even cycles. Finding the maximal (weighted) independent vertex set in a bipartite graph is not NP-hard.
The algorithm you will run on G' is as follows.
Find the connected components of G', say H_1, H_2, ..., H_k
For each H_i do a 2-coloring (say red and blue) of the nodes. The cookbook approach here is to do a depth-first search on H_i alternating colors. A simple approach would be to color each vertex in H_i based on whether the corresponding edge in G goes from U to V (red) or from V to U (blue).
The two options for which nodes to select from H_i are either all the red nodes or all the blue nodes. Choose the colored node set with higher weight. For example, the red node set has weight equal to H_i.nodes.where(node => node.color == red).sum(node => node.w). Call the higher-weight node set N_i.
Your maximal weighted independent vertex set is now union(N_1, N_2, ..., N_k).
Since each vertex in G' corresponds to one of the directed edges in G, you have your maximal DirectionalMatching.
This problem can be solved in polynomial time using the Hungarian Algorithm. The "proof" by Vor above is wrong.
The method of structuring the problem for the above example is as follows:
D E F
A # 7 9
B 1 # #
C # 3 #
where "#" means negative infinity. You then resolve the matrix using the Hungarian algorithm to determine the maximum matching. You can multiply the numbers by -1 if you want to find a minimum matching.

Resources