Library for finite domain constraint solving.
The general structure of a specification of an FD problem is as follows:
domain_constraint & fd_constraint & labeling
where:
domain_constraint
specifies the possible range of the FD variables (see constraint domain)
fd_constraint
specifies the constraint to be satisfied by a valid solution
(see constraints #+, #-, allDifferent, etc below)
labeling
is a labeling function to search for a concrete solution.
Note: This library is based on the corresponding library of Sicstus-Prolog
but does not implement the complete functionality of the
Sicstus-Prolog library.
However, using the PAKCS interface for external functions, it is relatively
easy to provide the complete functionality.
| Exported names: |
Datatypes:
Constraint
| LabelingOption
Constructors:
All
| Assumptions
| Bisect
| Down
| Enum
| FirstFail
| FirstFailConstrained
| LeftMost
| Max
| Maximize
| Min
| Minimize
| Step
| Up
Functions:
#/=#
| #<#
| #<=#
| #<=>#
| #=#
| #=>#
| #>#
| #>=#
| *#
| +#
| -#
| /=#
| <#
| <=#
| =#
| >#
| >=#
| allDifferent
| all_different
| count
| domain
| indomain
| labeling
| scalarProduct
| solve
| sum
| Summary of exported functions: |
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
| Imported modules: |
| Exported datatypes: |
A datatype to represent reifyable constraints.
Constructors:
This datatype contains all options to control the instantiated of FD variables
with the enumeration constraint labeling.
Constructors:
:: LabelingOption
LeftMost - The leftmost variable is selected for instantiation (default)
:: LabelingOption
FirstFail - The leftmost variable with the smallest domain is selected
(also known as first-fail principle)
:: LabelingOption
FirstFailConstrained - The leftmost variable with the smallest domain
and the most constraints on it is selected.
:: LabelingOption
Min - The leftmost variable with the smalled lower bound is selected.
:: LabelingOption
Max - The leftmost variable with the greatest upper bound is selected.
:: LabelingOption
Step - Make a binary choice between x=#b and
x/=#b for the selected variable
x where b is the lower or
upper bound of x (default).
:: LabelingOption
Enum - Make a multiple choice for the selected variable for all the values
in its domain.
:: LabelingOption
Bisect - Make a binary choice between x<=#m and
x>#m for the selected variable
x where m is the midpoint
of the domain x
(also known as domain splitting).
:: LabelingOption
Up - The domain is explored for instantiation in ascending order (default).
:: LabelingOption
Down - The domain is explored for instantiation in descending order.
:: LabelingOption
All - Enumerate all solutions by backtracking (default).
:: Int -> LabelingOption
Minimize v - Find a solution that minimizes the domain variable v
(using a branch-and-bound algorithm).
:: Int -> LabelingOption
Maximize v - Find a solution that maximizes the domain variable v
(using a branch-and-bound algorithm).
:: Int -> LabelingOption
Assumptions x - The variable x is unified with the number of choices
made by the selected enumeration strategy when a solution
is found.
| Exported functions: |
:: [Int] -> Int -> Int -> Success
Constraint to specify the domain of all finite domain variables.
Example call: (domain xs min max)
xs
- list of finite domain variables
min
- minimum value for all variables in xs
max
- maximum value for all variables in xs
:: Int -> Int -> Int
Addition of FD variables.
:: Int -> Int -> Int
Subtraction of FD variables.
:: Int -> Int -> Int
Multiplication of FD variables.
:: Int -> Int -> Success
Equality of FD variables.
:: Int -> Int -> Success
Disequality of FD variables.
:: Int -> Int -> Success
"Less than" constraint on FD variables.
:: Int -> Int -> Success
"Less than or equal" constraint on FD variables.
:: Int -> Int -> Success
"Greater than" constraint on FD variables.
:: Int -> Int -> Success
"Greater than or equal" constraint on FD variables.
:: Int -> Int -> Constraint
Reifyable equality constraint on FD variables.
:: Int -> Int -> Constraint
Reifyable inequality constraint on FD variables.
:: Int -> Int -> Constraint
Reifyable "less than" constraint on FD variables.
:: Int -> Int -> Constraint
Reifyable "less than or equal" constraint on FD variables.
:: Int -> Int -> Constraint
Reifyable "greater than" constraint on FD variables.
:: Int -> Int -> Constraint
Reifyable "greater than or equal" constraint on FD variables.
:: Constraint -> Constraint -> Constraint
The resulting constraint is satisfied if the first argument constraint do not hold or both argument constraints are satisfied.
:: Constraint -> Constraint -> Constraint
The resulting constraint is satisfied if both argument constraint are either satisfied and do not hold.
:: Constraint -> Success
Solves a reified constraint.
:: [Int] -> (Int -> Int -> Success) -> Int -> Success
Relates the sum of FD variables with some integer of FD variable.
:: [Int] -> [Int] -> (Int -> Int -> Success) -> Int -> Success
(scalarProduct cs vs relop v) is satisfied if ((cs*vs) relop v) is satisfied.
The first argument must be a list of integers. The other arguments are as
in sum.
:: Int -> [Int] -> (Int -> Int -> Success) -> Int -> Success
(count v vs relop c) is satisfied if (n relop c), where n is the number of
elements in the list of FD variables vs that are equal to v, is satisfied.
The first argument must be an integer. The other arguments are as
in sum.
:: [Int] -> Success
"All different" constraint on FD variables.
Example call: (allDifferent xs)
xs
- list of FD variables
:: [Int] -> Success
For backward compatibility. Use allDifferent.
:: Int -> Success
Instantiate a single FD variable to its values in the specified domain.
:: [LabelingOption] -> [Int] -> Success
Instantiate FD variables to their values in the specified domain.
Example call: (labeling options xs)
options
- list of option to control the instantiation of FD variables
xs
- list of FD variables that are non-deterministically
instantiated to their possible values.