Open alberdingk-thijm opened 4 years ago
Some thoughts on how we can potentially do this:
Vertex.t
One natural way to allow node aliases to work would be to change the underlying type of vertices to be some other value, e.g. a string. Code that currently assumes nodes are integers between 0 and n (like the SMT encoding) would then be change to iterate over the vertices of the graph. Pros:
O(|V|*ln(|V|))
operation), without needing to re-index any (grows with the size of the AST).Cons:
Array
(which has O(1) access time) to iterate over vertices (which are backed in ocamlgraph by a Map
, itself implemented using AVL trees). Swapping the Graph.Persistent
implementation for a Graph.Imperative
may however help address this issue.Another approach would be to convert a statement like this:
let nodes = ('a, 'b, 'c, 'd)
let edges = {'a-'b; 'b-'a; 'b='c; 'b='d; }
into one like this:
let nodes = 4
let edges = {0-1; 1-0; 1=2; 1=3; }
let 'a = 0
let 'b = 1
let 'c = 2
let 'd = 3
We then can use 'a, 'b, 'c, 'd
freely in the rest of the file and they will be inlined by the transformations.
Pros:
Cons:
O(|V|)
?)Overall, while Option 1 is promising from a design perspective, it may not make sense performance-wise. Hence, a better approach might be to take Option 2.
It would be great if we could use other values to refer to nodes rather than simply numbers. This could be a simple case where we internally just store all the node labels in a list and use the list indices internally, but print with the labels.
We would need to either add a new
node_labels
declaration of some kind, or change how a user can writenodes
declarations.Here's a rough idea of what it might look like: