2

Compare following two low-level box representations of a graph without VertexLabels and one with VertexLabels set to "Name" with ToBoxes[]:

ToBoxes[Graph[{1 <-> 2}]]

ToBoxes[Graph[{1 <-> 2}, VertexLabels -> "Name"]]

(Alternatively, select visual representation and press Cmd+Shift+E on mac.)

The first one uses GraphicsComplex for an efficient representation of the graph and the second does not.

enter image description here

Is there a conceptual or technical reason for this?

I came across this trying to use this answer for a graph with VertexLabels enabled where GraphicsComplexBox[x_, y_, z___] does not match anything anymore.

Mathematica version: 11.2

Hotschke
  • 707
  • 3
  • 11
  • 1
    Well, I made the experience that everything involving PropertyValues for Graphs is handled quite differently than without (and often in an inconsistent way but that's another story). This is maybe because there can be so many exceptions... And using VertexLabels also implies that your graph is not overly large so that the profit from GraphicsComplex is marginal, right? Maybe that was the thinking behind this design decision... – Henrik Schumacher Apr 13 '18 at 17:34
  • Thanks for your thoughts. I guess you are right that you only place labels when you have a graph not with thousands of vertices. Do you know if there is a way to use Normal[] or another function to get an identical representation for both? – Hotschke Apr 13 '18 at 17:44
  • Hm. AdjacencyGraph@AdjacencyMatrix should get rid of all PropertyValues. Plotting it leads to a GraphicsComplex, but the vertex lables, vertex coordinates, etc. are gone. Is that what you need? – Henrik Schumacher Apr 13 '18 at 18:37
  • You can also use H = Graph[VertexList[G], EdgeList[G]]. Depending on the internal representation of the graph (sparse or not), the one or the other may be faster. – Henrik Schumacher Apr 13 '18 at 18:42
  • Sorry, I guess I was not clear. I meant the same low-level box representation. I did not mean to strip of all PropertyValues. I want to adjust the function displayWeightedMultiGraph shown in the mentioned answer to handle both situations. – Hotschke Apr 13 '18 at 18:50
  • Okay, is this an XY problem? What is it what you really want? Have you also seen Carl's great answer? Look, this works: Block[{Identity}, Graph[{1 \[DirectedEdge] 1, 1 \[DirectedEdge] 1, 1 \[DirectedEdge] 1}, EdgeWeight -> Identity /@ {{1, 0}, {0, 1}, {1, 1}}, VertexLabels -> "Name", EdgeLabels -> "EdgeWeight" ] ]. – Henrik Schumacher Apr 13 '18 at 19:50
  • Sorry that the other issue contains actually two problems. One is solved by Carl (and has therefore the green mark) and is used in the answer by kglr answering the problem of visualization. So no, it is not an xy problem. I have already tried to ask kglr to help me out, but he didn't respond so I try it myself in steps. Writing a complex rule for a graph using GraphicsComplex and one without is not what I would ideally want to do . – Hotschke Apr 13 '18 at 19:59
  • Once again: Why do you want to write "a complex rule for a graph using GraphicsComplex"? Have you noticed the use of EdgeLabels -> "EdgeWeight", which resolves the display issue? – Henrik Schumacher Apr 13 '18 at 20:06
  • 1
    I guess you are not aware of the problems of mixed (directed and undirected edges) multi-graphs pointed out by Szabolc. I try to resolve it manually. But it is very hard to do. I am little bit disappointed with Mathematica. Also Normal[Graph] does not work. The documentation sounds promising but again does not work here because the undocumented GraphicsComplexBox is used. – Hotschke Apr 13 '18 at 20:06
  • Thanks for your interest! But I feel like we cannot resolve it together. At least not today :). Do not invest too much time in this! – Hotschke Apr 13 '18 at 20:08

0 Answers0