Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

A linkage problem

asked 6 years ago

guillermo gravatar image

updated 6 years ago

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 2k1-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 s1,...,sk,t1,...,tk of G. Pair these 2k vertices arbitrarily into k pairs (si,ti). The pair (si,ti) means that the vertex si has been paired with the vertex ti. This pairing doesn't altered the graph G in any way. The problem consists of finding k pairwise vertex-disjoint paths between si and ti 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 s1=(1,1,1), t1=(1,1,1), s2=(1,1,1) and t2=(1,1,1). Pair the vertices as (si,ti). Then we cannot find 2 vertex-disjoint paths, one connecting s1 to t1 and another s2 to t2. However, if I choose X to be s1=(1,1,1), t1=(1,1,1) and s2=(1,1,1) and t2=(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

Preview: (hide)

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 (si,ti) for i? 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 ( 6 years ago )

Hi Dan,

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

Regards, Guillermo

guillermo gravatar imageguillermo ( 6 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 6 years ago

Sébastien gravatar image

updated 6 years ago

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.

Preview: (hide)
link

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 ( 6 years ago )

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 ( 6 years ago )

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: 6 years ago

Seen: 817 times

Last updated: May 23 '18