3

The documentation for VertexWeight clearly states:

The weight wi can be any expression.

But I cannot seem to set list-valued vertex weights in my graph:

Graph[
    {"A", "B", "C"},
    Map[Apply[UndirectedEdge], {{"A", "B"}, {"A", "C"}}],
    VertexWeight -> {1, 2, 3}
] // GraphQ
(* True *)

Graph[ {"A", "B", "C"}, Map[Apply[UndirectedEdge], {{"A", "B"}, {"A", "C"}}], VertexWeight -> {{1, 2}, {2, 3}, {3, 4}} ] // GraphQ (* False *)

Is this a bug, or do I have a syntax error somewhere? (I am using Mathematica 13.0 on Windows 11 Pro.)

Shredderroy
  • 5,249
  • 17
  • 26
  • 3
    This does go against the documentation so it is worth reporting to WRI, but also you should find a workaround. Is there a reason you are storing the lists as weights rather than some other property? You could store them as a custom property with something like g = Graph[{"A", "B", "C"}, {"A" <-> "B", "A" <-> "C"}, AnnotationRules -> {"A" -> {"vertwt" -> {1, 2}}, "B" -> {"vertwt" -> {3, 4}}, "C" -> {"vertwt" -> {4, 5}}}] and access them via something like AnnotationValue[{g, "A"}, "vertwt"] – Jason B. Jan 10 '22 at 18:59
  • @JasonB. thanks for the confirmation. I will report this as a bug to WRI. Yes, I can certainly use the workaround mentioned in your comment. (As to the reason: I am designing a custom graph neural network to operate on the molecular library with which you are already so intimately familiar.) – Shredderroy Jan 10 '22 at 19:09
  • 1
    @Shredderroy you could store integer edge weights in the graph and then use them as keys into an Association which contains the lists / matrices etc. – flinty Jan 10 '22 at 20:30
  • 1
    VertexWeight is special, and seems to be optimized for storing numerical values. It can be accessed much faster than other properties. Unfortunately, these quirks of the property system are not documented. https://mathematica.stackexchange.com/q/118196/12 – Szabolcs Jan 11 '22 at 14:16

0 Answers0