Variables

Integer variables

The implementation of integer variables in SeaPearl is heavily inspired on MiniCP. If you have some troubles understanding how it works, you can get more visual explanations by reading their slides.

The integer variables are all a subset of AbstractIntVar.

Every AbstractIntVar must have a unique id that you can retrieve with id.

SeaPearl.idFunction
function id(x::AbstractVar)

Return the string identifier of x. Every variable must be assigned a unique identifier upon creation, that will be used as a key to identify the variable in the CPModel object.

source
SeaPearl.isboundFunction
isbound(x::AbstractIntVar)

Check whether x has an assigned value.

source
isbound(x::AbstractBoolVar)

Check whether x has an assigned value.

source
isbound(x::IntSetVar)

Check whether x has an assigned value (meaning its domain only contains one subset)

source
SeaPearl.assign!Method
assign!(x::AbstractIntVar, value::Int)

Remove everything from the domain of x but value.

source
SeaPearl.assignedValueFunction
assignedValue(x::AbstractIntVar)

Return the assigned value of x. Throw an error if x is not bound.

source
assignedValue(x::BoolVar)

Return the assigned value of x. Throw an error if x is not bound.

source
assignedValue(x::IntSetVar)

Return the assigned value of x, i.e. the only subset it contains. Throw an error if x is not bound.

source

IntVar

SeaPearl.IntVarType
struct IntVar <: AbstractIntVar

A "simple" integer variable, whose domain can be any set of integers. The constraints that affect this variable are stored in the onDomainChange array.

source
SeaPearl.IntVarMethod
function IntVar(min::Int, max::Int, id::String, trailer::Trailer)

Create an IntVar with a domain being the integer range [min, max] with the id string identifier and that will be backtracked by trailer.

source

IntDomain

SeaPearl.IntDomainType
struct IntDomain <: AbstractIntDomain

Sparse integer domain. Can contain any set of integer.

You must note that this implementation takes as much space as the size of the initial domain. However, it can be pretty efficient in accessing and editing. Operation costs are detailed for each method.

source
SeaPearl.IntDomainMethod
IntDomain(trailer::Trailer, n::Int, offset::Int)

Create an integer domain going from ofs + 1 to ofs + n. Will be backtracked by the given trailer.

source

Domain updates

Missing docstring.

Missing docstring for SeaPearl.isempty. Check Documenter's build log for details.

Base.lengthFunction
length(dom::IntDomain)

Return the size of dom. Done in constant time.

source
length(dom::BoolDomain)

Return the size of dom. Done in constant time.

source
length(dom::IntDomainView)

Return the size of dom.

source
length(dom::BoolDomainView)

Return the size of dom.

source
length(dom::IntDomain)

Return the size of dom. Done in constant time.

source
Base.length(set::SetModification)

a generic function length is needed for all modifications.

source
Base.inMethod
Base.in(value::Int, dom::IntDomain)

Check if an integer is in the domain. Done in constant time.

source
SeaPearl.remove!Function
remove!(dom::IntDomain, value::Int)

Remove value from dom. Done in constant time.

source
remove!(dom::BoolDomain, value::Bool)

Remove value from dom. Done in constant time.

source
remove!(dom::BoolDomain, value::Int)

Remove value from dom. Done in constant time.

source
remove!(dom::IntDomainView, value::Int)

Remove value from dom.

source
remove!(dom::BoolDomainViewNot, value::Bool)

Remove value from dom.

source
SeaPearl.removeAll!Function
removeAll!(dom::IntDomain)

Remove every value from dom. Return the removed values. Done in constant time.

source
removeAll!(dom::BoolDomain)

Remove every value from dom. Return the removed values. Done in constant time.

source
removeAll!(dom::IntDomainView)

Remove every value from dom. Return the removed values.

source
removeAll!(dom::BoolDomainViewNot)

Remove every value from dom. Return the removed values.

source
SeaPearl.removeAbove!Function
removeAbove!(dom::IntDomain, value::Int)

Remove every integer of dom that is strictly above value. Done in linear time.

source
removeAbove!(dom::IntDomain, value::Int)

Remove every integer of dom that is strictly above value. Done in linear time.

source
removeAbove!(dom::IntDomainView, value::Int)

Remove every integer of dom that is strictly above value.

source
SeaPearl.removeBelow!Function
removeBelow!(dom::IntDomain, value::Int)

Remove every integer of dom that is strictly below value. Return the pruned values. Done in linear time.

source
removeBelow!(dom::IntDomain, value::Int)

Remove every integer of dom that is strictly below value. Return the pruned values. Done in linear time.

source
removeBelow!(dom::IntDomainView, value::Int)

Remove every integer of dom that is strictly below value. Return the pruned values.

source
SeaPearl.assign!Function
assign!(dom::IntDomain, value::Int)

Remove everything from the domain but value. Return the removed values. Return the pruned values. Done in constant time.

source
assign!(x::AbstractIntVar, value::Int)

Remove everything from the domain of x but value.

source
assign!(dom::BoolDomain, value::Bool)

Remove everything from the domain but value. Return the removed values. Return the pruned values. Done in constant time.

source
assign!(dom::BoolDomain, value::Int)

Remove everything from the domain but value. Return the removed values. Return the pruned values. Done in constant time.

source
assign!(x::BoolVar, value::Bool)

Remove everything from the domain of x but value.

source
assign!(dom::IntDomainView, value::Int)

Remove everything from the domain but value. Return the removed values. Return the pruned values.

source
assign!(dom::BoolDomainViewNot, value::Bool)

Remove everything from the domain but value. Return the removed values. Return the pruned values.

source
Base.iterateMethod
Base.iterate(dom::IntDomain, state=1)

Iterate over the domain in an efficient way. The order may not be consistent. WARNING: Do NOT update the domain you are iterating on.

source
SeaPearl.updateMaxFromRemovedVal!Function
updateMaxFromRemovedVal!(dom::IntDomain, v::Int)

Knowing that v just got removed from dom, update dom's maximum value. Done in constant time.

source
updateMaxFromRemovedVal!(dom::IntDomainView, v::Int)

Knowing that v just got removed from dom, update dom's maximum value.

source
SeaPearl.updateMinFromRemovedVal!Function
updateMinFromRemovedVal!(dom::IntDomain, v::Int)

Knowing that v just got removed from dom, update dom's minimum value. Done in constant time.

source
updateMinFromRemovedVal!(dom::IntDomainView, v::Int)

Knowing that v just got removed from dom, update dom's minimum value.

source
SeaPearl.updateBoundsFromRemovedVal!Function
updateBoundsFromRemovedVal!(dom::AbstractIntDomain, v::Int)

Knowing that v just got removed from dom, update dom's minimum and maximum value. Done in constant time.

source
SeaPearl.minimumFunction
minimum(dom::IntDomain)

Return the minimum value of dom. Done in constant time.

source
minimum(dom::BoolDomain)

Return the minimum value of dom. Done in constant time.

source
minimum(dom::IntDomainView)

Return the minimum value of dom.

source
SeaPearl.maximumFunction
maximum(dom::IntDomain)

Return the maximum value of dom. Done in constant time.

source
maximum(dom::BoolDomain)

Return the maximum value of dom. Done in constant time.

source
maximum(dom::IntDomainView)

Return the maximum value of dom.

source

If you want to express some variations of an integer variable $x$ (for example $-x$ or $a x$ with $a > 0$) in a constraint, you can use the IntVarView types:

IntVarView

SeaPearl.IntVarViewMulType
IntVarViewMul(x::AbstractIntVar, a::Int, id::String)

Create a fake variable y, such that y == a*x. This variable behaves like an usual one.

source
SeaPearl.IntVarViewOppositeType
IntVarViewOpposite(x::AbstractIntVar, id::String)

Create a *fake* variable `y`, such that `y = -x`. This variable behaves like an usual one.
source
SeaPearl.IntVarViewOffsetType
IntVarViewOffset(x::AbstractIntVar, id::String)

Create a fake variable y, such that y = x + c. This variable behaves like an usual one.

source

IntDomainView

SeaPearl.IntDomainViewMulType
IntDomainViewMul(orig::AbstractIntDomain, a::Int)

Domain for an integer variable that is a multiple of another integer variable. See IntVarViewMul.

source
SeaPearl.IntDomainViewOppositeType
IntDomainViewOpposite(orig::AbstractIntDomain)

Domain for an integer variable that is the opposite of another integer variable (y = -x).

source
SeaPearl.IntDomainViewOffsetType
IntDomainViewOffset(orig::AbstractIntDomain, c::Int)

Domain for an integer variable that is offset by a constant 'c' (y = x + c)

source

Boolean Variables

Base Boolean Variables

SeaPearl.BoolVarType
struct BoolVar <: AbstractVar

A "simple" boolean variable. The constraints that affect this variable are stored in the onDomainChange array.

source

Boolean View Variables

SeaPearl.BoolVarViewNotType

BoolVarViewNot(x::AbstractBoolVar, id::String)

Fake variable y, such that y = ¬x. This variable behaves like an usual one.

source

Boolean Domains

SeaPearl.BoolDomainType
struct BoolDomain <: AbstractDomain

Boolean domain, uses a IntDomain in it. (true is 1 and false is 0)

source