Message Boards Message Boards

0
|
3384 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

How can I extract individual graph partitions as graphs?

Posted 10 years ago

After having applied the function FindGraphPartition to an arbitary graph with weighted vertices, how can I go about making graphs of the partitions?

e.g. If I cut the original graph into two parts, then how can I make two graphs (with properties preserved)?

POSTED BY: Shawn Doyle
3 Replies
Posted 10 years ago

Play the movie backwards?

In[1]:= g1 = Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1, 2 \[UndirectedEdge] 4, 4 \[UndirectedEdge] 5, 5 \UndirectedEdge] 6, 6 \[UndirectedEdge] 4}, VertexWeight -> {5, 7, 7, 2, 1, 5}];
p = FindGraphPartition[g1];
g4 = VertexDelete[g1, First[p]];
g5 = VertexDelete[g1, Last[p]];
FullForm[g4]

Out[5]//FullForm=Graph[{4 \[UndirectedEdge] 5, 5 \UndirectedEdge] 6, 6 \[UndirectedEdge] 4}, VertexWeight -> {2, 1, 5}];
POSTED BY: Bill Simpson
Posted 10 years ago

Thank you for the reply! The code doesn't preserve vertex weights if you add them. The following will give unweighted subgraphs:

g1 = Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1, 2 \[UndirectedEdge] 4,  4 \[UndirectedEdge] 5, 5 \[UndirectedEdge] 6,  6 \[UndirectedEdge] 4}, VertexWeight -> {5, 7, 7, 2, 1, 5}];
p = FindGraphPartition[g1];
g2 = Subgraph[g1, First[p]]; g3 = Subgraph[g1, Last[p]];

I will continue toying with this. I thought that this link would solve the problem, but that is not the case here. Thanks again!

POSTED BY: Shawn Doyle
Posted 10 years ago

Can you adapt this? And does it preserve all your properties?

In[1]:= g1 = Graph[{1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 1,
   2 \[UndirectedEdge] 4, 4 \[UndirectedEdge] 5, 5 \[UndirectedEdge] 6, 6 \[UndirectedEdge] 4}];
p = FindGraphPartition[g]

Out[2]= {{4, 5, 6}, {1, 2, 3}}

In[3]:= g2 = Subgraph[g1, First[p]]; g3 = Subgraph[g1, Last[p]];
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract