Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update custom constraint example #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions clpz.pl
Original file line number Diff line number Diff line change
Expand Up @@ -938,19 +938,30 @@
one of X and Y is instantiated:

==
:- multifile clpz:run_propagator/2.
:- multifile(clpz:run_propagator/4).

oneground(X, Y, Z) :-
clpz:make_propagator(oneground(X, Y, Z), Prop),
clpz:init_propagator(X, Prop),
clpz:init_propagator(Y, Prop),
clpz:trigger_once(Prop).

clpz:run_propagator(oneground(X, Y, Z), MState) :-
( integer(X) -> clpz:kill(MState), Z = 1
; integer(Y) -> clpz:kill(MState), Z = 1
; true
).
clpz:make_propagator(oneground(X,Y,Z), Prop),
clpz:init_propagator(X, Prop),
clpz:init_propagator(Y, Prop),
clpz:trigger_once(Prop).

clpz:run_propagator(oneground(X,Y,Z), MState) -->
{
(
integer(X)
->
clpz:kill(MState),
Z = 1
; (
integer(Y)
->
clpz:kill(MState),
Z = 1
; true
)
)
}.
==

First, clpz:make_propagator/2 is used to transform a user-defined
Expand All @@ -959,7 +970,7 @@
Y. From now on, the propagator will be invoked whenever the domains of
X or Y are changed. Then, clpz:trigger_once/1 is used to give the
propagator its first chance for propagation even though the variables'
domains have not yet changed. Finally, clpz:run_propagator/2 is
domains have not yet changed. Finally, clpz:run_propagator//2 is
extended to define the actual propagator. As explained, this predicate
is automatically called by the constraint solver. The first argument
is the user-defined representation of the constraint as used in
Expand Down Expand Up @@ -4328,6 +4339,7 @@

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

:- multifile(clpz:run_propagator/4).
%run_propagator(P, _) --> { portray_clause(run_propagator(P)), false }.
% trivial propagator, used only to remember pending constraints
run_propagator(presidual(_), _) --> [].
Expand Down