1
$\begingroup$

Consider a weighted graph:

g=Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1, 2 <-> 4, 4 <-> 5, 5 <-> 6, 6 <-> 4},EdgeWeight -> {0, 3, 4, 0, 4, 6, 9}, EdgeLabels -> "EdgeWeight", VertexShapeFunction -> "Name"];

g1 = FindGraphPartition[g]
g2 = HighlightGraph[g, Map[Subgraph[g, #] &, g1]]

How to determine data for red/yellow weighted graph. Example of Answers:

g3={{1 <-> 2, 0}, {2 <-> 3, 3}, {3 <-> 1, 4}}

I need to do this for large graphs Thanks

$\endgroup$

1 Answer 1

3
$\begingroup$

In Mathematica 12.0 and later, you can use

PropertyValue[
 Subgraph[g, g1[[2]]],
 EdgeWeight
]

In earlier versions, use IGWeightedSubgraph from IGraph/M instead of Subgraph, as Subgraph would discard weights.

With IGraph/M, you can also use IGEdgeProp[EdgeWeight][graph] to extract edge weights.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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