Ask Your Question
1

A linkage problem

asked 2018-05-22 06:44:14 -0500

guillermo gravatar image

updated 2018-05-22 19:50:28 -0500

Hi there,

I wonder how I can use Sage to solve the following problem, without implementing a full-blown backtracking.

Let $G$ be an undirected simple graph with at least $2k$ vertices. The graph $G$ would need to be $2k-1$-vertex-connected for the problem to hope to have a solution, but this is perhaps beside the point. Let $X$ be a set of $2k$ distinct vertices $s_1,...,s_k,t_1,...,t_k$ of G. Pair these $2k$ vertices arbitrarily into k pairs $(s_i,t_i)$. The pair $(s_i,t_i)$ means that the vertex $s_i$ has been paired with the vertex $t_i$. This pairing doesn't altered the graph $G$ in any way. The problem consists of finding k pairwise vertex-disjoint paths between $s_i$ and $t_i$ for each i, or returns that it is not possible to do so.

A graph for which you can find the $k$ vertex-disjoint paths for any possible set $X$ is called $k$-linked.

Let me give you an example. Suppose I take the 3-cube graph. I am gonna see it as a graph of the polytope 3-cube because the image is better.

P3=polytopes.hypercube(3)

Q3=P3.graph()

Q3.show()

Let me choose 4 vertices arbitrary vertices for my set $X$, say $s_1=(1,1,1)$, $t_1=(-1,-1,1)$, $s_2=(1,-1,1)$ and $t_2=(-1,1,1)$. Pair the vertices as $(s_i,t_i)$. Then we cannot find 2 vertex-disjoint paths, one connecting $s_1$ to $t_1$ and another $s_2$ to $t_2$. However, if I choose $X$ to be $s_1=(1,1,1)$, $t_1=(-1,-1,1)$ and $s_2=(-1,-1,-1)$ and $t_2=(1,1,-1)$ we can.

As an aside this shows that the 3-CubeGraph is not 2-linked.

Hope this is a bit clearer now.

Thank you in advance, and regards, Guillermo

edit retag flag offensive close merge delete

Comments

Please give the code for an explicit graph $G$. Also, form the context it is hard to understand what is given, and what should be found. (The index $i$ is used for the "pairs". What are the edges of $G$? Are the $(s_i,t_i)$ for $i\in ?$ all edges of $G$. An example, with the expected solution to be found, possibly one among many, would be helpful.)

To start with, consider in the sage interpreter

sage: ?Graph

to see how to initialize a graph.

dan_fulea gravatar imagedan_fulea ( 2018-05-22 13:37:34 -0500 )edit

Hi Dan,

Thank you for your comment. I have explained the problem a bit more.

Regards, Guillermo

guillermo gravatar imageguillermo ( 2018-05-22 19:22:11 -0500 )edit

1 answer

Sort by » oldest newest most voted
1

answered 2018-05-22 16:28:46 -0500

Sébastien gravatar image

updated 2018-05-23 03:46:05 -0500

You may use the dancing links solver in Sage to do this:

sage: G = graphs.CompleteGraph(6)
sage: G.vertices()
[0, 1, 2, 3, 4, 5]
sage: rows = [[a,b] for (a,b,label) in G.edges()]
sage: dlx = dlx_solver(rows)
sage: indices = dlx.one_solution()
sage: indices
[2, 5, 14]
sage: [rows[i] for i in indices]
[[0, 3], [1, 2], [4, 5]]

or just search for a matching:

sage: G.matching()
[(0, 5, None), (1, 4, None), (2, 3, None)]

... if I understand your question correctly.

EDIT:

Okay, I see now that you updated the question. I think you want to use the method disjoint_routed_paths :

sage: G = polytopes.hypercube(3).graph()
sage: edges = [(tuple(u.vector()), tuple(v.vector())) for (u,v,label) in G.edges()]
sage: G = Graph(edges, format='list_of_edges')
sage: s1=(1,1,1); t1=(-1,-1,1); s2=(1,-1,1); t2=(-1,1,1)
sage: pairs = [(s1,t1), (s2,t2)]
sage: G.disjoint_routed_paths(pairs)
Traceback (most recent call last):
...
EmptySetError: The disjoint routed paths do not exist.

and here it works:

sage: pairs = [((1,1,1), (-1,-1,1)), ((-1,-1,-1), (1,1,-1))]
sage: paths = G.disjoint_routed_paths(pairs)
sage: paths
[Subgraph of (): Graph on 3 vertices, Subgraph of (): Graph on 3 vertices]
sage: paths[0].edges()
[((-1, -1, 1), (1, -1, 1), 1), ((1, -1, 1), (1, 1, 1), 1)]
sage: paths[1].edges()
[((-1, -1, -1), (-1, 1, -1), 1), ((-1, 1, -1), (1, 1, -1), 1)]

So you want to write a function like this maybe :

sage: def is_k_linked(G, k):
....:     V = G.vertices()
....:     for S in Subsets(range(len(V)), 2*k):
....:         for R in Subsets(S, k):
....:             L = S.difference(R)
....:             pairs = [(V[a],V[b]) for (a,b) in zip(L,R)]
....:             try:
....:                 G.disjoint_routed_paths(pairs)
....:             except EmptySetError:
....:                 return False
....:     return True
....: 
sage: is_k_linked(G,2) # something is wrong in my code, as it should return False
True

I do not have time now to debug this further now.

edit flag offensive delete link more

Comments

HI Sebastien,

Thank you for your code. I fail to understand how this solve the linkage problem. I have explained the problem a bit more.

Regards, Guillermo

guillermo gravatar imageguillermo ( 2018-05-22 19:21:42 -0500 )edit

Thank you very much Sebastien. The method disjoint_routed_paths was what I was after.

I believe the problem with your code is that, once you have the k-sets L and R, you need to permute one of them, say L, to consider all the possible pairings for these two sets.

Regards, Guillermo

guillermo gravatar imageguillermo ( 2018-05-23 19:05:53 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-05-22 06:44:14 -0500

Seen: 50 times

Last updated: May 23