use main to call all tests:

This commit is contained in:
Vítor Santos Costa 2015-11-10 14:22:13 +00:00
parent adf3ed0311
commit e4bcc5e8a2
5 changed files with 64 additions and 11 deletions

View File

@ -19,9 +19,23 @@
:- use_module(library(gecode/clpfd)). :- use_module(library(gecode/clpfd)).
:- use_module(library(maplist)). :- 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. % 5 people want to have a photograph together, but they have preferences.
photo(Ex, People, Amount) :- photo(Ex, People, Amount) :-
ex(Ex, People, Preferences), ex(Ex, People, _, Preferences),
length(People, Len), length(People, Len),
Len0 is Len-1, Len0 is Len-1,
People ins 0..Len0, People ins 0..Len0,
@ -39,7 +53,9 @@ photo(Ex, People, Amount) :-
preference_satisfied(X-Y, B) :- preference_satisfied(X-Y, B) :-
abs(X - Y) #= 1 #<==> 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, Carl-Deb,
Deb-Alice, Deb-Alice,
Evan-Alice, Evan-Alice,
@ -49,6 +65,7 @@ ex(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl,
Evan-Bob]). Evan-Bob]).
ex(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan], ex(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan],
['Betty','Chris','Donald','Fred','Gary','Mary','Paul','Peter','Susan'],
[Betty-Donald, [Betty-Donald,
Betty-Gary, Betty-Gary,
Betty-Peter, Betty-Peter,

View File

@ -2,6 +2,18 @@
:- use_module(library(gecode/clpfd)). :- use_module(library(gecode/clpfd)).
:- use_module(library(maplist)). :- 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) :- queens(N, Queens) :-
length(Queens, N), length(Queens, N),
Queens ins 1..N, Queens ins 1..N,
@ -35,4 +47,3 @@ constrain(Q, I, R, J, J1) :-
J1 is J+1, J1 is J+1,
Q + I #\= R + J, Q + I #\= R + J,
Q - I #\= R - J. Q - I #\= R - J.

View File

@ -6,18 +6,28 @@
%% under the terms of the GNU Lesser General Public License as published by the %% 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 %% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version. %% option) any later version.
%% %%
%% This program is distributed in the hope that it will be useful, but WITHOUT %% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or %% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for %% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details. %% more details.
%% %%
%% You should have received a copy of the GNU Lesser General Public License %% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%============================================================================= %%=============================================================================
:- use_module(library(gecode/clpfd)). :- 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 % S E N D
% + M O R E % + M O R E
% --------- % ---------

View File

@ -6,20 +6,31 @@
%% under the terms of the GNU Lesser General Public License as published by the %% 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 %% Free Software Foundation, either version 3 of the License, or (at your
%% option) any later version. %% option) any later version.
%% %%
%% This program is distributed in the hope that it will be useful, but WITHOUT %% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or %% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for %% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
%% more details. %% more details.
%% %%
%% You should have received a copy of the GNU Lesser General Public License %% You should have received a copy of the GNU Lesser General Public License
%% along with this program. If not, see <http://www.gnu.org/licenses/>. %% along with this program. If not, see <http://www.gnu.org/licenses/>.
%%============================================================================= %%=============================================================================
:- use_module(library(gecode/clpfd)). :- 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 % S E N D
% + M O S T % + M O S T
% --------- % ---------
% M O N E Y % M O N E Y
send_most_money(Letters, Money) :- send_most_money(Letters, Money) :-

View File

@ -5,15 +5,19 @@
:- use_module(library(gecode/clpfd)). :- use_module(library(gecode/clpfd)).
:- use_module(library(maplist)). :- use_module(library(maplist)).
main :-
sudoku(Ex, Els),
fail.
main.
sudoku( Ex ) :- sudoku( Ex, Els ) :-
problem(Ex, Els), problem(Ex, Els),
output(Els). output(Els).
% %
% gecode constraints % gecode constraints
% %
problem(Ex, Els) :- problem(Ex, Els) :-
length(Els, 81), length(Els, 81),
Els ins 1..9, Els ins 1..9,
M <== matrix( Els, [dim=[9,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). format('| ~d ~d ~d | ~d ~d ~d | ~d ~d ~d |~n', L).
output_line :- output_line :-
format(' ~|~`-t~24+~n', []). format(' ~|~`-t~24+~n', []).
ex( 1, [ ex( 1, [
_,6,_,1,_,4,_,5,_, _,6,_,1,_,4,_,5,_,