Is it possible to make (Weighted)AdjacencyMatrix from a graph whose elements have custom properties?

Consider this graph:

g = Graph[{
      Property[DirectedEdge[0, 1], {"WaterFlow" -> x, "PipeWidth" -> 10.0}],
      Property[DirectedEdge[1, 2], {"WaterFlow" -> x + y, "PipeWidth" -> 8.5}],
      Property[DirectedEdge[2, 1], {"WaterFlow" -> y, "PipeWidth" -> 8.5}],
      Property[DirectedEdge[2, 3], {"WaterFlow" -> x, "PipeWidth" -> 10.0}]

enter image description here

How do I make one WeightedAdjacencyMatrix weighted by "WaterFlow" and another one weighted by "PipeWidth"?

For example, the one for "WaterFlow" would be:

enter image description here


1 Answer 1


You could specify custom properties to set edge weights using undocumented option EdgeWeight:

WeightedAdjacencyMatrix[g, EdgeWeight -> "WaterFlow"] // MatrixForm

"WaterFlow" edge weight

WeightedAdjacencyMatrix[g, EdgeWeight -> "PipeWidth"] // MatrixForm

"PipeWidth" edge weight

Since this option is not documented, its behavior could be changed later though.


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.