-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliquid_rules.dl
61 lines (54 loc) · 3.82 KB
/
liquid_rules.dl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
typedef Operation = Source { node: string, out_port: string }
| Push { node: string, out_port: string }
| Route { node: string, in_port: string, out_port: string }
| Sink { node: string, in_port: string }
| Pull { node: string, in_port: string }
input relation Can(op: Operation)
input relation Edge(edge_id:string, from_node: string, to_node: string, from_port: string, to_port: string)
output relation CanFollow(op1: Operation, op2: Operation)
CanFollow(Source{node1, port1}, Sink{node2, port2}) :- Edge(_, node1, node2, port1, port2),
Can(Source{node1, port1}),
Can(Sink{node2, port2}).
CanFollow(Source{node1, port1}, Pull{node2, port2}) :- Edge(_, node1, node2, port1, port2),
Can(Source{node1, port1}),
Can(Pull{node2, port2}).
CanFollow(Source{node1, port1}, Route{node2, port2, port3}) :- Edge(_, node1, node2, port1, port2),
Can(Source{node1, port1}),
Can(Route{node2, port2, port3}).
CanFollow(Push{node1, port1}, Sink{node2, port2}) :- Edge(_, node1, node2, port1, port2),
Can(Push{node1, port1}),
Can(Sink{node2, port2}).
CanFollow(Push{node1, port1}, Pull{node2, port2}) :- Edge(_, node1, node2, port1, port2),
Can(Push{node1, port1}),
Can(Pull{node2, port2}).
CanFollow(Push{node1, port1}, Route{node2, port2, port3}) :- Edge(_, node1, node2, port1, port2),
Can(Push{node1, port1}),
Can(Route{node2, port2, port3}).
CanFollow(Route{node1, port1, port2}, Sink{node2, port3}) :- Edge(_, node1, node2, port2, port3),
Can(Route{node1, port1, port2}),
Can(Sink{node2, port3}).
CanFollow(Route{node1, port1, port2}, Pull{node2, port3}) :- Edge(_, node1, node2, port2, port3),
Can(Route{node1, port1, port2}),
Can(Pull{node2, port3}).
CanFollow(Route{node1, port1, port2}, Route{node2, port3, port4}) :- Edge(_, node1, node2, port2, port3),
Can(Route{node1, port1, port2}),
Can(Route{node2, port3, port4}).
CanFollow(Pull{node, port1}, Push{node, port2}) :- Can(Pull{node, port1}),
Can(Push{node, port2}).
output relation Interpolate(op1: Operation, op2: Operation, ops: Vec<Operation>)
Interpolate(op1, op2, vec_empty()) :- CanFollow(op1, op2).
extern function std_vec_insert_imm (v: Vec<'X>, x: 'X): Vec<'X>
Interpolate(op1, op2, std_vec_insert_imm(v, op)) :- Interpolate(op1, op, v),
CanFollow(op, op2),
not vec_contains(v, op).
function shortest(g: Group<Vec<'X>>): Vec<'X> = {
var result: Vec<'X> = group_first(g);
for (v in g) {
if (vec_len(v) < vec_len(result)) {
result = v
}
};
result
}
output relation Shortest(a: Operation, b: Operation, ops: Vec<Operation>)
Shortest(a, b, ops) :- Interpolate(a, b, v), var ops = Aggregate((a, b), shortest(v)).