Node:Reflection Predicates, Next:, Previous:The Global Constraint Programming Interface, Up:Defining Global Constraints



Reflection Predicates

The constraint solving method needs access to information about the current domains of variables. This is provided by the following predicates, which are all constant time operations.

fd_var(?X)

Checks that X is currently an unbound variable which is known to the CLPFD solver.

fd_min(?X, ?Min)

where X is a domain variable (or an integer). Min is unified with the smallest value in the current domain of X, i.e. an integer or the atom inf denoting minus infinity.

fd_max(?X, ?Max)

where X is a domain variable (or an integer). Max is unified with the upper bound of the current domain of X, i.e. an integer or the atom sup denoting infinity.

fd_size(?X, ?Size)

where X is a domain variable (or an integer). Size is unified with the size of the current domain of X, if the domain is bounded, or the atom sup otherwise.

fd_set(?X, ?Set)

where X is a domain variable (or an integer). Set is unified with an FD set term denoting the internal representation of the current domain of X; see below.

fd_dom(?X, ?Range)

where X is a domain variable (or an integer). Range is unified with a ConstantRange (see Syntax of Indexicals) denoting the the current domain of X.

fd_degree(?X, ?Degree)

where X is a domain variable (or an integer). Degree is unified with the number of constraints that are attached to X. NOTE: this number may include some constraints that have been detected as entailed. Also, Degree is not the number of neighbors of X in the constraint network.

The following predicates can be used for computing the set of variables that are (transitively) connected via constraints to some given variable(s).

fd_neighbors(+Var, -Neighbors)

Given a domain variable Var, Neighbors is the set of variables that can be reached from Var via constraints posted so far.

fd_closure(+Vars, -Closure)

Given a list Vars of domain variables, Closure is the set of variables (including Vars) that can be transitively reached via constraints posted so far. Thus, fd_closure/2 is the transitive closure of fd_neighbors/2.

The following predicate can be used for computing a symbolic form of the constraints that are transitively attached to some term. This is useful e.g. in the context of asserting or copying terms, as these operations are not supported on terms containing domain variables:

fd_copy_term(+Term, -Template, -Body)

Given a term Term containing domain variables, Template is a copy of the same term with all variables renamed to new variables such that executing Body will post constraints equivalent to those that Term is attached to.

For example:

          | ?- X in 0..1, Y in 10..11, X+5 #=< Y, fd_copy_term(f(X,Y), Template, Body).
          Body = _A in_set[[0|1]],_B in_set[[10|11]],clpfd:'t>=u+c'(_B,_A,5),
          Template = f(_A,_B),
          X in 0..1,
          Y in 10..11 ?