Question

Set A has n devices. Set B has m devices. Some devices in A are compatible with the devices in B, and some devices in B are compatible with those in A.

I want as many compatible devices connected to each other as possible. (It's not necessary to have the device a in A and b in B to be mutually compatible.)

Edit for clarity: any device can be linked to 0, 1 or 2 other devices, but not itself.

Eventually all devices (or all but two, if the "ends" don't meet) should be linked together 1 on 1. It's possible to link any one device to any other device. But no device in A are compatible with any device in A (but they are linkable), and the same holds true for devices in B.

If I have A = {a1,a2,a3}, B = {b1,b2,b3} and n=m=3

a1 is compatible with b1,b2
a2 is compatible with b1
a3 is compatible with b1
b1 is compatible with a1,a3
b2 is compatible with a1
b3 is compatible with a1

Then the graph G

a1 <-> b2 <-> a2 <-> b1 <-> a3 <-> b3 <-> a1

is an optimal graph.

G doesn't have to be cyclic, but it can be.

Are there any clever ways to approach this?

Was it helpful?

Solution

I believe that this problem is NP-hard by a reduction from undirected longest path problem, which is known to be NP-hard by a reduction from the undirected Hamiltonian path problem (see Sipser's Introduction to the Theory of Computation for details on why).

In the undirected longest path problem, we are given as input an undirected graph G = (V, E), along with a pair of nodes u and v and some number k, and want to determine whether or not there is a simple (no node appears twice) path from u to v of length at least k. We can convert this into your problem using a polynomial-time reduction as follows:

  • For each node vi ∈ V, there is a device in A (call it di).
  • For each edge {vi, vj} ∈ V, there is a device in B (call it ei, j).
  • For each node vi and edge {vi, vj}, device di is compatible with device ei, j.

This reduction has polynomial size, since the total number of devices generated is of size |V| + |E| and the number of connections is 2|E|. Moreover, we can see that there is a path of length k from vi to vj in graph G iff there is a chain of devices of length 2k + 1 from di to dj. Specifically, if ((vi1, vi2), (vi2, vi3), ..., (vik - 1, vik)) is a simple path from vi to vj, then the chain di1 → ei1, i2 → di2 → ei2, i3 → di3 → ... → eik - 1, ik → dik and vice-versa. We thus have a polynomial-time reduction from undirected longest path to you problem as follows:

  • Given as input (G, vi, vj, k) to the undirected longest path problem:
    • Construct the sets A and B as above, with compatibilities C as above.
    • Check whether there is a chain of devices of length 2k + 1 from di to dj.
    • If so, output "yes"
    • If not, output "no."

This reduction solves the undirected longest path problem in nondeterministic polynomial time using a solver for your problem, and so your problem is NP-hard. As a result, you should not expect to find a polynomial-time algorithm for your problem; finding an exact answer is likely to take exponential time unless P = NP.

Sorry to give a negative answer, but I hope this helps!

OTHER TIPS

This is np-hard but I think a maximal cycle cover problem approximations can help you(in each group link devices with edge of size 0), Also you can add some extra node which connected to all other nodes by weight 0), for example this paper: Approximating Maximum Weight Cycle Covers in Directed Graphs with Weights Zero and One will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top