# Finite domain solver runtime

Author(s): Emilio Jesús Gallego Arias, Rémy Haemmerlé.

This module provides Finite Domain (FD) constraints and enumerating predicates for FD variables. See clpfd_doc for more details about the Ciao FD solver.

This module provides two kinds of contraints: basic constraints (such as domain/3, all_different/1, ...) that deal with FD variables or lists of FD variables, and meta-contraints (such as #=/2, #=</2, ...) that deal with arithmetic expressions over FD variables, called in the following FD expressions. Meta-constraints of this module behave as described in package clpfd, except that their arguments are interpreted at run time.

## Documentation on exports

PREDICATEin/2

Usage:in(Var,Range)

Constrains Var to take its value in the domain described by Range.

• The following properties should hold at call time:
Var is a variable or an integer.
Range is a range expression.

REGTYPEfdvar/1

Usage:fdvar(X)

X is a variable or an integer.

A term denoting a range expression:
```fd_range_expr(I) :-
integer(I).
fd_range_expr(..(Min,Max)) :-
integer(Min),
integer(Max).
fd_range_expr(A\/B) :-
fd_range_expr(A),
fd_range_expr(B).
```
an integer stands for a singleton range, Min..Max for the closed interval from Min to Max, and A\/B for the union of ranges A and B. Range expressions are used by the in/2 predciate.

Usage:fd_range_expr(Expr)

Expr is a range expression.

REGTYPEfd_expr/1
A term denoting an arithmetic expression over FD variables:
```fd_expr(Var) :-
var(Var).
fd_expr(I*Exp) :-
int(I),
fd_expr(Exp).
fd_expr(Exp*I) :-
int(I),
fd_expr(Exp).
fd_expr(Exp1+Exp2) :-
fd_expr(Exp1),
fd_expr(Exp2).
fd_expr(Exp1-Exp2) :-
fd_expr(Exp1),
fd_expr(Exp2).
fd_expr(-Exp) :-
fd_expr(Exp).
```
FD expressions are used by meta-constraints.

Usage:fd_expr(Expr)

Expr is an FD expression.

PREDICATE#=/2
Meta-constraint "equal".

Usage:#=(A,B)

Constrains the interpretation of A to be equal to the interpretation of B.

• The following properties should hold at call time:
A is an FD expression.
B is an FD expression.

PREDICATE#\=/2
Meta-constraint "not equal".

Usage:#\=(A,B)

Constrains the interpretation of A to be different from the interpretation of B

• The following properties should hold at call time:
A is an FD expression.
B is an FD expression.

PREDICATE#</2
Meta-constraint "smaller than".

Usage:#<(A,B)

Constrains the interpretation of A to be smaller than the interpretation of B.

• The following properties should hold at call time:
A is an FD expression.
B is an FD expression.

PREDICATE#=</2
Meta-constraint "smaller or equal".

Usage:#=<(A,B)

Constrains A to be smaller or equal to B.

• The following properties should hold at call time:
A is an FD expression.
B is an FD expression.

PREDICATE#>/2
Meta-constraint "greater than".

Usage:#>(A,B)

Constrains the interpretation of A to be greater than the interpretation of B.

• The following properties should hold at call time:
A is an FD expression.
B is an FD expression.

PREDICATE#>=/2
Meta-constraint "greater or equal".

Usage:#>=(A,B)

Constrains the interpretation of A to be greater or equal than the interpretation of B.

• The following properties should hold at call time:
A is an FD expression.
B is an FD expression.

PREDICATEdomain/3

Usage:domain(Vars,Min,Max)

Constrains each element of Vars to take its value between Min and Max (included). This predicate is generally used to set the initial domain of an interval

• The following properties should hold at call time:
Vars is a list of fdvars.
Min is an integer.
Max is an integer.

PREDICATEin/2

Usage:in(Var,Range)

Constrains Var to take its value in the domain described by Range.

• The following properties should hold at call time:
Var is a variable or an integer.
Range is a range expression.

Usage:all_different(Vars)

Constrains all elements in Vars to take distinct values. This is equivalent to posting an inequality constraint for each pair of variables. This constraint is triggered when a variable becomes ground, removing its value from the domain of the other variables.

• The following properties should hold at call time:
Vars is a list of fdvars.

PREDICATElabeling/2

Usage:labeling(Options,Vars)

Assigns a value to each variable in Vars according to the labeling options given by Options. This predicate is re-executable on backtracking.

The different options are :

• []: the leftmost variables is selected first. Its values are enumerating from the smallest to the greatest.

• [ff]: the variable with the smallest number of elements in its domain is selected first. Its values are then enumerated from the smallest to the greatest.

• [step]: the variable with the smallest number of elements in its domain is selected first. The minimal value of the domainis assigned, on bactracking the value is pruned form the domain and a new variable is selected.

• The following properties should hold at call time:
Vars is a list of fdvars.

PREDICATEindomain/1
No further documentation available for this predicate.

PREDICATElabel/1
No further documentation available for this predicate.

PREDICATElabeling/2

Usage:labeling(Options,Vars)

Assigns a value to each variable in Vars according to the labeling options given by Options. This predicate is re-executable on backtracking.

The different options are :

• []: the leftmost variables is selected first. Its values are enumerating from the smallest to the greatest.

• [ff]: the variable with the smallest number of elements in its domain is selected first. Its values are then enumerated from the smallest to the greatest.

• [step]: the variable with the smallest number of elements in its domain is selected first. The minimal value of the domainis assigned, on bactracking the value is pruned form the domain and a new variable is selected.

• The following properties should hold at call time:
Vars is a list of fdvars.

PREDICATEminimize/2
No further documentation available for this predicate. Meta-predicate with arguments: minimize(goal,?).

PREDICATEmaximize/2
No further documentation available for this predicate. Meta-predicate with arguments: maximize(goal,?).

PREDICATEwrapper/2
No further documentation available for this predicate.

## Documentation on multifiles

No further documentation available for this predicate. The predicate is multifile.

No further documentation available for this predicate. The predicate is multifile.

## Documentation on imports

This module has the following direct dependencies: