I have a very long list of element, say $a1,a2, a3$,..., and they are all connected in that each is the child of many parents. E.g. $a74$ is associated with $a2,a55,a71$, and also contains information, like 'the name of $a74$ is bob. It's an upwards tree if you want, with the $a$'s as vertices.
Now I wonder what the most efficient way to store this information in Mathematica is, given that I might have to run exhaustive computation along that graph. I'll mainly call the list of $a$-symbols to use them to climb further and I want to compute statistics about the graph itself. Sometimes I'll need the names of the vertices or other information.
My naive ideas are to make all symbols a list
a74={{a2,a55,a71},"bob"};
and then $a74[[1]]$ is the partent list and so on.
Or maybe I could define fictions $n\rightarrow \text{list}$ and store the information in them, like
parent[a5]={a1,a4};
parent[a74]={a2,a55,a71};
and
name[a5]="mila";
name[a74]="bob";
Or a mix, depending on what I call more often?
Or are there structures, which simplify or automatize these kind of things?
I don't know yet how computationally difficult it's going to be, so the practical point might also be considered. In any case, I'd like to hear what seems to be not the way to do it.
What is the right way to do this and/or are there other options?
At the moment I'd just generate the lists as in the first example. In actuality, I will write the list in a text-file and only later read in the information to a Mathematica file.
Graph
with each node being a list. 2. Use aGraph
with each node being an integer index into a list of information associated with each node. 3. Use the properties framework ofGraph
(seeSetProperty
, etc.) I'd try 3. first because it's a built-in way, but I've never seriously used it, so I can't comment on potential problems. My main worry would be that these properties don't go that well with functional programming. $\endgroup$Graph
-s here are at all questionable IMO. $\endgroup$