NetworkVerification / nv

A Framework for Modeling and Analyzing Network Configurations
MIT License
31 stars 2 forks source link

Allow node aliases #48

Open alberdingk-thijm opened 4 years ago

alberdingk-thijm commented 4 years ago

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 write nodes declarations.

Here's a rough idea of what it might look like:

type attribute = int

(* 4 node SRP *)
let nodes = [ 'a, 'b, 'c, 'd, ]

let edges = {
    'a-'b;
    'b-'a;
    'c='d;
    'b='d;
}

let merge n x y = min x y

let trans e x = if e = 'a~'b then 0 else x + 1

let init n = if n = 'd then 0 else 10
alberdingk-thijm commented 2 years ago

Some thoughts on how we can potentially do this:

Change the type of 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:

Cons:

Add syntactic sugar to name nodes

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:

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.