Ask Your Question
2

Code to find separating set in SageMath of a given Graph

asked 2019-08-04 14:52:38 +0200

Captcha gravatar image

updated 2022-03-04 16:56:12 +0200

slelievre gravatar image

Given a Graph $G$ how can I find the separating set of the Graph?

Suppose I am given this graph

G = Graph({1: [2, 3, 4, 5],
           2: [1, 3, 4, 5],
           3: [1, 2, 4, 5],
           4: [1, 2, 3],
           5: [1, 2, 3]})

I want to find the set of vertices whose removal disconnects the graph.

I found that the vertex connectivity of $G$ is 2.

Looking at the graph, the smallest set of vertices whose removal disconnects the graph is $(1, 2, 3)$.

But how to find it using a code in SageMath?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2019-08-04 17:27:23 +0200

dazedANDconfused gravatar image

Try this code:

from sage.graphs.connectivity import vertex_connectivity
G=Graph({1:[2,3,4,5],2:[1,3,4,5],3:[1,2,4,5],4:[1,2,3],5:[1,2,3]})
vertex_connectivity(G,value_only=False)

The result, running in a SageCell Server is

(3, [1, 2, 3])

Which says the vertex connectivity is 3 and the vertices 1,2,3 are such a set.

The documentation for vertex_connectivity() is here.

edit flag offensive delete link more

Comments

Thanks a lot sir. Can you kindly tell if there is any code which can find all the minimal separating sets of a given graph? How to write such a code

Captcha gravatar imageCaptcha ( 2019-08-05 07:53:28 +0200 )edit

I don't see anything in the documentation that would provide all minimal separating sets of a graph. Given that circulants would have a lot of vertex separating sets, I don't see any way around brute force checking whether the removal of k vertices (where k is the vertex connectivity) over all subsets of k vertices results in a disconnected graph. If so add to the list.

dazedANDconfused gravatar imagedazedANDconfused ( 2019-08-05 16:52:55 +0200 )edit

Okay Thank you so much

Captcha gravatar imageCaptcha ( 2019-08-06 03:53:23 +0200 )edit
3

answered 2022-03-04 04:25:19 +0200

licheng gravatar image

updated 2022-03-04 16:53:20 +0200

slelievre gravatar image

The networkx package can be used to find all minimum separating sets.

sage: import networkx as nx
sage: G = Graph({1: [2, 3, 4, 5],
....:            2: [1, 3, 4, 5],
....:            3: [1, 2, 4, 5],
....:            4: [1, 2, 3],
....:            5: [1, 2, 3]})
sage: G1 = G.networkx_graph()  
sage: cutsets = list(nx.all_node_cuts(G1))
sage: cutsets
[{1, 2, 3}]

So G has only one minimum separated set.

See the documentation:

edit flag offensive delete link more

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: 2019-08-04 14:52:38 +0200

Seen: 887 times

Last updated: Mar 04 '22