From e4bcc5e8a20510b240f70111eb91689a402424a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Tue, 10 Nov 2015 14:22:13 +0000 Subject: [PATCH] use main to call all tests: --- packages/gecode/clp_examples/photo.yap | 21 +++++++++++++++++-- packages/gecode/clp_examples/queens.yap | 13 +++++++++++- .../gecode/clp_examples/send_more_money.yap | 14 +++++++++++-- .../gecode/clp_examples/send_most_money.yap | 17 ++++++++++++--- packages/gecode/clp_examples/sudoku.yap | 10 ++++++--- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/packages/gecode/clp_examples/photo.yap b/packages/gecode/clp_examples/photo.yap index f34bbd290..c27ca873d 100644 --- a/packages/gecode/clp_examples/photo.yap +++ b/packages/gecode/clp_examples/photo.yap @@ -19,9 +19,23 @@ :- use_module(library(gecode/clpfd)). :- use_module(library(maplist)). +main :- ex(Ex, People, Names, _Preferences), + photo(Ex, People, Amount ), + format( 'Example ~a: ~w~n', [Ex, Amount]), + maplist(join, People, Names, PeopleNames), + keysort( PeopleNames, SortedPeopleNames), + maplist(join, _People, SortedNames, SortedPeopleNames), + maplist(output, SortedNames ), + fail. +main. + +join( Key, El, Key-El ). + +output( Name ) :- format(' ~a~n', [Name]). + % 5 people want to have a photograph together, but they have preferences. photo(Ex, People, Amount) :- - ex(Ex, People, Preferences), + ex(Ex, People, _, Preferences), length(People, Len), Len0 is Len-1, People ins 0..Len0, @@ -39,7 +53,9 @@ photo(Ex, People, Amount) :- preference_satisfied(X-Y, B) :- abs(X - Y) #= 1 #<==> B. -ex(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl, +ex(s,[Alice,Bob,Carl,Deb,Evan], + ['Alice','Bob','Carl','Deb','Evan'], + [Alice-Carl, Carl-Deb, Deb-Alice, Evan-Alice, @@ -49,6 +65,7 @@ ex(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl, Evan-Bob]). ex(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan], + ['Betty','Chris','Donald','Fred','Gary','Mary','Paul','Peter','Susan'], [Betty-Donald, Betty-Gary, Betty-Peter, diff --git a/packages/gecode/clp_examples/queens.yap b/packages/gecode/clp_examples/queens.yap index 4131a68f5..bfc9b9839 100644 --- a/packages/gecode/clp_examples/queens.yap +++ b/packages/gecode/clp_examples/queens.yap @@ -2,6 +2,18 @@ :- use_module(library(gecode/clpfd)). :- use_module(library(maplist)). +main :- + between(1,10,N), + I is N*100, + statistics( runtime, _ ), + once( queens(I, _Queens) ), + statistics( runtime, [DT|_] ), +% findall(Queens, queens(I, Queens), Solutions ), +% length( Solutions, N), + format('~d took ~w msec to find first solution.~n', [I, DT]), + fail. +main. + queens(N, Queens) :- length(Queens, N), Queens ins 1..N, @@ -35,4 +47,3 @@ constrain(Q, I, R, J, J1) :- J1 is J+1, Q + I #\= R + J, Q - I #\= R - J. - diff --git a/packages/gecode/clp_examples/send_more_money.yap b/packages/gecode/clp_examples/send_more_money.yap index fc03a4337..6f9c467fa 100644 --- a/packages/gecode/clp_examples/send_more_money.yap +++ b/packages/gecode/clp_examples/send_more_money.yap @@ -6,18 +6,28 @@ %% under the terms of the GNU Lesser General Public License as published by the %% Free Software Foundation, either version 3 of the License, or (at your %% option) any later version. -%% +%% %% This program is distributed in the hope that it will be useful, but WITHOUT %% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or %% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for %% more details. -%% +%% %% You should have received a copy of the GNU Lesser General Public License %% along with this program. If not, see . %%============================================================================= :- use_module(library(gecode/clpfd)). +main :- + statistics( runtime, _ ), + once( send_more_money(Letters) ), + statistics( runtime, [DT|_] ), +% findall(Queens, queens(I, Queens), Solutions ), +% length( Solutions, N), + format('took ~w msec to find first solution, ~w.~n', [I, DT, Letters]), + fail. +main. + % S E N D % + M O R E % --------- diff --git a/packages/gecode/clp_examples/send_most_money.yap b/packages/gecode/clp_examples/send_most_money.yap index 9665b3eeb..e31a7c16e 100644 --- a/packages/gecode/clp_examples/send_most_money.yap +++ b/packages/gecode/clp_examples/send_most_money.yap @@ -6,20 +6,31 @@ %% under the terms of the GNU Lesser General Public License as published by the %% Free Software Foundation, either version 3 of the License, or (at your %% option) any later version. -%% +%% %% This program is distributed in the hope that it will be useful, but WITHOUT %% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or %% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for %% more details. -%% +%% %% You should have received a copy of the GNU Lesser General Public License %% along with this program. If not, see . %%============================================================================= :- use_module(library(gecode/clpfd)). + +main :- + statistics( runtime, _ ), + once( send_most_money(Letters, Money) ), + statistics( runtime, [DT|_] ), +% findall(Queens, queens(I, Queens), Solutions ), +% length( Solutions, N), + format('took ~w msec to find first solution, ~w.~n', [DT, Letters:Money]), + fail. +main. + % S E N D -% + M O S T +% + M O S T % --------- % M O N E Y send_most_money(Letters, Money) :- diff --git a/packages/gecode/clp_examples/sudoku.yap b/packages/gecode/clp_examples/sudoku.yap index 34b5735d9..a6ff99c3b 100644 --- a/packages/gecode/clp_examples/sudoku.yap +++ b/packages/gecode/clp_examples/sudoku.yap @@ -5,15 +5,19 @@ :- use_module(library(gecode/clpfd)). :- use_module(library(maplist)). +main :- + sudoku(Ex, Els), + fail. +main. -sudoku( Ex ) :- +sudoku( Ex, Els ) :- problem(Ex, Els), output(Els). % % gecode constraints % -problem(Ex, Els) :- +problem(Ex, Els) :- length(Els, 81), Els ins 1..9, M <== matrix( Els, [dim=[9,9]] ), @@ -51,7 +55,7 @@ output_row( M, Row ) :- format('| ~d ~d ~d | ~d ~d ~d | ~d ~d ~d |~n', L). output_line :- - format(' ~|~`-t~24+~n', []). + format(' ~|~`-t~24+~n', []). ex( 1, [ _,6,_,1,_,4,_,5,_,