-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evolog Modules: Fix bugs where module definitions do not get passed o…
…n. Add very simple end2end test with module-based 3-coloring implementation.
- Loading branch information
1 parent
13010e0
commit 8bf77b3
Showing
14 changed files
with
106 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
alpha-solver/src/test/resources/e2e-tests/modules-basic.evl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
%%% Module 3col %%% | ||
% | ||
% Calculates 3-colorings of a given graph. | ||
% Graph is expected to be represented as a function term with following | ||
% structure: graph(list(V, TAIL), list(E, TAIL)), where list(V, TAIL) | ||
% and list(E, TAIL) are vertex- and edge-lists. | ||
% | ||
%%% | ||
#module threecol(graph/2 => {col/2}) { | ||
% Unwrap input | ||
vertex_element(V, TAIL) :- graph(list(V, TAIL), _). | ||
vertex_element(V, TAIL) :- vertex_element(_, list(V, TAIL)). | ||
vertex(V) :- vertex_element(V, _). | ||
edge_element(E, TAIL) :- graph(_, list(E, TAIL)). | ||
edge_element(E, TAIL) :- edge_element(_, list(E, TAIL)). | ||
edge(V1, V2) :- edge_element(edge(V1, V2), _). | ||
|
||
% Make sure edges are symmetric | ||
edge(V2, V1) :- edge(V1, V2). | ||
|
||
% Guess colors | ||
red(V) :- vertex(V), not green(V), not blue(V). | ||
green(V) :- vertex(V), not red(V), not blue(V). | ||
blue(V) :- vertex(V), not red(V), not green(V). | ||
|
||
% Filter invalid guesses | ||
:- vertex(V1), vertex(V2), edge(V1, V2), red(V1), red(V2). | ||
:- vertex(V1), vertex(V2), edge(V1, V2), green(V1), green(V2). | ||
:- vertex(V1), vertex(V2), edge(V1, V2), blue(V1), blue(V2). | ||
|
||
col(V, red) :- red(V). | ||
col(V, blue) :- blue(V). | ||
col(V, green) :- green(V). | ||
} | ||
|
||
%%% Main program %%% | ||
% | ||
% This program uses the module "3col" to determine 3-colorability and actual colorings of a graph | ||
% | ||
%%% | ||
|
||
%% pack vertices into a vertex list | ||
vertex_element(E) :- vertex(E). | ||
% First, establish ordering of elements (which we need to establish the order within the list) | ||
vertex_element_less(N, K) :- vertex_element(N), vertex_element(K), N < K. | ||
vertex_element_not_predecessor(N, K) :- vertex_element_less(N, I), vertex_element_less(I, K). | ||
vertex_element_predecessor(N, K) :- vertex_element_less(N, K), not vertex_element_not_predecessor(N, K). | ||
vertex_element_has_predecessor(N) :- vertex_element_predecessor(_, N). | ||
% Now build the list as a recursively nested function term | ||
vertex_lst_element(IDX, list(N, list_empty)) :- vertex_element(N), not vertex_element_has_predecessor(N), IDX = 0. | ||
vertex_lst_element(IDX, list(N, list(K, TAIL))) :- vertex_element(N), vertex_element_predecessor(K, N), vertex_lst_element(PREV_IDX, list(K, TAIL)), IDX = PREV_IDX + 1. | ||
has_next_vertex_element(IDX) :- vertex_lst_element(IDX, _), NEXT_IDX = IDX + 1, vertex_lst_element(NEXT_IDX, _). | ||
vertex_lst(LIST) :- vertex_lst_element(IDX, LIST), not has_next_vertex_element(IDX). | ||
|
||
%% pack edges into an edge list | ||
edge_element(edge(V1, V2)) :- edge(V1, V2). | ||
% First, establish ordering of elements (which we need to establish the order within the list) | ||
edge_element_less(N, K) :- edge_element(N), edge_element(K), N < K. | ||
edge_element_not_predecessor(N, K) :- edge_element_less(N, I), edge_element_less(I, K). | ||
edge_element_predecessor(N, K) :- edge_element_less(N, K), not edge_element_not_predecessor(N, K). | ||
edge_element_has_predecessor(N) :- edge_element_predecessor(_, N). | ||
% Now build the list as a recursively nested function term | ||
edge_lst_element(IDX, list(N, list_empty)) :- edge_element(N), not edge_element_has_predecessor(N), IDX = 0. | ||
edge_lst_element(IDX, list(N, list(K, TAIL))) :- edge_element(N), edge_element_predecessor(K, N), edge_lst_element(PREV_IDX, list(K, TAIL)), IDX = PREV_IDX + 1. | ||
has_next_edge_element(IDX) :- edge_lst_element(IDX, _), NEXT_IDX = IDX + 1, edge_lst_element(NEXT_IDX, _). | ||
edge_lst(LIST) :- edge_lst_element(IDX, LIST), not has_next_edge_element(IDX). | ||
|
||
coloring(COL) :- vertex_lst(VERTEX_LST), edge_lst(EDGE_LST), #threecol[VERTEX_LST, EDGE_LST](COL). | ||
|
||
#test smokeTest(expect: >0) { | ||
given { | ||
vertex(a). | ||
vertex(b). | ||
vertex(c). | ||
edge(a, b). | ||
edge(b, c). | ||
edge(c, a). | ||
} | ||
assertForAll { | ||
coloring_found :- coloring(_). | ||
:- not coloring_found. | ||
} | ||
} |