Find a vertex disjoint path from source to destination - algorithm

Is there a deterministic algorithm to check if a graph contains a vertex-disjoint path from a source to destination, with complexity O(nm^2) (n is number of vertices, m is number of edges) or is this NP-Hard (if so, why)? Vertex disjoint path means a path with no common internal vertex. eg.
s -> a -> b -> c -> d
s -> x -> y -> z -> d
Are vertex disjoint but
s -> a -> b -> c -> d
s -> x -> a -> z -> d
^
Are not since a is common vertex.
The full question is:

The problem (asked in the question, find "ONE" vertex disjoint path between s and t which is different from the picture of the question posted) is not NP-hard and can be solved in polynomial time O(V^2E). Moreover, the question of is there are k disjoint paths between s and t is also not NP-Complete.
The article which was referred above to prove NP-completeness (http://www.shannarasite.org/kb/kbse48.html) has a subtle difference....there you do not know s and t, thus the problem becomes hard. But, once you fix s and t, it is polynomial.
Here is the algorithm to find a vertex disjoint path in polynomial time ---
Convert this problem to a maximum flow problem and use Dinic's algorithm to solve it in O(V^2E)
http://en.wikipedia.org/wiki/Dinitz_blocking_flow_algorithm
This is the conversion:
Pick the source s and destination t vertices between which you want to find the disjoint path.
For each vertex v add two new vertices to G' (the graph we are constructing) , i.e. for each v \in G add v_1 and v_2 to G'.
For each edge (a,b) add the following edges (a_1, a_2), (b_1, b_2), (a_2, b_1) and (b_2, a_1) (remember that the vertices have already been transformed, and note the direction of the edges).
Add S and T to G' and edges (S,s_1), and (t_2, T).
Assign weight of 1 to all the edges and run the max-flow algorithm (between S and T). If you get a max-flow of 1, then that flow (or path) corresponds to the vertex disjoint path in your original graph.
Now to kind k disjoint paths :
Assign weight of k for edges (S,s_1), (t_2, T) , (s1_, s_2), and (t_1, t_2).....and weight 1 for the remaining edges...run the Dinic's algo again, and if there is max flow of capacity k, that gives you the disjoint paths.

The problem is NP-Hard. This may be proven by reduction from 3-SAT. Here is sketch of a proof.
Assign 'n' source/destination pairs (for each variable). Connect each pair with two paths, each having 'm' internal nodes (for 'm' clauses). One path is for the case when variable is 'true', other one - 'false'.
Also assign 'm' source/destination pairs (for each clause). Connect each pair with 3 paths, each path - through corresponding internal node of "variable" paths, choosing 'true' or 'false' paths if this variable is negated or not in the clause.
Then find 'm+n' vertex-disjoint paths to solve 3-SAT.

Related

Given a weighted graph and natural number k how to find the cheapest path from node s to t that can be divided by k?

Given a weighted graph G=(V,E) which doesnt include negative cycles, a natural number k, and two verticles: s,t.
How can I find the cheapest route from s to t which its length can be divied by k?
Prepare a new graph G' with vertices V × {0, 1, …, n−1} and for each arc v → w of length ℓ in G, arcs (v, x) → (w, (x + ℓ) mod k). Then use Dijkstra's algorithm to find a shortest path from (s, 0) to (t, 0).
Use BFS with a priority queue, so as to always examine states (= paths from s) that are shortest. Unlike normal Dijkstra, your states are full paths, and you can revisit already-visited vertices as often as they are encountered.
I cannot prove that such an algorithm would be optimal, but at least it should be correct, always returning a valid shortest-path answer if it exists. Runtime for certain graphs and values of K would be very high, and the algorithm may not finish at all if there are no k-divisible paths from s to t but there are loops with a path-length divisible by k. You could find and filter those out first by using a preliminary DFS.

Implementation of multiple sink shortest pair of disjoint paths problem for multigraphs

I would like to implement the shortest pairs of edge-disjoint paths of Suurballe and Tarjan for multigraphs in the interpretation of Banerjee et al. (http://web.cs.iastate.edu/~pavan/papers/short.pdf, relying only on Section 3).
As regards simple graphs, this algorithm can be defined for a G=(V,E) simple graph having a source s and nonnegative edge costs c(u,v) as follows:
(1) Construct the shortest path tree T rooted at s for G using the Dijkstra algorithm.
(2) Reduce the cost on all edges (a,b) as c'(a,b)=c(a,b)+d(a)-d(b), where d(a) is the distance of vertex a from vertex s.
(3) Create an auxiliary graph G'=(V',E') in the following way:
(3.1) set V'=V and E' = empty,
(3.2) for each nontree edge (a,b) of E\T:
(3.2.1) define V * as the set of nodes in the path between a and b in T except for b,
(3.2.2) for each v' of V *: set E'=E' U {(v',b)} and c'(v',b)=c'(a,b).
(4) Construct a shortest path tree T' rooted at s for G' weighted by the c' function, using the Dijkstra algorithm.
(5) Save the predecessor of each vertex x in T' as q(x) and the tail of the nontree edge in G which caused the insertion of the (q(x),x) in G'.
(6) Create the pairs of edge-disjoint paths for each v of V in the following manner:
(6.1) Mark all the vertices in the shortest path from v to s in G.
(6.2) Generate the paths by two iterations of the step Traversal given below. In each iteration one path of the shortest pairs is generated.
Traversal: Define x=v, the path to be empty and repeat the following steps until x=s. If x is marked then unmark it and add (p(x),x) to the path, or else add (y,x) to the path, where y is the parent of x in T.
Could you please help me how to reformulate the algorithm for multigraphs? I guess that G', p(), q(), and Traversal of Section 3 in paper of Banerjee et al. should be modified somehow, but I don't know how.

How to find maximal subgraph of bipartite graph with valence constraint?

I have a bipartite graph. I'll refer to red-nodes and black-nodes of the respective disjoint sets.
I would like to know how to find a connected induced subgraph that maximizes the number of red-nodes while ensuring that all black nodes in the subgraph have new valences less than or equal to 2. Where "induced" means that if two nodes are connected in the original graph and both exist in the subgraph then the edge between them is automatically included. Eventually I'd like to introduce non-negative edge-weights.
Can this be reduced to a standard graph algorithm? Hopefully one with known complexity and simple implementation.
It's clearly possible to grow a subgraph greedily. But is this best?
I'm sure that this problem belongs to NP-complete class, so there is no easy way to solve it. I would suggest you using constraint satisfaction approach. There are quite a few ways to formulate your problem, for example mixed-integer programming, MaxSAT or even pseudo-boolean constraints.
For the first try, I would recommend MiniZinc solver. For example, consider this example of defining and solving graph problems in MiniZinc.
Unfortunately this is NP-hard, so there are probably no polynomial-time algorithms to solve it. Here is a reduction from the NP-hard problem Independent Set, where we are given a graph G = (V, E) (with n = |V| and m = |E|) and an integer k, and the task is to determine whether it is possible to find a set of k or more vertices such that no two vertices in the set are linked by an edge:
For every vertex v_i in G, create a red vertex r_i in H.
For every edge (v_i, v_j) in G, create the following in H:
a black vertex b_ij,
n+1 red vertices t_ijk (1 <= k <= n+1),
n black vertices u_ijk (1 <= k <= n),
n edges (t_ijk, u_ijk) (1 <= k <= n)
n edges (t_ijk, u_ij{k-1}) (2 <= k <= n+1)
the three edges (r_i, b_ij), (r_j, b_ij), and (t_ij1, b_ij).
For every pair of vertices v_i, v_j, create the following:
a black vertex c_ij,
the two edges (r_i, c_ij) and (r_j, c_ij).
Set the threshold to m(n+1)+k.
Call the set of all r_i R, the set of all b_ij B, the set of all c_ij C, the set of all t_ij T, and the set of all u_ij U.
The general idea here is that we force each black vertex b_ij to choose at most 1 of the 2 red vertices r_i and r_j that correspond to the endpoints of the edge (i, j) in G. We do this by giving each of these b_ij vertices 3 outgoing edges, of which one (the one to t_ij1) is a "must-have" -- that is, any solution in which a t_ij1 vertex is not selected can be improved by selecting it, as well as the n other red vertices it connects to (via a "wiggling path" that alternates between vertices in t_ijk and vertices in u_ijk), getting rid of either r_i or r_j to restore the property that no black vertex has 3 or more neighbours in the solution if necessary, and then finally restoring connectedness by choosing vertices from C as necessary. (The c_ij vertices are "connectors": they exist only to ensure that whatever subset of R we include can be made into a single connected component.)
Suppose first that there is an IS of size k in G. We will show that there is a connected induced subgraph X with at least m(n+1)+k red nodes in H, in which every black vertex has at most 2 neighbours in X.
First, include in X the k vertices from R that correspond to the vertices in the IS (such a set must exist by assumption). Because these vertices form an IS, no vertex in B is adjacent to more than 1 of them, so for each vertex b_ij, we may safely add it, and the "wiggling path" of 2n+1 vertices beginning at t_ij1, into X as well. Each of these wiggling paths contains n+1 red vertices, and there are m such paths (one for each edge in G), so there are now m(n+1)+k red vertices in X. Finally, to ensure that X is connected, add to it every vertex c_ij such that r_i and r_j are both in X already: notice that this does not change the total number of red vertices in X.
Now suppose that there is a connected induced subgraph X with at least m(n+1)+k red nodes in H, in which every black vertex has at most 2 neighbours in X. We will show that there is an IS in G of size k.
The only red vertices in H are those in R and those in T. There are only n vertices in R, so if X does not contain all m wiggly paths, it must have at most (m-1)(n+1)+n = m(n+1)-1 red vertices, contradicting the assumption that it has at least m(n+1)+k red vertices. Thus X must contain all m wiggly paths. This leaves k other red vertices in X, which must be from R. No two of these vertices can be adjacent to the same vertex in B, since that B-vertex would then be adjacent to 3 vertices: thus, these k vertices correspond to an IS in G.
Since a YES-instance of IS implies a YES-instance to the constructed instance of your problem and vice versa, the solution to the constructed instance of your problem corresponds exactly to the solution to the IS instance; and since the construction is clearly polynomial-time, this establishes that your problem is NP-hard.

Find two paths in a graph that are in distance of at least D(constant)

Instance of the problem:
Undirected and unweighted graph G=(V,E).
two source nodes a and b, two destination nodes c and d and a constant D(complete positive number).(we can assume that lambda(c,d),lambda(a,b)>D, when lambda(x,y) is the shortest path between x and y in G).
we have two peoples standing on the nodes a and b.
Definition:scheduler set-
A scheduler set is a set of orders such that in each step only one of the peoples make a move from his node v to one of v neighbors, when the starting position of them is in the nodes a,b and the ending position is in the nodes c,d.A "scheduler set" is missing-disorders if in each step the distance between the two peoples is > D.
I need to find an algorithm that decides whether there is a "missing-disorders scheduler set" or not.
any suggestions?
One simple solution would be to first solve all-pairs shortest paths using n breadth-first searches from every node in O(n * (n + m)).
Then create the graph of valid node pairs (x,y) with lambda(x, y) > D, with edges indicating the possible moves. There is an edge {(v,w), (x,y)} if v = x and there is an edge {w, y} in the original graph or if w = y and there is an edge {v, x} in the original graph. This new graph has O(n^2) nodes and O(nm) edges.
Now you just need to check whether (c, d) is reachable from (a, b) in the new graph. This can be achieved using DFS or BFS.
The total runtime be O(n * (n + m)).

Shortest two disjoint paths; two sources and two destinations

We're given an unweighted undirected graph G = (V, E) where |V| <= 40,000 and |E| <= 106. We're also given four vertices a, b, a', b'. Is there a way to find two node-disjoint paths a -> a' and b -> b' such that the sum of their lengths is minimum?My first thought was to first find the shortest path a -> a', delete it from the graph, and then find the shortest path b -> b'. I don't think this greedy approach would work.
Note: Throughout the application, a and b are fixed, while a' and b' change at each query, so a solution that uses precomputing in order to provide efficient querying would be preferable. Note also that only the minimum sum of lengths is needed, not the actual paths.
Any help, ideas, or suggestions would be extremely appreciated. Thanks a lot in advance!
This may be reduced to the shortest edge-disjoint paths problem:
(Optionally) Collapse all chains in the graph into single edges. This produces a smaller weighted graph (if there are any chains in the original graph).
Transform undirected graph into digraph by substituting each edge by a pair of directed edges.
Split each node into the pair of nodes: one with only incoming edges of the original node, other with only its outgoing edges. Connect each pair of nodes with a single directed edge. (For example, node c in the diagram below should be split into c1 and c2; now every path containing node c in the original graph should pass through the edge c1 -> c2 in the transformed graph; here x and y represent all nodes in the graph except node c).
Now if a = b or a' = b', you get exactly the same problem as in your previous question (which is Minimum-cost flow problem and may be solved by assigning flow capacity for each edge equal to 1, then searching for a minimum-cost flow between a and b with flow=2). If a != b, you just create a common source node and connect both a and b to it. If a' != b', do the same with a common destination node.
But if a != b and a' != b', minimum-cost flow problem is not applicable. Instead this problem may be solved as Multi-commodity flow problem.
My previous (incorrect) solution was to connect both pairs of (a, b) and (a', b') to common source/destination nodes, then to find a minimum-cost flow. Following graph is a counter-example for this approach:
How about this? Do BFS (breadth first search) traversal from a1 -> a2 and remove the path and compute BFS b1 -> b2. Now reset the graph and do same with b1->b2 first and remove path and then a1->a2.
Whatever sum is minumum is the answer.

Resources