sdoyle
(Shawn Doyle)
1
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)?
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]];
sdoyle
(Shawn Doyle)
3
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!
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}];