3
$\begingroup$

According to the docs this should work but for some reason does not:

g = CompleteGraph[3];
Annotate[{g, 3}, "a" -> 17];
AnnotationValue[{g, 3}, "a"]

It returns $Failed, both on desktop and in the cloud. On the other hand, if one uses

AnnotationValue[{g, 3}, "a"] = 17

the annotation does works. A glitch in paradise?

$\endgroup$
1
$\begingroup$

This is not a bug.

Annotate does not modify the graph. Instead, it returns a new graph. It is like Append and not like AppendTo.

g = CompleteGraph[3];
g2 = Annotate[{g, 3}, "a" -> 17];
AnnotationValue[{g2, 3}, "a"]
$\endgroup$
3
  • $\begingroup$ Ah! Each and every (incremental) annotation creates a new graph. Not what 'annotation' typically means and a waste of memory as well, but what can one do. $\endgroup$ – Francois Vanderseypen Apr 1 '20 at 9:31
  • $\begingroup$ @FrancoisVanderseypen "but what can one do" One of two things: (1) your approach with AnnotationValue[...] = ... (2) Set multiple properties at the same time. E.g., do not set it vertex by vertex. Set it at once for all vertices. Both will improve performance significantly. $\endgroup$ – Szabolcs Apr 1 '20 at 11:10
  • 1
    $\begingroup$ @FrancoisVanderseypen Also, do check out my IGraph/M package which makes some operations on properties easier, and carefully avoids badly performing constructs (when possible). szhorvat.net/mathematica/IGDocumentation/… $\endgroup$ – Szabolcs Apr 1 '20 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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