Closed alexpghayes closed 11 months ago
Further investigation reveals topo_sort()
does what I need. It also unfortunately reveals that my data is not actually a tree, but I'd like to treat nodes that connect to each other in both directions as the same (in other words, I'd like to treat cycles, which are small, as collapsed to a single node). Does this exist?
Not yet but I'll look into it — it is related to other morphemes I have in mind
and a node can only connect to older nodes. So my graph is a tree.
This does not mean that the graph is a tree. It means that you have a directed acyclic graph (DAG).
get a partial ordering on the nodes
Indeed topo_sort()
does that.
Depth of node in tree
But this is not the same as the depth of a node in a tree. That would be the distance from the root, which you can compute by walking backwars from the node until you hit the root. This will only work on an actual tree, not a DAG.
If you want to go along your last idea you can try using the to_contracted
morpher
Closing as solved for now
I have nodes that correspond to time ordered events. I don't know the exact times, but the edges are directed, and a node can only connect to older nodes. So my graph is a tree. Is there any easy way to get a partial ordering on the nodes?
I've been playing with the
seriation
package to order the adjacency matrix but wonder if there's an easier way?