module 'data.fd' { syntax: infix '..'. syntax: '=' < '..' < ':'. constructor: '..'/2. /** check(X). * Succeeds if X is a finite-domain variable, the domain * of which is already initialized. */ check(X) :- kernel:fd_check(X). /** set_domain(X, Lower, Upper). * * Lower and Upper are instantiated integers. * * Succeeds if X is a finite-domain variable, the * domain of which is * [Lower ... Upper]. */ set_domain(X, Lower, Upper) :- kernel:fd_set_domain(X, Lower, Upper). /** set_domain(X, List). * * List is a list of instantiated integers. * * Succeeds if X is a finite-domain variable, the * domain of which is List. */ set_domain(X, List) :- kernel:fd_set_domain(X, List). /** new(Lower, Upper, X). * Equivalent to set_domain(X, Lower, Upper). */ new(Lower, Upper, X) :- set_domain(X, Lower, Upper). /** new(List, X). * Equivalent to set_domain(X, List). */ new(List, X) :- set_domain(X, List). import: module { domain_list(Number) = 'data.number':check(Number) >> ! >> [Number]. domain_list(Lower .. Upper) = 'data.number':(Lower .. Upper). domain_list(A, B) = 'data.list':append(Impl:domain_list(A), Impl:domain_list(B)). }. /** { Domain } = X. * * Either Domain is a sequence of items of the form Value or Lower .. Upper, * where Value, Lower and Upper are instantiated integers. * * Succeeds if X is a finite-domain variable, the domain * of which matches the specification given by Domain * (sequence of sparse values and intervals). */ `{}'(Domain, Domain) :- ( X = Lower .. Upper -> new(Lower, Upper, X) ; new(domain_list(Domain), X) ). /** min(X, Lower). * * X is a finite-domain variable. * * Succeeds if Lower is the minimal value of the domain of * X. */ min(X) = kernel:fd_min(X). /** max(X, Upper). * * X is a finite-domain variable. * * Succeeds if Upper is the maximal value of the domain of * X. */ max(X) = kernel:fd_max(X). /** size(X, Size). * * X is a finite-domain variable. * * Succeeds if Size is the number of values in the domain of * X. */ size(X) = kernel:fd_size(X). /** get_domain(X, List). * * X is a finite-domain variable. * * Succeeds if List is the list of values in the domain of * X. */ get_domain(X) = kernel:fd_dom(X). syntax: infix right associative \/ /\ <=> => . syntax: '\\+' < <=> = => < \/ < /\ <'='. /** (A \/ B) = X. * Succeeds if X is the reified constraint A * ∨ B, where A and B are * reified constraints. */ `\\/'(A, B) = kernel:fd_or(A, B). /** (A /\ B) = X. * Succeeds if X is the reified constraint A * ∧ B, where A and B are * reified constraints. */ `/\\'(A, B) = kernel:fd_and(A, B). /** (A <=> B) = X. * Succeeds if X is the reified constraint A * ⇔ B, where A and B are * reified constraints. */ `<=>'(A, B) = kernel:fd_equiv(A, B). /** A <=> B. * Ensures that A * ⇔ B, where A and B are * reified constraints. */ `<=>'(A, B) :- kernel:fd_equiv(A, B). /** (A => B) = X. * Succeeds if X is the reified constraint A * ⇒ B, where A and B are * reified constraints. */ `=>'(A, B) = kernel:fd_impl(A, B). /** A => B. * Ensures that A * ⇒ B, where A and B are * reified constraints. */ `=>'(A, B) :- kernel:fd_impl(A, B). /** cardinality(List, X). * * List is a list of finite-domain variables. * * Ensures that the finite-domain variable X is equal to * the count of reified constraints which are true in List. */ cardinality(List) = kernel:fd_cardinality(List). /** all_different(List). * * List is a list of finite-domain variables. * * Ensures that the finite-domain variables in List are * pairwise distinct. */ all_different(List) :- kernel:fd_all_different(List) . /** element(I, List, X). * * List is a list of instantiated integers. * * Ensures that the Ith element of List is * X, where I and X are * finite-domain variables. */ element(I, List, X) :- kernel:fd_element(I, List, X). /** element_var(I, List, X). * * List is a list of finite-domain variables. * * Ensures that the Ith element of List is * X, where I and X are * finite-domain variables. */ element_var(I, List, X) :- kernel:fd_element_var(I, List, X). relation(R, List) :- kernel:fd_relation(R, List). /** labeling(X). * * X is either a finite-domain variable or a list of * finite-domain variables. * * Enumerates satisfiable instantiations of X. */ labeling(X) :- kernel:fd_labeling(X). labeling(X, Opts) :- kernel:fd_labeling(X, Opts). /** minimize(M). * * M is a module with a predicate objective(X). * * Finds the minimal value for X by branch-and-bound. */ minimize(M) :- kernel:fd_minimize(M). /** maximize(M). * * M is a module with a predicate objective(X). * * Finds the maximal value for X by branch-and-bound. */ maximize(M) :- kernel:fd_maximize(M). pretty(X) = 'data.fd:'({ 'data.fd':min(X) .. 'data.fd':max(X) }). }