Package org.jacop.constraints
Class Constraint
- java.lang.Object
-
- org.jacop.constraints.DecomposedConstraint<Constraint>
-
- org.jacop.constraints.Constraint
-
- Direct Known Subclasses:
AbsPeqR
,AdiffBeqC
,AdisjointB
,AintersectBeqC
,Alldifferent
,Alldistinct
,Among
,AmongVar
,ArgMax
,ArgMin
,Assignment
,AunionBeqC
,Binpacking
,CardA
,CardAeqX
,Conditional
,CosPeqR
,Count
,CountBounds
,Cumulative
,CumulativeBasic
,CumulativePrimary
,Diff
,Element
,ElementFloat
,ElementFloatVariable
,ElementInteger
,ElementIntegerFast
,ElementSet
,ElementSetVariable
,ElementVariable
,ElementVariableFast
,EquationSystem
,ExpPeqR
,ExtensionalConflictVA
,ExtensionalSupportMDD
,ExtensionalSupportSTR
,ExtensionalSupportVA
,GCC
,Geost
,Knapsack
,Lex
,LexOrder
,Linear
,Match
,Max
,Max
,MaxSimple
,Min
,Min
,MinSimple
,NetworkFlow
,NoGood
,Nooverlap
,PmulCeqR
,PmulQeqR
,PrimitiveConstraint
,Regular
,SatWrapper
,SimpleTable
,SinPeqR
,Sum
,SumWeight
,SumWeightDom
,SumWeightedSet
,Table
,TanPeqR
,ValuePrecede
,Values
,VariableTrace
,XdivYeqZ
,XeqP
,XexpYeqZ
,XmodYeqZ
,XmulYeqZ
public abstract class Constraint extends DecomposedConstraint<Constraint>
Standard unified interface/abstract class for all constraints.Defines how to construct a constraint, impose, check satisfiability, notSatisfiability, enforce consistency.
- Version:
- 4.7
-
-
Field Summary
Fields Modifier and Type Field Description (package private) float
afcWeight
Handling of AFC (accumulated failure fail) for constraintsboolean
atomicExecution
It specifies if the constraint consistency function requires consistency function executed in one atomic step.java.util.Hashtable<Var,java.lang.Integer>
consistencyPruningEvents
It specifies the event which must occur in order for the consistency function to be called.java.util.Set<PrimitiveConstraint>
constraintScope
boolean
earlyTerminationOK
It specifies if the constraint consistency function can be prematurely terminated through other than FailureException exception.boolean
increaseWeight
It specifies if upon the failure of the constraint, all variables in the constraint scope should have their weight increased.int
numberId
It specifies the number id for a given constraint.protected java.util.Set<Var>
scope
It specifies a set of variables that in the scope of this constraint.boolean
trace
(package private) Var
watchedVariableGrounded
-
Fields inherited from class org.jacop.constraints.DecomposedConstraint
queueIndex
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Constraint()
protected
Constraint(java.util.Set<? extends Var> set)
protected
Constraint(java.util.stream.Stream<Var> vars)
protected
Constraint(PrimitiveConstraint[] constraints)
protected
Constraint(Var[]... vars)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description float
afc()
java.util.Set<Var>
arguments()
It returns the variables in a scope of the constraint.void
cleanAfterFailure()
It is executed after the constraint has failed.private java.util.Set<RemoveLevelLate>
computeFixpoint(Constraint c, java.util.Set<RemoveLevelLate> fixpoint)
abstract void
consistency(Store store)
It is a (most probably incomplete) consistency function which removes the values from variables domains.java.util.List<Constraint>
decompose(Store store)
It returns an array list of constraint which are used to decompose this constraint.int
getConsistencyPruningEvent(Var var)
It retrieves the pruning event which causes reevaluation of the constraint.abstract int
getDefaultConsistencyPruningEvent()
Constraint
getGuideConstraint()
It specifies a constraint which if imposed by search will enhance propagation of this constraint.int
getGuideValue()
This function provides a value which if assigned to a variable returned by getGuideVariable() will enhance propagation of this constraint.Var
getGuideVariable()
This function provides a variable which assigned a value returned by will enhance propagation of this constraint.boolean
grounded()
It checks if the constraint has all variables in its scope grounded (singletons).boolean
grounded(Var[] vars)
It checks if provided variables are grounded (singletons).java.lang.String
id()
It gives the id string of a constraint.void
impose(Store store)
It imposes the constraint in a given store.void
impose(Store store, int queueIndex)
It imposes the constraint and adjusts the queue index.void
imposeDecomposition(Store store)
It imposes the decomposition of the given constraint in a given store.void
increaseWeight()
It increases the weight of the variables in the constraint scope.static java.lang.String
intArrayToString(int[] array)
(package private) int
long2int(long value)
int
numberArgs()
It returns the number of variables within a constraint scope.void
queueVariable(int level, Var var)
This is a function called to indicate which variable in a scope of constraint has changed.void
removeConstraint()
It removes the constraint by removing this constraint from all variables.boolean
requiresMonotonicity()
It specifies if the constraint allows domains of variables in its scope only to shrink its domain with the progress of search downwards.void
setConsistencyPruningEvent(Var var, int pruningEvent)
It allows to customize the event for a given variable which causes the re-execution of the consistency method for a constraint.protected void
setConstraintScope(PrimitiveConstraint... primitiveConstraints)
protected void
setScope(java.util.Set<? extends Var> set)
protected void
setScope(java.util.stream.Stream<Var> scope)
protected void
setScope(PrimitiveConstraint[] constraints)
protected void
setScope(Var... variables)
protected void
setScope(Var[]... variables)
void
setWatchedVariableGrounded(Var var)
void
supplyGuideFeedback(boolean feedback)
This function allows to provide a guide feedback.(package private) static int
toInt(double f)
(package private) static int
toInt(float f)
java.lang.String
toString()
It produces a string representation of a constraint state.void
updateAFC(java.util.Set<Constraint> allConstraints, float decay)
boolean
watchedVariableGrounded()
-
Methods inherited from class org.jacop.constraints.DecomposedConstraint
auxiliaryVariables, checkInput, checkInput, checkInputForDuplication, checkInputForDuplicationSkipSingletons, checkInputForNullness, checkInputForNullness, checkInputForNullness, derivative, getDubletonsSkipSingletons, imposeDecomposition
-
-
-
-
Field Detail
-
trace
public boolean trace
-
numberId
public int numberId
It specifies the number id for a given constraint. All constraints within the same type have unique number ids.
-
scope
protected java.util.Set<Var> scope
It specifies a set of variables that in the scope of this constraint.
-
constraintScope
public java.util.Set<PrimitiveConstraint> constraintScope
-
watchedVariableGrounded
Var watchedVariableGrounded
-
increaseWeight
public boolean increaseWeight
It specifies if upon the failure of the constraint, all variables in the constraint scope should have their weight increased.
-
consistencyPruningEvents
public java.util.Hashtable<Var,java.lang.Integer> consistencyPruningEvents
It specifies the event which must occur in order for the consistency function to be called.
-
earlyTerminationOK
public boolean earlyTerminationOK
It specifies if the constraint consistency function can be prematurely terminated through other than FailureException exception.
-
atomicExecution
public boolean atomicExecution
It specifies if the constraint consistency function requires consistency function executed in one atomic step. A constraint can specify that if any other pruning events are initiated by outside entity then the constraint may not work correctly if the execution is continued, but it will work well if consistency() function is restarted.
-
afcWeight
float afcWeight
Handling of AFC (accumulated failure fail) for constraints
-
-
Constructor Detail
-
Constraint
protected Constraint()
-
Constraint
protected Constraint(Var[]... vars)
-
Constraint
protected Constraint(java.util.stream.Stream<Var> vars)
-
Constraint
protected Constraint(PrimitiveConstraint[] constraints)
-
Constraint
protected Constraint(java.util.Set<? extends Var> set)
-
-
Method Detail
-
arguments
public java.util.Set<Var> arguments()
It returns the variables in a scope of the constraint.- Returns:
- variables in a scope of the constraint.
-
setScope
protected void setScope(Var... variables)
-
setScope
protected void setScope(Var[]... variables)
-
setScope
protected void setScope(java.util.stream.Stream<Var> scope)
-
setScope
protected void setScope(PrimitiveConstraint[] constraints)
-
setScope
protected void setScope(java.util.Set<? extends Var> set)
-
setConstraintScope
protected void setConstraintScope(PrimitiveConstraint... primitiveConstraints)
-
consistency
public abstract void consistency(Store store)
It is a (most probably incomplete) consistency function which removes the values from variables domains. Only values which do not have any support in a solution space are removed.- Parameters:
store
- constraint store within which the constraint consistency is being checked.
-
getConsistencyPruningEvent
public int getConsistencyPruningEvent(Var var)
It retrieves the pruning event which causes reevaluation of the constraint.- Parameters:
var
- variable for which pruning event is retrieved- Returns:
- it returns the int code of the pruning event (GROUND, BOUND, ANY, NONE)
-
getDefaultConsistencyPruningEvent
public abstract int getDefaultConsistencyPruningEvent()
-
id
public java.lang.String id()
It gives the id string of a constraint.- Returns:
- string id of the constraint.
-
impose
public void impose(Store store)
It imposes the constraint in a given store.- Parameters:
store
- the constraint store to which the constraint is imposed to.
-
computeFixpoint
private java.util.Set<RemoveLevelLate> computeFixpoint(Constraint c, java.util.Set<RemoveLevelLate> fixpoint)
-
impose
public void impose(Store store, int queueIndex)
It imposes the constraint and adjusts the queue index.- Parameters:
store
- the constraint store to which the constraint is imposed to.queueIndex
- the index of the queue in the store it is assigned to.
-
queueVariable
public void queueVariable(int level, Var var)
This is a function called to indicate which variable in a scope of constraint has changed. It also indicates a store level at which the change has occurred.- Parameters:
level
- the level of the store at which the change has occurred.var
- variable which has changed.
-
removeConstraint
public void removeConstraint()
It removes the constraint by removing this constraint from all variables.
-
setWatchedVariableGrounded
public void setWatchedVariableGrounded(Var var)
-
watchedVariableGrounded
public boolean watchedVariableGrounded()
-
grounded
public boolean grounded()
It checks if the constraint has all variables in its scope grounded (singletons).- Returns:
- true if all variables in constraint scope are singletons, false otherwise.
-
grounded
public boolean grounded(Var[] vars)
It checks if provided variables are grounded (singletons).- Parameters:
vars
- variables to be checked if they are grounded.- Returns:
- true if all variables in constraint scope are singletons, false otherwise.
-
toString
public java.lang.String toString()
It produces a string representation of a constraint state.- Overrides:
toString
in classjava.lang.Object
-
intArrayToString
public static java.lang.String intArrayToString(int[] array)
-
getGuideConstraint
public Constraint getGuideConstraint()
It specifies a constraint which if imposed by search will enhance propagation of this constraint.- Returns:
- Constraint enhancing propagation of this constraint.
-
getGuideVariable
public Var getGuideVariable()
This function provides a variable which assigned a value returned by will enhance propagation of this constraint.- Returns:
- Variable which is a base of enhancing constraint.
-
getGuideValue
public int getGuideValue()
This function provides a value which if assigned to a variable returned by getGuideVariable() will enhance propagation of this constraint.- Returns:
- Value which is a base of enhancing constraint.
-
supplyGuideFeedback
public void supplyGuideFeedback(boolean feedback)
This function allows to provide a guide feedback. If constraint does not propose sufficiently good enhancing constraints it will be informed so it has a chance to reexamine its efforts.- Parameters:
feedback
- true if the guide was useful, false otherwise.
-
increaseWeight
public void increaseWeight()
It increases the weight of the variables in the constraint scope.
-
setConsistencyPruningEvent
public void setConsistencyPruningEvent(Var var, int pruningEvent)
It allows to customize the event for a given variable which causes the re-execution of the consistency method for a constraint.- Parameters:
var
- variable for which the events are customized.pruningEvent
- the event which must occur to trigger execution of the consistency method.
-
numberArgs
public int numberArgs()
It returns the number of variables within a constraint scope.- Returns:
- number of variables in the constraint scope.
-
requiresMonotonicity
public boolean requiresMonotonicity()
It specifies if the constraint allows domains of variables in its scope only to shrink its domain with the progress of search downwards.- Returns:
- true, by default by all constraints.
-
imposeDecomposition
public void imposeDecomposition(Store store)
It imposes the decomposition of the given constraint in a given store.- Specified by:
imposeDecomposition
in classDecomposedConstraint<Constraint>
- Parameters:
store
- the constraint store to which the constraint is imposed to.
-
decompose
public java.util.List<Constraint> decompose(Store store)
It returns an array list of constraint which are used to decompose this constraint. It actually creates a decomposition (possibly also creating variables), but it does not impose the constraint.- Specified by:
decompose
in classDecomposedConstraint<Constraint>
- Parameters:
store
- the constraint store in which context the decomposition takes place.- Returns:
- an array list of constraints used to decompose this constraint.
-
afc
public float afc()
-
updateAFC
public void updateAFC(java.util.Set<Constraint> allConstraints, float decay)
-
cleanAfterFailure
public void cleanAfterFailure()
It is executed after the constraint has failed. It allows to clean some data structures.
-
toInt
static int toInt(float f)
-
toInt
static int toInt(double f)
-
long2int
int long2int(long value)
-
-