-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-remove-po.dl
42 lines (33 loc) · 1 KB
/
add-remove-po.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
.type id = symbol
// OPs
.decl addBetween(U: id, V: id, W: id)
.decl removeVertex(V: id)
// Example
addBetween("|-","a","-|").
addBetween("|-","b","-|").
addBetween("a","c","-|").
removeVertex("d").
removeVertex("e").
addBetween("c","e","-|").
addBetween("e","f","-|").
addBetween("a","d","-|").
removeVertex("a").
// Internal added vertex and edges sets
.decl vertexAdded(V: id)
.decl vertexRemoved(V: id)
.decl edgeAdded(U: id, V: id)
vertexAdded("|-").
vertexAdded("-|").
vertexAdded(V) :- addBetween(U,V,W), vertexAdded(U), vertexAdded(W).
vertexRemoved(V) :- removeVertex(V), V != "|-", V != "-|".
edgeAdded("|-","-|").
edgeAdded(U,V) :- addBetween(U,V,W), vertexAdded(U), vertexAdded(W).
edgeAdded(V,W) :- addBetween(U,V,W), vertexAdded(U), vertexAdded(W).
edgeAdded(U,W) :- edgeAdded(U,V), edgeAdded(V,W).
// Queries
.decl vertex(V: id)
.decl edge(U: id, V: id)
vertex(V) :- vertexAdded(V), ! vertexRemoved(V).
edge(U,V) :- vertex(U), vertex(V), edgeAdded(U,V).
.output vertex(IO=stdout)
.output edge(IO=stdout)