# How to work with structured data using graphs

Given that the functions for not only creating but also modifying Graph are functional programming creating copies it seems to me that it is a good idea to keep the vertices small, such as sticking to just natural numbering (makes reading the matrix representations simple as well).

However a lot of real problems need to "store" structured data with the graph. Not having found any real world complicated example including editing the graph and not just creating once and applying a few built in functions to it this is what I thought might make sense:

aG = Graph[{ (* [course of] action graph *)
0 \[DirectedEdge] 1,
0 \[DirectedEdge] 2
}
, VertexLabels -> vertexRenderFunction["Name"]];
aGD = Association[ (* action graph data *)
0 -> {"now"},
1 -> {"left", 12, "blue", 4, 8, 0, 0, 0, 1, 0, 0, 1, 1, 0, {}, {}},
2 -> {"right", 12, "red", 2, 3, 0, 0, 0, 1, 0, 0, 0, 0, 1, {}, {}}
];
vertexRenderFunction[v_] := Lookup[aGD, v][[1]];

1. Is such a separation concept a good idea at all?
2. Is an Association the way to go?
3. How do I use the real vertex name as the Key for Lookup at the Association?
• I think it's a good idea and I'm investigating in the same direction. If the graph is large you could use a database also. Entity framework might be a very handy framework also. Perhaps you could expand your question to get a small example.
– Lou
Oct 19 '21 at 5:42
• @Lou I will, but to make a useful (instructive) one I need to know the 3rd part — how to use a function I provide with the vertices' name to label the vertices in the graph displayed. Being flexible with that (multiple functions or a flexible function) is one part that seems to be critical to the whole idea. Oct 19 '21 at 9:38
• checkout VertexShapeFunction. That function gives you the edge as parameter and then you can do whatever you want. There are many examples with this function on SE
– Lou
Oct 19 '21 at 20:12
• @Lou Well, that would work, but I would have to create a Graphics object, most likely recreating a circle for the vertex shape for which is intended, placing the (likely textual) representation of the vertex' associated data from the Association somewhere to it (partially replicating function other options to the Graph already manipulate) and putting both into the Graphics object in order to become a valid output for a function provided to VertexShapeFunction. Pretty sure that is not where I should go to. Think I need the same thing for VertexLabels like VertexLabels -> vlf. Oct 21 '21 at 20:25