Thank you Vitaliy! This works for EdgeLabels
. The problem seems to be specific to EdgeWeight
, EdgeCost
and EdgeCapacity
.
I have the impression that there are at least three types of graph properties:
- those that show up as a separate option in
Options[g]
with a list value
- those that show up as a separate option in
Options[g]
with a rule-list value
- those that show up in
Properties
in Options[g]
The problem seems to affect only category 1.
I tried to explore these here, but I did not get any feedback, so I am not certain that my hypothesis about them is correct (there are exceptions, e.g. VertexCoordiates
seems to have its own special behaviour).
There are more differences between these than how they are stored. Some quirks and bugs (like this property removal problem) affect only some of them.
- Category 1 works with multigraphs, the rest doesn't (but instead of giving errors, they tend to misbehave).
- Category 1 has a default value, and all items (all edges or all vertices) must have a value assigned.
- Category 2 allows assigning values to only some of them.
- Category 2 seems to be accessible at the graph level, i.e.
PropertyValue[g, prop]
instead of PropertyValue[{g, 1<->2}, prop]
. Category 3 isn't.
- Category 2 properties seem to always be present in a sense, even if it doesn't show up in
Options[g]
. They are always listed in PropertyList[g]
.
- There seems to be no easy way to query which category 3 properties a graph has (unless it's a graph-level property). They would need to be queries separately for each edge/vertex.
- Both category 2 and category 3 properties are settable as
SetProperty[g, Properties -> {UndirectedEdge[1,2] -> {prop -> value}}]
. Category 1 isn't. However, category 1 is also settable as SetProperty[g, prop -> ruleList]
, not only as SetProperty[g, prop -> valueList]
.
As you can see, it's pretty complicated.
Note: Since EdgeLabels
wants a rule list, your example should be:
g = RandomGraph[{10, 20}];
g2 = SetProperty[g,
EdgeLabels -> Thread[EdgeList[g] -> RandomReal[1, 20]]]
Otherwise all but the first value in RandomReal[1,20]
will be ignored (and this happens completely silently, which is a bit confusing).
But PropertyValue[g2, EdgeLabels] =.
works fine for EdgeLabels
(as you say), and so does RemoveProperty[g2, EdgeLabels]
. The former is imperative and changes the graph, the latter is functional, and returns a new graph.