Apologies for what seems like a silly question. I'm sure I am missing something obvious, but this is driving me a bit crazy.
Does EdgeWeight work differently in Directed vs. Undirected graphs?
If I have a weighted undirected graph, I can assign and then extract the list of edge weights, or individual weights, as follows:
G = Graph[{1 <-> 2, 2 <-> 3, 1 <-> 3, 2 <-> 4, 3 <-> 4},
EdgeWeight -> {1, 2, 3, 4, 5}];
PropertyValue[G, EdgeWeight]
PropertyValue[{G, 2 <-> 3}, EdgeWeight]
And I get the expected output
{1, 2, 3, 4, 5}
2
However, if I try the same with a directed graph:
H = DirectedGraph[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 2},
EdgeWeight -> {6, 7, 8, 9}];
PropertyValue[H, EdgeWeight]
PropertyValue[{H, 1 -> 2}, EdgeWeight]
I get the following nonsense
Automatic
$Failed
As I said, I'm sure I'm doing something stupid, but I'm not sure what. Can anyone help?
\[DirectedEdge]
instead of->
? $\endgroup$DirectedGraph
. UseGraph
.Graph
is a constructor for the graph data structure, either directed or undirected.DirectedGraph
converts undirected graphs to directed ones, an entirely different use. IMO there's no bug here, just a misuse ofDirectedGraph
. $\endgroup$DirectedGraph
discarded all properties (including edge weights) up to M11.3. Since M12.0, many graph functions, includingDirectedGraph
, preserve properties. Why this major wasn't documented by Wolfram is beyond me ... $\endgroup$