Constraints API
The Constraints API provides the constraint programming functionality for move filtering.
CP Variables
IntVariable
JuLS.IntVariable
— Typestruct IntVariable <: CPVariable
A "simple" integer variable, whose domain can be any set of integers. The constraints that affect this variable are stored in the on_domain_change
array.
BoolVariable
JuLS.BoolVariable
— Typestruct BoolVariable <: AbstractVar
A "simple" boolean variable. The constraints that affect this variable are stored in the on_domain_change
array.
CP Constraints
Basic Constraints
JuLS.Equal
— Typestruct Equal <: CPConstraint
CPConstraint x = y
JuLS.NotEqual
— Typestruct NotEqual <: CPConstraint
CPConstraint x != y between two CPVariables x
and y
.
JuLS.SumLessThan
— Typestruct SumLessThan <: CPConstraint
CPConstraint ∑(x_i ∀ i ∈ |x|) ≤ upper
Filtering: The goal is to enforce the constraint: ∑(x_i ∀ i ∈ |x|) ≤ upper
We can rewrite as: xi + ∑(xj ∀ j != i) ≤ upper → xi ≤ - ∑(xj ∀ j != i) + upper
Therefore, the tighest bound on xi (maximum value xi can take) is: xi = - ∑(xj ∀ j != i) + upper
We know that:
- ∑(xj ∀ j != i) ≤ - ∑(min(xj) ∀ j != i)
- ∑(min(xj) ∀ j != i) = min(xi) - ∑(min(x_i) ∀ i ∈ |x|)
Rewrite:
- ∑(xj ∀ j != i) ≤ min(xi) - ∑(min(xi) ∀ i ∈ |x|) xi - upper ≤ min(xi) - ∑(min(xi) ∀ i ∈ |x|)
⟹ xi ≤ min(xi) - ∑(min(x_i) ∀ i ∈ |x|) + upper This means that we can prune all values greater than - ∑(min(xj) ∀ j != i) + upper from xi's domain
Integration with DAG
CP constraints are automatically generated from DAG invariants when using_cp = true
.