- java.lang.Object
-
- org.chocosolver.solver.constraints.Constraint
-
- Direct Known Subclasses:
AllDifferent
,Arithmetic
,ClauseConstraint
,CostRegular
,Cumulative
,GlobalCardinality
,LocalConstructiveDisjunction
,Member
,NogoodConstraint
,NotMember
,Opposite
,RealConstraint
,ReificationConstraint
,SatConstraint
,SumConstraint
public class Constraint extends Object
A Constraint is basically a set ofPropagator
. It can either be posted or reified- Since:
- 0.01
- Version:
- major revision 13/01/2014
- Author:
- Jean-Guillaume Fages, Xavier Lorca, Charles Prud'homme
- See Also:
Variable
,Propagator
,PropagationEngine
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Constraint.Status
Status of this constraint wrt the model
-
Field Summary
Fields Modifier and Type Field Description protected BoolVar
boolReif
BoolVar that reifies this constraint, unique.protected Propagator[]
propagators
Propagators of the constraint (they will filter domains and eventually check solutions)
-
Constructor Summary
Constructors Constructor Description Constraint(String name, Propagator... propagators)
Make a new constraint defined as a set of given propagators
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
checkNewStatus(Constraint.Status aStatus)
Check if the new status is not in conflict with the current onePropagatorPriority
computeMaxPriority()
void
declareAs(Constraint.Status aStatus, int idx)
For internal usage only, declare the status of this constraint in the model and, if need be, its position in the constraint list.int
getCidxInModel()
String
getName()
Constraint
getOpposite()
Get the opposite constraint of this constraint.Propagator
getPropagator(int i)
Propagator[]
getPropagators()
Return an array which contains the propagators declared inthis
.Constraint.Status
getStatus()
void
ignore()
When a constraint has been declared but neither posted or reified, a call toignore()
ensures this constraint will be ignored when declared constraints are checked.boolean
isReified()
ESat
isSatisfied()
Test if thisConstraint
object is satisfied, regarding itsPropagators
and itsVariable
current domains.protected Constraint
makeOpposite()
Make the opposite constraint of this.static Constraint
merge(String name, Constraint... toMerge)
Creates a new constraint with all propagators of toMergevoid
post()
Posts the constraint to its model so that the constraint must be satisfied.BoolVar
reify()
Get/make the boolean variable indicating whether the constraint is satisfied or not This should not be posted.void
reifyWith(BoolVar bool)
Reifies the constraint with a boolean variable If the reified boolean variable already exists, an additional (equality) constraint is automatically posted.void
setName(String newName)
Changes the name ofthis
constraintprotected void
setOpposite(Constraint opp)
String
toString()
-
-
-
Field Detail
-
propagators
protected final Propagator[] propagators
Propagators of the constraint (they will filter domains and eventually check solutions)
-
boolReif
protected BoolVar boolReif
BoolVar that reifies this constraint, unique.
-
-
Constructor Detail
-
Constraint
public Constraint(String name, Propagator... propagators)
Make a new constraint defined as a set of given propagators- Parameters:
name
- name of the constraintpropagators
- set of propagators defining the constraint
-
-
Method Detail
-
getPropagators
public Propagator[] getPropagators()
Return an array which contains the propagators declared inthis
.- Returns:
- an array of
Propagator
.
-
getPropagator
public Propagator getPropagator(int i)
-
isSatisfied
public ESat isSatisfied()
Test if thisConstraint
object is satisfied, regarding itsPropagators
and itsVariable
current domains. This method is called on each solution as a checker when assertions are enabled (-ea in VM parameters) It is also called for constraint reification (to state whether or not a constraint is satisfied) The method calls entailment checks ofthis
propagators- Returns:
ESat.FALSE
if the constraint cannot be satisfied (from domain consideration),ESat.TRUE
if whatever future decisions are, the constraint will be satisfied for sure (without propagating domain modifications)ESat.UNDIFINED
otherwise (more decisions/filtering must be made before concluding about constraint satisfaction)
-
isReified
public final boolean isReified()
- Returns:
- true iff this constraint has been reified
-
reifyWith
public void reifyWith(BoolVar bool)
Reifies the constraint with a boolean variable If the reified boolean variable already exists, an additional (equality) constraint is automatically posted.- Parameters:
bool
- the variable to reify with
-
reify
public final BoolVar reify()
Get/make the boolean variable indicating whether the constraint is satisfied or not This should not be posted.- Returns:
- the boolean reifying the constraint
-
post
public final void post()
Posts the constraint to its model so that the constraint must be satisfied. This should not be reified.
-
ignore
public final void ignore()
When a constraint has been declared but neither posted or reified, a call toignore()
ensures this constraint will be ignored when declared constraints are checked.
-
declareAs
public final void declareAs(Constraint.Status aStatus, int idx) throws SolverException
For internal usage only, declare the status of this constraint in the model and, if need be, its position in the constraint list.- Parameters:
aStatus
- status of this constraint in the modelidx
- position of this constraint in the constraint list.- Throws:
SolverException
- if the constraint a incoherent status is declared
-
checkNewStatus
public final void checkNewStatus(Constraint.Status aStatus) throws SolverException
Check if the new status is not in conflict with the current one- Parameters:
aStatus
- new status of the constraint- Throws:
SolverException
- if the constraint a incoherent status is declared
-
getStatus
public final Constraint.Status getStatus()
- Returns:
- the
Constraint.Status
of this constraint
-
getCidxInModel
public int getCidxInModel()
- Returns:
- the position of this constraint in the model
-
getOpposite
public Constraint getOpposite()
Get the opposite constraint of this constraint. At first call, it creates the opposite constraint, links them together (the opposite constraint of this opposite constraint is this constraint) and returns the opposite. Next calls will return the previously created opposite constraint. In other words, there can be only one opposite per instance of constraint. The default opposite constraint does not filter domains but fails if this constraint is satisfied.- Returns:
- the opposite constraint of this
-
setOpposite
protected void setOpposite(Constraint opp)
-
makeOpposite
protected Constraint makeOpposite()
Make the opposite constraint of this. BEWARE: this method should never be called by the user but it can be overridden to provide better constraint negations
-
setName
public void setName(String newName)
Changes the name ofthis
constraint- Parameters:
newName
- the name of the constraint
-
getName
public String getName()
- Returns:
- the name of
this
constraint
-
computeMaxPriority
public PropagatorPriority computeMaxPriority()
- Returns:
- the maximum priority of a propagator of this constraint
-
merge
public static Constraint merge(String name, Constraint... toMerge)
Creates a new constraint with all propagators of toMerge- Parameters:
name
- name of the new constrainttoMerge
- a set of constraints to merge in this- Returns:
- a new constraint with all propagators of toMerge
-
-