Add graph coloring example

This commit is contained in:
Patrick Lühne 2020-06-12 23:03:58 +02:00
parent 57e4a9f145
commit a81da75306
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
2 changed files with 26 additions and 0 deletions

12
examples/coloring-1.lp Normal file
View File

@ -0,0 +1,12 @@
% After eliminating the super-easy aggregate expression from the rule
%
% {color(X,Z) : color(Z)} = 1 :- vertex(X).
%
% we get 4 rules:
{color(X,Z)} :- vertex(X), color(Z).
:- color(X,Z1), color(X,Z2), vertex(X), color(Z1), color(Z2), Z1 != Z2.
aux(X) :- vertex(X), color(Z), color(X,Z).
:- vertex(X), not aux(X).
:- edge(X,Y), color(X,Z), color(Y,Z).

14
examples/coloring.spec Normal file
View File

@ -0,0 +1,14 @@
input: vertex/1, edge/2, color/1.
output: color/2.
# edge/2 is a set of pairs of vertices
assume: forall X, Y (edge(X,Y) -> vertex(X) and vertex(Y)).
# color/2 is a function from vertices to colors
spec: forall X, Z (color(X,Z) -> vertex(X) and color(Z)).
spec: forall X (vertex(X) -> exists Z color(X,Z)).
spec: forall X, Z1, Z2 (color(X,Z1) and color(X,Z2) -> Z1 = Z2).
# adjacent vertices have different colors
spec: not exists X, Y, Z (edge(X,Y) and color(X,Z) and color(Y,Z)).