Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I need to find the total weight of an WeightedAdjacencyGraph. I have a graph in that form

a = WeightedAdjacencyGraph[{...},{...},{...}....etc]

How can I find its total weight?

share|improve this question
add comment

2 Answers

You could just do this: if a graph is undirected:

Total[UpperTriangularize[WeightedAdjacencyMatrix[g]], 2]

if a graph is directed:

Total[WeightedAdjacencyMatrix[g], 2]

or by PropertyValue

Total[PropertyValue[g, EdgeWeight]]
share|improve this answer
    
Don't forget the self loops! –  Szabolcs Oct 12 '13 at 19:23
    
@Szabolcs thanks, I missed that. –  halmir Oct 13 '13 at 4:39
add comment

This should deal with undirected, directed and graphs with loops (non-infinite non-zero diagonal elements):

totalweight=Total@(PropertyValue[{g, #}, EdgeWeight] & /@ EdgeList[g])

where g is graph of interest

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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