# Build Table of Edge Weight Sums

Is there a convenient way to build a table as generated by the code below where a 5th column (at the far right) could be added to the table that is the sum of the edge weights for the nodes in a given row. Then also be able to sort that table from smallest edge weight sum to largest edge weight sum?

Clear[edges,g]
edges = {N1 -> N2, N1 -> N3, N1 -> N4,
N2 -> N5, N3 -> N5, N3 -> N6,
N4 -> N6, N5 -> N7, N6 -> N7};

g = Graph[
edges,
VertexLabels -> "Name",
EdgeWeight -> {1, 2, 3, 4, 5, 6, 7, 8, 9},
EdgeLabels -> {"EdgeWeight"},
EdgeLabelStyle -> Directive[Red, 20]
]

TableForm[FindPath[g, N1, N7, Infinity, All]]


I'm looking for the sum of the edge weights of each row in the above table. For example, the last row would be generated as N1 N2 N5 N7 13, where 13 is the sum of the edge weights 1 (N1 -> N2) + 4 (N2 -> N5) + 8 (N5 -> N7) = 13. So, 13 would be the 5th column computed for each row in the above table generated by the last line of code in the above.

• I'm looking for the sum of the edge weights of each row in the above table. For example, the last row would be generated as N1 N2 N5 N7 13, where 13 is the sum of the edge weights 1 (N1->N2) + 4 (N2->N5) + 8 (N5->N7) = 13. So, 13 would be the 5th column computed for each row in the above table generated by the last line of code in the above. Jan 13, 2021 at 1:17
• You comment should be part of the question. Jan 13, 2021 at 2:11

paths = FindPath[g, N1, N7, Infinity, All];

totalweights = Total[PropertyValue[{g, DirectedEdge @@ #}, EdgeWeight] & /@
Partition[#, 2, 1]] & /@ paths;

Join[paths, List /@ totalweights, 2] // MatrixForm


• kglr ... I wrote the above clarification Jan 13, 2021 at 1:19
• @PRG, please see the update.
– kglr
Jan 13, 2021 at 2:33
• kglr ... superbly done ... thank u very much! ... prg Jan 13, 2021 at 3:19