public class Constraints extends Object
Modifier and Type | Method and Description |
---|---|
static solver.constraints.Constraint |
acyclic(solver.variables.IntVar... edges)
A constraint enforcing no cycles.
|
static solver.constraints.Constraint |
and(solver.variables.BoolVar... operands)
A constraint enforcing
{@code operands[0] ∧ operands[1] ∧ ...
|
static solver.constraints.Constraint |
arrayToSet(solver.variables.IntVar[] ivars,
solver.variables.SetVar svar,
solver.variables.IntVar svarCard)
A constraint enforcing
{ivar[0], ivar[1], ..., ivar[n]} = svar . |
static solver.constraints.Constraint |
arrayToSet(solver.variables.IntVar[] ivars,
solver.variables.SetVar svar,
solver.variables.IntVar svarCard,
Integer globalCardinality)
A constraint enforcing
{ivar[0], ivar[1], ..., ivar[n]} = svar
and for all constant k, |{i | ivar[i] = k}| ≤ globalCardinality . |
static solver.constraints.Constraint |
difference(solver.variables.SetVar minuend,
solver.variables.IntVar minuendCard,
solver.variables.SetVar subtrahend,
solver.variables.IntVar subtrahendCard,
solver.variables.SetVar difference,
solver.variables.IntVar differenceCard)
A constraint enforcing
minuend - subtrahend = difference . |
static solver.constraints.Constraint |
equal(solver.variables.SetVar set1,
solver.variables.IntVar set1Card,
solver.variables.SetVar set2,
solver.variables.IntVar set2Card)
A constraint enforcing
set1 = set2 . |
static solver.constraints.Constraint |
filterString(solver.variables.SetVar set,
solver.variables.IntVar setCard,
int offset,
solver.variables.IntVar[] string,
solver.variables.IntVar[] result)
A constraint enforcing
result[i] = if i < array(set).length then string[array(set)[i] - offset] else -1
where array is the sorted array representation of the set. |
static solver.constraints.Constraint |
ifThenElse(solver.variables.BoolVar antecedent,
solver.variables.BoolVar consequent,
solver.variables.BoolVar alternative)
A constraint enforcing
antecedent => consequent && !antecedent => alternative . |
static solver.constraints.Constraint |
intChannel(solver.variables.SetVar[] sets,
solver.variables.IntVar[] ints)
A constraint enforcing
x ∈ sets[i] <=> ints[x] = i . |
static solver.constraints.Constraint |
intersection(solver.variables.SetVar[] operands,
solver.variables.IntVar[] operandCards,
solver.variables.SetVar intersection,
solver.variables.IntVar intersectionCard)
A constraint enforcing
{@code operands[0] ∩ operands[1] ∩ ...
|
static solver.constraints.Constraint |
joinFunction(solver.variables.SetVar take,
solver.variables.IntVar takeCard,
solver.variables.IntVar[] refs,
solver.variables.SetVar to,
solver.variables.IntVar toCard)
A constraint enforcing
take.refs = to where refs is a function. |
static solver.constraints.Constraint |
joinFunction(solver.variables.SetVar take,
solver.variables.IntVar takeCard,
solver.variables.IntVar[] refs,
solver.variables.SetVar to,
solver.variables.IntVar toCard,
Integer globalCardinality)
A constraint enforcing
take.refs = to where refs is a function
and for all k in take, |{i | refs[i] = k}| ≤ globalCardinality . |
static solver.constraints.Constraint |
joinInjectiveRelation(solver.variables.SetVar take,
solver.variables.IntVar takeCard,
solver.variables.SetVar[] children,
solver.variables.IntVar[] childrenCards,
solver.variables.SetVar to,
solver.variables.IntVar toCard)
A constraint enforcing
take.children = to where children is an
injective relation. |
static solver.constraints.Constraint |
joinRelation(solver.variables.SetVar take,
solver.variables.SetVar[] children,
solver.variables.SetVar to)
Deprecated.
|
static solver.constraints.Constraint |
lexChainChannel(solver.variables.IntVar[][] strings,
solver.variables.IntVar[] ints)
A constraint enforcing
strings[i] ≤ strings[j] <=> ints[i] ≤ ints[j] and
strings[i] = strings[j] <=> ints[i] = ints[j] . |
static solver.constraints.Constraint |
lone(solver.variables.BoolVar... operands)
A constraint enforcing
{@code operands[0] + operands[1] + ...
|
static solver.constraints.Constraint |
mask(solver.variables.SetVar set,
solver.variables.IntVar setCard,
solver.variables.SetVar masked,
solver.variables.IntVar maskedCard,
int from,
int to)
A constraint enforcing
{i + from | i ∈ member} = set ∩ {from, from + 1, ..., to - 1} . |
static solver.constraints.Constraint |
notEqual(solver.variables.SetVar set,
int[] constant)
A constraint enforcing
set ≠ {constant} . |
static solver.constraints.Constraint |
notEqual(solver.variables.SetVar set1,
solver.variables.IntVar set1Card,
solver.variables.SetVar set2,
solver.variables.IntVar set2Card)
A constraint enforcing
set1 ≠ set2 . |
static solver.constraints.Constraint |
notMember(solver.variables.IntVar element,
solver.variables.SetVar set)
A constraint enforcing
element ∉ set . |
static solver.constraints.Constraint |
one(solver.variables.BoolVar... operands)
A constraint enforcing
{@code operands[0] + operands[1] + ...
|
static solver.constraints.Constraint |
or(solver.variables.BoolVar... operands)
A constraint enforcing
{@code operands[0] ∨ operands[1] ∨ ...
|
static solver.constraints.Constraint |
or(solver.constraints.Constraint... constraints)
A constraint enforcing
{@code constraints[0] ∨ constraints[1] ∨ ...
|
static solver.constraints.Constraint |
reifyEqual(solver.variables.BoolVar reify,
solver.variables.IntVar variable,
int constant)
A constraint enforcing
reify <=> (variable = constant) . |
static solver.constraints.Constraint |
reifyEqual(solver.variables.BoolVar reify,
solver.variables.IntVar v1,
solver.variables.IntVar v2)
A constraint enforcing
reify <=> (v1 = v2) . |
static solver.constraints.Constraint |
reifyNotEqual(solver.variables.BoolVar reify,
solver.variables.IntVar variable,
int constant)
A constraint enforcing
reify <=> (variable ≠ constant) . |
static solver.constraints.Constraint |
reifyNotEqual(solver.variables.BoolVar reify,
solver.variables.IntVar v1,
solver.variables.IntVar v2)
A constraint enforcing
reify <=> (v1 ≠ v2) . |
static solver.constraints.Constraint |
selectN(solver.variables.BoolVar[] bools,
solver.variables.IntVar n)
A constraint enforcing that
bools[i] <=> i < n . |
static solver.constraints.Constraint |
setSum(solver.variables.SetVar set,
solver.variables.IntVar setCard,
solver.variables.IntVar sum)
A constraint enforcing
Σ set= sum . |
static solver.constraints.Constraint |
singleton(solver.variables.IntVar ivar,
solver.variables.SetVar svar)
A constraint enforcing
{ivar} = svar . |
static solver.constraints.Constraint |
singleton(solver.variables.IntVar ivar,
solver.variables.SetVar svar,
solver.variables.IntVar svarCard)
A constraint enforcing
{ivar} = svar and svarCard = 1 . |
static solver.constraints.Constraint |
sortedSets(solver.variables.SetVar[] sets,
solver.variables.IntVar[] setCards)
A constraint enforcing
{@code array(sets[0]) ++ array(sets[1]) ++ ...
|
static solver.constraints.Constraint |
subsetEq(solver.variables.SetVar sub,
solver.variables.IntVar subCard,
solver.variables.SetVar sup,
solver.variables.IntVar supCard)
A constraint enforcing
sub ⊆ sup . |
static solver.constraints.Constraint |
union(solver.variables.SetVar[] operands,
solver.variables.IntVar[] operandCards,
solver.variables.SetVar union,
solver.variables.IntVar unionCard,
boolean disjoint)
A constraint enforcing
{@code operands[0] ∪ operands[1] ∪ ...
|
static solver.constraints.Constraint |
unreachable(solver.variables.IntVar[] edges,
int from,
int to)
A constraint enforcing no path from one node to another.
|
public static solver.constraints.Constraint and(solver.variables.BoolVar... operands)
operands[0] ∧ operands[1] ∧ ... ∧ operands[n]
.operands
- the operandsoperands[0] ∧ operands[1] ∧ ... ∧ operands[n]
public static solver.constraints.Constraint lone(solver.variables.BoolVar... operands)
operands[0] + operands[1] + ... + operands[n] ≤ 1
.operands
- the operandsoperands[0] + operands[1] + ... + operands[n] ≤ 1
public static solver.constraints.Constraint one(solver.variables.BoolVar... operands)
operands[0] + operands[1] + ... + operands[n] = 1
.operands
- the operandsoperands[0] + operands[1] + ... + operands[n] = 1
public static solver.constraints.Constraint or(solver.variables.BoolVar... operands)
operands[0] ∨ operands[1] ∨ ... ∨ operands[n]
.operands
- the operandsoperands[0] ∨ operands[1] ∨ ... ∨ operands[n]
public static solver.constraints.Constraint or(solver.constraints.Constraint... constraints)
constraints[0] ∨ constraints[1] ∨ ... ∨ constraints[n]
. The
reason this constraint is useful is because it does not require
introducing new reified variables to the solver thus can be added
dynamically while the solver is in progress.constraints
- the constraintsconstraints[0] ∨ constraints[1] ∨ ... ∨ constraints[n]
public static solver.constraints.Constraint ifThenElse(solver.variables.BoolVar antecedent, solver.variables.BoolVar consequent, solver.variables.BoolVar alternative)
antecedent => consequent && !antecedent => alternative
.antecedent
- the antecedentconsequent
- the consequentalternative
- the alternativeantecedent => consequent && !antecedent => alternative
public static solver.constraints.Constraint reifyEqual(solver.variables.BoolVar reify, solver.variables.IntVar variable, int constant)
reify <=> (variable = constant)
.reify
- the reified constraintvariable
- the variableconstant
- the constantreify <=> (variable = constant)
public static solver.constraints.Constraint reifyEqual(solver.variables.BoolVar reify, solver.variables.IntVar v1, solver.variables.IntVar v2)
reify <=> (v1 = v2)
.reify
- the reified constraintv1
- the first variablev2
- the second variablereify <=> (v1 = v2)
public static solver.constraints.Constraint reifyNotEqual(solver.variables.BoolVar reify, solver.variables.IntVar variable, int constant)
reify <=> (variable ≠ constant)
.reify
- the reified constraintvariable
- the variableconstant
- the constantreify <=> (variable ≠ constant)
public static solver.constraints.Constraint reifyNotEqual(solver.variables.BoolVar reify, solver.variables.IntVar v1, solver.variables.IntVar v2)
reify <=> (v1 ≠ v2)
.reify
- the reified constraintv1
- the first variablev2
- the second variablereify <=> (v1 ≠ v2)
public static solver.constraints.Constraint equal(solver.variables.SetVar set1, solver.variables.IntVar set1Card, solver.variables.SetVar set2, solver.variables.IntVar set2Card)
set1 = set2
. Does not enforce that
set1Card = |set1Card|
nor set2Card = |set2Card|
because
of how the compilation works, it is already enforced elsewhere.set1
- the left setset1Card
- the cardinality of set1
set2
- the right setset2Card
- the cardinality of set2
set1 = set2
public static solver.constraints.Constraint notEqual(solver.variables.SetVar set1, solver.variables.IntVar set1Card, solver.variables.SetVar set2, solver.variables.IntVar set2Card)
set1 ≠ set2
.set1
- the left setset1Card
- the cardinality of set1
set2
- the right setset2Card
- the cardinality of set2
set1 ≠ set2
public static solver.constraints.Constraint notEqual(solver.variables.SetVar set, int[] constant)
set ≠ {constant}
.set
- the setconstant
- the constantset1 ≠ set2
public static solver.constraints.Constraint notMember(solver.variables.IntVar element, solver.variables.SetVar set)
element ∉ set
.element
- the elementset
- the setelement ∉ set
.public static solver.constraints.Constraint subsetEq(solver.variables.SetVar sub, solver.variables.IntVar subCard, solver.variables.SetVar sup, solver.variables.IntVar supCard)
sub ⊆ sup
. Does not enforce that
subCard = |sub|
nor supCard = |sup|
because of how the
compilation works, it is already enforced elsewhere.sub
- the subsetsubCard
- the cardinality of sub
sup
- the supersetsupCard
- the cardinality of sup
sub ⊆ sup
public static solver.constraints.Constraint intChannel(solver.variables.SetVar[] sets, solver.variables.IntVar[] ints)
x ∈ sets[i] <=> ints[x] = i
.sets
- the setsints
- the integersx ∈ sets[i] <=> ints[x] = i
public static solver.constraints.Constraint sortedSets(solver.variables.SetVar[] sets, solver.variables.IntVar[] setCards)
array(sets[0]) ++ array(sets[1]) ++ ... ++ array(sets[n]) ∈ N
where array
is the sorted array representation of the set,
++
is append, and N = {[0,1,...,i] | i ≥ 0}
.sets
- the setssetCards
- the cardinalities of sets
array(sets[0]) ++ array(sets[1]) ++ ... ++ array(sets[n]) ∈ N
public static solver.constraints.Constraint lexChainChannel(solver.variables.IntVar[][] strings, solver.variables.IntVar[] ints)
strings[i] ≤ strings[j] <=> ints[i] ≤ ints[j]
and
strings[i] = strings[j] <=> ints[i] = ints[j]
.strings
- the stringsints
- the integersstrings[i] ≤ strings[j] <=> ints[i] ≤ ints[j]
and strings[i] = strings[j] <=> ints[i] = ints[j]
public static solver.constraints.Constraint selectN(solver.variables.BoolVar[] bools, solver.variables.IntVar n)
bools[i] <=> i < n
.bools
- the booleansn
- the number of true booleansbools[i] <=> i < n
public static solver.constraints.Constraint acyclic(solver.variables.IntVar... edges)
edges[i] = j
implies that there
is a directed edge from node i to node j. edges[i] = edges.length
implies that there are no direct edges from node i.edges
- the edges of the graphpublic static solver.constraints.Constraint unreachable(solver.variables.IntVar[] edges, int from, int to)
edges[i] = j
implies that there is a directed edge from node i to
node j. edges[i] ≥ edges.length
implies that there are no direct
edges from node i.edges
- the edges of the graphpublic static solver.constraints.Constraint filterString(solver.variables.SetVar set, solver.variables.IntVar setCard, int offset, solver.variables.IntVar[] string, solver.variables.IntVar[] result)
result[i] = if i < array(set).length then string[array(set)[i] - offset] else -1
where array
is the sorted array representation of the set. Does
not enforce that setCard = |setCard|
because of how the
compilation works, it is already enforced elsewhere.set
- the setsetCard
- the cardinality of set
offset
- the offsetstring
- the stringresult
- the resultresult[i] = if i < array(set).length then string[array(set)[i] - offset] else -1
public static solver.constraints.Constraint setSum(solver.variables.SetVar set, solver.variables.IntVar setCard, solver.variables.IntVar sum)
A constraint enforcing Σ set= sum
. Does not enforce that
sumCard = |sum|
because of how the compilation works, it is
already enforced elsewhere.
More * efficient than the standard operation in the Choco library when the cardinality is bounded to be relatively small.
For example:
Animal 2 Age -> integer [Animal.Age = 1000]
Animal.Age
is a set with a very large envelope. However, due
to static analysis of the model, it is easy to see that the cardinality
must be 2. In general, the cardinality is bounded by the scope of Age,
although often times the analysis will find a tighter bound. Once the
first integer x is selected for the set, the second integer 1000 - x is
already determined due to cardinality = 2. Since the Choco library's
setSum constraint is not given the cardinality, it cannot make this
deduction.
set
- the set of integerssetCard
- the cardinality of set
sum
- the sum of the setΣ set= sum
public static solver.constraints.Constraint singleton(solver.variables.IntVar ivar, solver.variables.SetVar svar)
{ivar} = svar
.ivar
- the integersvar
- the singleton set{ivar} = svar
public static solver.constraints.Constraint singleton(solver.variables.IntVar ivar, solver.variables.SetVar svar, solver.variables.IntVar svarCard)
{ivar} = svar
and svarCard = 1
.
Does not enforce that svarCard = |svarCard|
because of how the
compilation works, it is already enforced elsewhere.ivar
- the integersvar
- the singleton setsvarCard
- the cardinality of svar
{ivar} = svar
public static solver.constraints.Constraint arrayToSet(solver.variables.IntVar[] ivars, solver.variables.SetVar svar, solver.variables.IntVar svarCard)
{ivar[0], ivar[1], ..., ivar[n]} = svar
.ivars
- the arraysvar
- the setsvarCard
- the cardinality of svar
{ivar[0], ivar[1], ..., ivar[n]} = svar
public static solver.constraints.Constraint arrayToSet(solver.variables.IntVar[] ivars, solver.variables.SetVar svar, solver.variables.IntVar svarCard, Integer globalCardinality)
{ivar[0], ivar[1], ..., ivar[n]} = svar
and for all constant k, |{i | ivar[i] = k}| ≤ globalCardinality
.
Does not enforce that svarCard = |svar|
because of how the
compilation works, it is already enforced elsewhere.ivars
- the arraysvar
- the setsvarCard
- the cardinality of svar
globalCardinality
- the global cardinality of the array elements{ivar[0], ivar[1], ..., ivar[n]} = svar
and
for all constant k |{i | ivar[i] = k}| ≤ globalCardinality
@Deprecated public static solver.constraints.Constraint joinRelation(solver.variables.SetVar take, solver.variables.SetVar[] children, solver.variables.SetVar to)
public static solver.constraints.Constraint joinInjectiveRelation(solver.variables.SetVar take, solver.variables.IntVar takeCard, solver.variables.SetVar[] children, solver.variables.IntVar[] childrenCards, solver.variables.SetVar to, solver.variables.IntVar toCard)
take.children = to
where children is an
injective relation. The representation of the relation is explained in
PropJoinRelation
. Does not enforce that the children relation is
injective nor takeCard = |take|
nor
childrenCards[i] = |children[i]|
nor toCard = |to|
because of how the compilation works, it is already enforced elsewhere.take
- the left-hand side settakeCard
- the cardinality of take
children
- the set representation of a injective binary relationchildrenCards
- the cardinalities of children
to
- the right-hand side settoCard
- the cardinality of to
take.children = to
PropJoinFunction
public static solver.constraints.Constraint joinFunction(solver.variables.SetVar take, solver.variables.IntVar takeCard, solver.variables.IntVar[] refs, solver.variables.SetVar to, solver.variables.IntVar toCard)
take.refs = to
where refs is a function.
The representation of the function is explained in
PropJoinFunction
. Does not enforce that takeCard = |take|
nor toCard = |to|
because of how the compilation works, it is
already enforced elsewhere.take
- the left-hand side settakeCard
- the cardinality of take
refs
- the integer representation of a binary functionto
- the right-hand side settoCard
- the cardinality of to
take.refs = to
PropJoinFunction
public static solver.constraints.Constraint joinFunction(solver.variables.SetVar take, solver.variables.IntVar takeCard, solver.variables.IntVar[] refs, solver.variables.SetVar to, solver.variables.IntVar toCard, Integer globalCardinality)
take.refs = to
where refs is a function
and for all k in take, |{i | refs[i] = k}| ≤ globalCardinality
.
The representation of the function is explained in
PropJoinFunction
. Does not enforce that takeCard = |take|
nor toCard = |to|
because of how the compilation works, it is
already enforced elsewhere.take
- the left-hand side settakeCard
- the cardinality of take
refs
- the integer representation of a binary functionto
- the right-hand side settoCard
- the cardinality of to
globalCardinality
- the global cardinality of the refs
function for the domain of take
take.refs = to
and
for all k in take, |{i | refs[i] = k}| ≤ globalCardinality
PropJoinFunction
public static solver.constraints.Constraint difference(solver.variables.SetVar minuend, solver.variables.IntVar minuendCard, solver.variables.SetVar subtrahend, solver.variables.IntVar subtrahendCard, solver.variables.SetVar difference, solver.variables.IntVar differenceCard)
minuend - subtrahend = difference
. Does
not enforce that minuendCard = |minuend|
nor
subtrahendCard = |subtrahend|
nor
differenceCard = |difference|
because of how the compilation
works, it is already enforced elsewhere.minuend
- the minuendminuendCard
- the cardinality of minuend
subtrahend
- the subtrahendsubtrahendCard
- the cardinality of subtrahend
difference
- the differencedifferenceCard
- the cardinality of difference
minuend - subtrahend = difference
public static solver.constraints.Constraint intersection(solver.variables.SetVar[] operands, solver.variables.IntVar[] operandCards, solver.variables.SetVar intersection, solver.variables.IntVar intersectionCard)
operands[0] ∩ operands[1] ∩ ... ∩ operands[n] = intersection
.
Does not enforce that operandCards[i] = |operands[i]|
nor
intersectionCard = |intersection|
because of how the compilation
works, it is already enforced elsewhere.operands
- the operandsoperandCards
- the cardinalities of operands
intersection
- the intersectionintersectionCard
- the cardinality of intersection
operands[0] ∩ operands[1] ∩ ... ∩ operands[n] = intersection
public static solver.constraints.Constraint union(solver.variables.SetVar[] operands, solver.variables.IntVar[] operandCards, solver.variables.SetVar union, solver.variables.IntVar unionCard, boolean disjoint)
operands[0] ∪ operands[1] ∪ ... ∪ operands[n] = union
. Does not
enforce that operandCards[i] = |operands[i]|
nor
unionCard = |union|
because of how the compilation works, it is
already enforced elsewhere.operands
- the operandsoperandCards
- the cardinalities of operands
union
- the unionunionCard
- the cardinality of union
disjoint
- the sets are disjointoperands[0] ∪ operands[1] ∪ ... ∪ operands[n] = union
public static solver.constraints.Constraint mask(solver.variables.SetVar set, solver.variables.IntVar setCard, solver.variables.SetVar masked, solver.variables.IntVar maskedCard, int from, int to)
{i + from | i ∈ member} = set ∩ {from, from + 1, ..., to - 1}
.
Does not enforce that setCard = |set|
nor
maskedCard = |masked|
because of how the compilation works, it is
already enforced elsewhere.set
- the setsetCard
- the cardinality of set
masked
- the masked setmaskedCard
- the cardinality of masked
from
- the inclusive start of the maskto
- the exclusive end of the mask{i + from | i ∈ member} = set ∩ {from, from + 1, ..., to - 1}
Copyright © 2013. All Rights Reserved.