Class Constraint
- java.lang.Object
-
- org.chocosolver.solver.constraints.Constraint
-
- Direct Known Subclasses:
AllDifferent,Arithmetic,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 classConstraint.StatusStatus of this constraint wrt the model
-
Field Summary
Fields Modifier and Type Field Description protected BoolVarboolReifBoolVar that reifies this constraint, unique.protected Propagator[]propagatorsPropagators 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 voidcheckNewStatus(Constraint.Status aStatus)Check if the new status is not in conflict with the current onePropagatorPrioritycomputeMaxPriority()voiddeclareAs(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.intgetCidxInModel()StringgetName()ConstraintgetOpposite()Get the opposite constraint of this constraint.PropagatorgetPropagator(int i)Propagator[]getPropagators()Return an array which contains the propagators declared inthis.Constraint.StatusgetStatus()booleanisReified()ESatisSatisfied()Test if thisConstraintobject is satisfied, regarding itsPropagatorsand itsVariablecurrent domains.protected ConstraintmakeOpposite()Make the opposite constraint of this.static Constraintmerge(String name, Constraint... toMerge)Creates a new constraint with all propagators of toMergevoidpost()Posts the constraint to its model so that the constraint must be satisfied.BoolVarreify()Get/make the boolean variable indicating whether the constraint is satisfied or not This should not be posted.voidreifyWith(BoolVar bool)Reifies the constraint with a boolean variable If the reified boolean variable already exists, an additional (equality) constraint is automatically posted.voidsetName(String newName)Changes the name ofthisconstraintprotected voidsetOpposite(Constraint opp)StringtoString()
-
-
-
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 thisConstraintobject is satisfied, regarding itsPropagatorsand itsVariablecurrent 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 ofthispropagators- Returns:
ESat.FALSEif the constraint cannot be satisfied (from domain consideration),ESat.TRUEif whatever future decisions are, the constraint will be satisfied for sure (without propagating domain modifications)ESat.UNDIFINEDotherwise (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.
-
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.Statusof 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 ofthisconstraint- Parameters:
newName- the name of the constraint
-
getName
public String getName()
- Returns:
- the name of
thisconstraint
-
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
-
-