5
$\begingroup$

Consider the following:

g = RandomGraph[WattsStrogatzGraphDistribution[1000, 0.1, 5]]
comm = FindGraphPartition[g, 2];
CommunityGraphPlot[g, comm]

FindGraphPartition[g,2] will find a partition of vertices such that the number of edges having endpoints in different parts is minimized. How can I get Mathematica to tell me the number of edges that connect these two groups? It seems like something I should be able to get at easily, but looking through the documentation I just can't find anything.

Thank you!

$\endgroup$
5
$\begingroup$

If you just need the number of edges, you can use

EdgeCount[g, UndirectedEdge[Alternatives @@ comm[[1]], Alternatives @@ comm[[2]]]]
 376

If you need the list of edges:

el = EdgeList[g, UndirectedEdge[Alternatives @@ comm[[1]], Alternatives @@ comm[[2]]]]

Length @ el
376
Short[el, 5]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.