improve CLP support
This commit is contained in:
@@ -21,25 +21,25 @@
|
||||
|
||||
% 5 people want to have a photograph together, but they have preferences.
|
||||
photo(Ex, People, Amount) :-
|
||||
db(Ex, People, Preferences),
|
||||
ex(Ex, People, Preferences),
|
||||
length(People, Len),
|
||||
Len0 is Len-1,
|
||||
People ins 0..Len0,
|
||||
all_distinct(People),
|
||||
% Bools are the satisfied constraints
|
||||
maplist(preferences, Preferences, Bools),
|
||||
maplist(preference_satisfied, Preferences, Bools),
|
||||
length(Preferences, PLen),
|
||||
Amount in 0..PLen,
|
||||
sum( Bools, #= , Amount ),
|
||||
sum( Bools ) #= Amount,
|
||||
% add all satisfied constraints
|
||||
maximize(Amount),
|
||||
labeling([], People).
|
||||
|
||||
%reification, use with care
|
||||
preferences(X-Y, B) :-
|
||||
preference_satisfied(X-Y, B) :-
|
||||
abs(X - Y) #= 1 #<==> B.
|
||||
|
||||
db(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl,
|
||||
ex(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl,
|
||||
Carl-Deb,
|
||||
Deb-Alice,
|
||||
Evan-Alice,
|
||||
@@ -48,7 +48,7 @@ db(s,[Alice,Bob,Carl,Deb,Evan], [Alice-Carl,
|
||||
Deb-Evan,
|
||||
Evan-Bob]).
|
||||
|
||||
db(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan],
|
||||
ex(l,[Betty,Chris,Donald,Fred,Gary,Mary,Paul,Peter,Susan],
|
||||
[Betty-Donald,
|
||||
Betty-Gary,
|
||||
Betty-Peter,
|
||||
|
@@ -19,7 +19,7 @@
|
||||
:- use_module(library(gecode/clpfd)).
|
||||
|
||||
% S E N D
|
||||
% + M O R E
|
||||
% + M O S T
|
||||
% ---------
|
||||
% M O N E Y
|
||||
send_most_money(Letters, Money) :-
|
||||
@@ -30,8 +30,7 @@ send_most_money(Letters, Money) :-
|
||||
S #\= 0,
|
||||
all_distinct(Letters),
|
||||
1000*S + 100*E + 10*N + D +
|
||||
1000*M + 100*O + 10*S + T #=
|
||||
10000*M + 1000*O + 100*N + 10*E + Y,
|
||||
1000*M + 100*O + 10*S + T #= Money,
|
||||
10000*M + 1000*O + 100*N + 10*E + Y #= Money,
|
||||
maximize(Money),
|
||||
labeling([], Letters).
|
||||
|
17
library/gecode/clp_examples/test.yap
Normal file
17
library/gecode/clp_examples/test.yap
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
:- use_module(library(gecode/clpfd)).
|
||||
:- use_module(library(maplist)).
|
||||
|
||||
test0(X) :-
|
||||
X in 1..10,
|
||||
X #= 2.
|
||||
test1(X) :-
|
||||
X in 1..10,
|
||||
Y in 3..7,
|
||||
Z in 1..4,
|
||||
X / Y #= Z,
|
||||
labeling([], [X]).
|
||||
test2(X) :-
|
||||
X in 1..10,
|
||||
X / 4 #= 2,
|
||||
labeling([], [X]).
|
Reference in New Issue
Block a user