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.id
— Functionfunction 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.
SeaPearl.isbound
— Functionisbound(x::AbstractIntVar)
Check whether x has an assigned value.
isbound(x::AbstractBoolVar)
Check whether x has an assigned value.
isbound(x::IntSetVar)
Check whether x has an assigned value (meaning its domain only contains one subset)
SeaPearl.assign!
— Methodassign!(x::AbstractIntVar, value::Int)
Remove everything from the domain of x
but value
.
SeaPearl.assignedValue
— FunctionassignedValue(x::AbstractIntVar)
Return the assigned value of x
. Throw an error if x
is not bound.
assignedValue(x::BoolVar)
Return the assigned value of x
. Throw an error if x
is not bound.
assignedValue(x::IntSetVar)
Return the assigned value of x
, i.e. the only subset it contains. Throw an error if x
is not bound.
IntVar
SeaPearl.IntVar
— Typestruct 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.
SeaPearl.IntVar
— Methodfunction 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
.
IntDomain
SeaPearl.AbstractIntDomain
— Typeabstract type AbstractIntDomain end
Abstract domain type. Every integer domain must inherit from this type.
SeaPearl.IntDomain
— Typestruct 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.
SeaPearl.IntDomain
— MethodIntDomain(trailer::Trailer, n::Int, offset::Int)
Create an integer domain going from ofs + 1
to ofs + n
. Will be backtracked by the given trailer
.
Domain updates
Missing docstring for SeaPearl.isempty
. Check Documenter's build log for details.
Base.length
— Functionlength(dom::IntDomain)
Return the size of dom
. Done in constant time.
length(dom::BoolDomain)
Return the size of dom
. Done in constant time.
length(dom::IntDomainView)
Return the size of dom
.
length(dom::BoolDomainView)
Return the size of dom
.
length(dom::IntDomain)
Return the size of dom
. Done in constant time.
Base.length(set::SetModification)
a generic function length is needed for all modifications.
Base.in
— MethodBase.in(value::Int, dom::IntDomain)
Check if an integer is in the domain. Done in constant time.
SeaPearl.remove!
— Functionremove!(dom::IntDomain, value::Int)
Remove value
from dom
. Done in constant time.
remove!(dom::BoolDomain, value::Bool)
Remove value
from dom
. Done in constant time.
remove!(dom::BoolDomain, value::Int)
Remove value
from dom
. Done in constant time.
remove!(dom::IntDomainView, value::Int)
Remove value
from dom
.
remove!(dom::BoolDomainViewNot, value::Bool)
Remove value
from dom
.
SeaPearl.removeAll!
— FunctionremoveAll!(dom::IntDomain)
Remove every value from dom
. Return the removed values. Done in constant time.
removeAll!(dom::BoolDomain)
Remove every value from dom
. Return the removed values. Done in constant time.
removeAll!(dom::IntDomainView)
Remove every value from dom
. Return the removed values.
removeAll!(dom::BoolDomainViewNot)
Remove every value from dom
. Return the removed values.
SeaPearl.removeAbove!
— FunctionremoveAbove!(dom::IntDomain, value::Int)
Remove every integer of dom
that is strictly above value
. Done in linear time.
removeAbove!(dom::IntDomain, value::Int)
Remove every integer of dom
that is strictly above value
. Done in linear time.
removeAbove!(dom::IntDomainView, value::Int)
Remove every integer of dom
that is strictly above value
.
SeaPearl.removeBelow!
— FunctionremoveBelow!(dom::IntDomain, value::Int)
Remove every integer of dom
that is strictly below value
. Return the pruned values. Done in linear time.
removeBelow!(dom::IntDomain, value::Int)
Remove every integer of dom
that is strictly below value
. Return the pruned values. Done in linear time.
removeBelow!(dom::IntDomainView, value::Int)
Remove every integer of dom
that is strictly below value
. Return the pruned values.
SeaPearl.assign!
— Functionassign!(dom::IntDomain, value::Int)
Remove everything from the domain but value
. Return the removed values. Return the pruned values. Done in constant time.
assign!(x::AbstractIntVar, value::Int)
Remove everything from the domain of x
but value
.
assign!(dom::BoolDomain, value::Bool)
Remove everything from the domain but value
. Return the removed values. Return the pruned values. Done in constant time.
assign!(dom::BoolDomain, value::Int)
Remove everything from the domain but value
. Return the removed values. Return the pruned values. Done in constant time.
assign!(x::BoolVar, value::Bool)
Remove everything from the domain of x
but value
.
assign!(dom::IntDomainView, value::Int)
Remove everything from the domain but value
. Return the removed values. Return the pruned values.
assign!(dom::BoolDomainViewNot, value::Bool)
Remove everything from the domain but value
. Return the removed values. Return the pruned values.
Base.iterate
— MethodBase.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.
SeaPearl.updateMaxFromRemovedVal!
— FunctionupdateMaxFromRemovedVal!(dom::IntDomain, v::Int)
Knowing that v
just got removed from dom
, update dom
's maximum value. Done in constant time.
updateMaxFromRemovedVal!(dom::IntDomainView, v::Int)
Knowing that v
just got removed from dom
, update dom
's maximum value.
SeaPearl.updateMinFromRemovedVal!
— FunctionupdateMinFromRemovedVal!(dom::IntDomain, v::Int)
Knowing that v
just got removed from dom
, update dom
's minimum value. Done in constant time.
updateMinFromRemovedVal!(dom::IntDomainView, v::Int)
Knowing that v
just got removed from dom
, update dom
's minimum value.
SeaPearl.updateBoundsFromRemovedVal!
— FunctionupdateBoundsFromRemovedVal!(dom::AbstractIntDomain, v::Int)
Knowing that v
just got removed from dom
, update dom
's minimum and maximum value. Done in constant time.
SeaPearl.minimum
— Functionminimum(dom::IntDomain)
Return the minimum value of dom
. Done in constant time.
minimum(dom::BoolDomain)
Return the minimum value of dom
. Done in constant time.
minimum(dom::IntDomainView)
Return the minimum value of dom
.
SeaPearl.maximum
— Functionmaximum(dom::IntDomain)
Return the maximum value of dom
. Done in constant time.
maximum(dom::BoolDomain)
Return the maximum value of dom
. Done in constant time.
maximum(dom::IntDomainView)
Return the maximum value of dom
.
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.IntVarViewMul
— TypeIntVarViewMul(x::AbstractIntVar, a::Int, id::String)
Create a fake variable y
, such that y == a*x
. This variable behaves like an usual one.
SeaPearl.IntVarViewOpposite
— TypeIntVarViewOpposite(x::AbstractIntVar, id::String)
Create a *fake* variable `y`, such that `y = -x`. This variable behaves like an usual one.
SeaPearl.IntVarViewOffset
— TypeIntVarViewOffset(x::AbstractIntVar, id::String)
Create a fake variable y
, such that y = x + c
. This variable behaves like an usual one.
IntDomainView
SeaPearl.IntDomainViewMul
— TypeIntDomainViewMul(orig::AbstractIntDomain, a::Int)
Domain for an integer variable that is a multiple of another integer variable. See IntVarViewMul.
SeaPearl.IntDomainViewOpposite
— TypeIntDomainViewOpposite(orig::AbstractIntDomain)
Domain for an integer variable that is the opposite of another integer variable (y = -x).
SeaPearl.IntDomainViewOffset
— TypeIntDomainViewOffset(orig::AbstractIntDomain, c::Int)
Domain for an integer variable that is offset by a constant 'c' (y = x + c)
Boolean Variables
Base Boolean Variables
SeaPearl.BoolVar
— Typestruct BoolVar <: AbstractVar
A "simple" boolean variable. The constraints that affect this variable are stored in the onDomainChange
array.
Boolean View Variables
SeaPearl.BoolVarViewNot
— TypeBoolVarViewNot(x::AbstractBoolVar, id::String)
Fake variable y
, such that y = ¬x
. This variable behaves like an usual one.
Boolean Domains
SeaPearl.BoolDomain
— Typestruct BoolDomain <: AbstractDomain
Boolean domain, uses a IntDomain in it. (true is 1 and false is 0)
SeaPearl.BoolDomainViewNot
— TypeBoolDomainViewNot <: BoolDomainView Domain for BoolVarView variables