Package org.jacop.constraints
Class Alldistinct
- java.lang.Object
-
- org.jacop.constraints.DecomposedConstraint<Constraint>
-
- org.jacop.constraints.Constraint
-
- org.jacop.constraints.Alldistinct
-
- All Implemented Interfaces:
SatisfiedPresent,Stateful,UsesQueueVariable
public class Alldistinct extends Constraint implements UsesQueueVariable, Stateful, SatisfiedPresent
Alldistinct constraint assures that all FDVs have different values.This implementation is based on Regin paper. It uses slightly modified Hopcroft-Karp algorithm to compute maximum matching. The value graph is analysed and Tarjan algorithm for finding strongly connected components is used. Maximum matching and Value Graph is stored as TimeStamp Mutable variables to minimize recomputation. Value graph is expensive in terms of memory usage. Use this constraint with care. One variable with domain 0..1000000 will make it use few MB already and kill the efficiency.
- Version:
- 4.8
-
-
Field Summary
Fields Modifier and Type Field Description (package private) booleanbacktrackOccuredintconsistencyChecksIt counts the number of executions of the consistency function.(package private) static booleandebugAll(package private) static booleandebugPruning(package private) java.util.LinkedHashSet<IntVar>freeVariablesintfullConsistencyPassesWithNarrowingEventIt computes how many times did consistency execution has been re-executed due to narrowing event at the end of the consistency function.(package private) booleangreedy(package private) intguideValue(package private) IntVarguideVariable(package private) static java.util.concurrent.atomic.AtomicIntegeridNumber(package private) booleanimpositionFailureIntVar[]listIt specifies all variables which have to have different values.(package private) java.util.Map<IntVar,TimeStamp<java.lang.Integer>>matching(package private) booleanmaximumMatchingNotRecomputed(package private) intn(package private) TimeStamp<java.lang.Integer>nStamp(package private) booleanpermutationConsistency(package private) java.lang.Integer[]potentialFreeValues(package private) java.util.Map<IntVar,java.lang.Integer>scc(package private) java.util.Map<IntVar,TimeStamp<java.lang.Integer>>sccStamp(package private) TimeStamp<java.lang.Integer>stampNotGroundedVariables(package private) TimeStamp<java.lang.Integer>stampReachability(package private) java.util.Map<java.lang.Integer,TimeStamp<java.lang.Integer>>stamps(package private) TimeStamp<java.lang.Integer>stampValues(package private) java.util.Map<java.lang.Integer,java.lang.Integer>valueIndex(package private) java.util.Map<java.lang.Integer,SimpleArrayList<IntVar>>valueMapVariable(package private) java.util.LinkedHashSet<IntVar>variableQueue(package private) intvn-
Fields inherited from class org.jacop.constraints.Constraint
afcWeight, atomicExecution, consistencyPruningEvents, constraintScope, earlyTerminationOK, increaseWeight, numberId, scope, trace, watchedVariableGrounded
-
Fields inherited from class org.jacop.constraints.DecomposedConstraint
queueIndex
-
-
Constructor Summary
Constructors Constructor Description Alldistinct(java.util.List<? extends IntVar> list)It constructs an alldistinct constraint.Alldistinct(IntVar[] list)It constructs an alldistinct constraint.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconsistency(Store store)It is a (most probably incomplete) consistency function which removes the values from variables domains.(package private) intestimatePruning(IntVar x, java.lang.Integer v)(package private) intestimatePruningRecursive(IntVar xVar, java.lang.Integer v, java.util.List<IntVar> exploredX, java.util.List<java.lang.Integer> exploredV)intgetDefaultConsistencyPruningEvent()ConstraintgetGuideConstraint()It specifies a constraint which if imposed by search will enhance propagation of this constraint.intgetGuideValue()This function provides a value which if assigned to a variable returned by getGuideVariable() will enhance propagation of this constraint.VargetGuideVariable()This function provides a variable which assigned a value returned by will enhance propagation of this constraint.private booleanhopcroftKarpMaximumMatching()voidimpose(Store store)It imposes the constraint in a given store.private voidmarkReachableVariables(java.util.LinkedHashSet<IntVar> variablesReachableFromFreeValues, java.lang.Integer value)voidqueueVariable(int level, Var var)This is a function called to indicate which variable in a scope of constraint has changed.voidremoveLevel(int level)This function is called in case of the backtrack, so a constraint can clear the queue of changed variables which is no longer valid.private voidrevisitTarjan(IntVar x, java.util.List<IntVar> l, java.util.Map<IntVar,java.lang.Integer> dfsnum, java.util.Map<IntVar,java.lang.Integer> low, java.util.LinkedHashSet<IntVar> fdvs)booleansatisfied()It checks if the constraint is satisfied.java.lang.StringtoString()It produces a string representation of a constraint state.private voidvisitTarjan(IntVar x, java.util.List<IntVar> l, java.util.Map<IntVar,java.lang.Integer> dfsnum, java.util.Map<IntVar,java.lang.Integer> low)-
Methods inherited from class org.jacop.constraints.Constraint
afc, arguments, cleanAfterFailure, decompose, getConsistencyPruningEvent, grounded, grounded, id, impose, imposeDecomposition, increaseWeight, intArrayToString, long2int, numberArgs, removeConstraint, requiresMonotonicity, setConsistencyPruningEvent, setConstraintScope, setScope, setScope, setScope, setScope, setScope, setWatchedVariableGrounded, supplyGuideFeedback, toInt, toInt, updateAFC, watchedVariableGrounded
-
Methods inherited from class org.jacop.constraints.DecomposedConstraint
auxiliaryVariables, checkInput, checkInput, checkInputForDuplication, checkInputForDuplicationSkipSingletons, checkInputForNullness, checkInputForNullness, checkInputForNullness, derivative, getDubletonsSkipSingletons, imposeDecomposition
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.jacop.api.Stateful
isStateful
-
-
-
-
Field Detail
-
debugAll
static final boolean debugAll
- See Also:
- Constant Field Values
-
debugPruning
static final boolean debugPruning
- See Also:
- Constant Field Values
-
idNumber
static java.util.concurrent.atomic.AtomicInteger idNumber
-
backtrackOccured
boolean backtrackOccured
-
consistencyChecks
public int consistencyChecks
It counts the number of executions of the consistency function.
-
fullConsistencyPassesWithNarrowingEvent
public int fullConsistencyPassesWithNarrowingEvent
It computes how many times did consistency execution has been re-executed due to narrowing event at the end of the consistency function.
-
freeVariables
java.util.LinkedHashSet<IntVar> freeVariables
-
impositionFailure
boolean impositionFailure
-
maximumMatchingNotRecomputed
boolean maximumMatchingNotRecomputed
-
n
int n
-
nStamp
TimeStamp<java.lang.Integer> nStamp
-
permutationConsistency
boolean permutationConsistency
-
potentialFreeValues
java.lang.Integer[] potentialFreeValues
-
scc
java.util.Map<IntVar,java.lang.Integer> scc
-
stampNotGroundedVariables
TimeStamp<java.lang.Integer> stampNotGroundedVariables
-
stampReachability
TimeStamp<java.lang.Integer> stampReachability
-
stamps
java.util.Map<java.lang.Integer,TimeStamp<java.lang.Integer>> stamps
-
stampValues
TimeStamp<java.lang.Integer> stampValues
-
valueIndex
java.util.Map<java.lang.Integer,java.lang.Integer> valueIndex
-
valueMapVariable
java.util.Map<java.lang.Integer,SimpleArrayList<IntVar>> valueMapVariable
-
variableQueue
java.util.LinkedHashSet<IntVar> variableQueue
-
vn
int vn
-
list
public IntVar[] list
It specifies all variables which have to have different values.
-
guideVariable
IntVar guideVariable
-
guideValue
int guideValue
-
greedy
boolean greedy
-
-
Constructor Detail
-
Alldistinct
public Alldistinct(IntVar[] list)
It constructs an alldistinct constraint.- Parameters:
list- an array of variables.
-
Alldistinct
public Alldistinct(java.util.List<? extends IntVar> list)
It constructs an alldistinct constraint.- Parameters:
list- arraylist of variables.
-
-
Method Detail
-
removeLevel
public void removeLevel(int level)
Description copied from interface:StatefulThis function is called in case of the backtrack, so a constraint can clear the queue of changed variables which is no longer valid. This function is called *before* all timestamps, variables, mutablevariables have reverted to their previous value.- Specified by:
removeLevelin interfaceStateful- Parameters:
level- the level which is being removed.
-
consistency
public void consistency(Store store)
Description copied from class:ConstraintIt 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.- Specified by:
consistencyin classConstraint- Parameters:
store- constraint store within which the constraint consistency is being checked.
-
getDefaultConsistencyPruningEvent
public int getDefaultConsistencyPruningEvent()
- Specified by:
getDefaultConsistencyPruningEventin classConstraint
-
hopcroftKarpMaximumMatching
private boolean hopcroftKarpMaximumMatching()
-
impose
public void impose(Store store)
Description copied from class:ConstraintIt imposes the constraint in a given store.- Overrides:
imposein classConstraint- Parameters:
store- the constraint store to which the constraint is imposed to.
-
markReachableVariables
private void markReachableVariables(java.util.LinkedHashSet<IntVar> variablesReachableFromFreeValues, java.lang.Integer value)
-
queueVariable
public void queueVariable(int level, Var var)Description copied from class:ConstraintThis 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.- Overrides:
queueVariablein classConstraint- Parameters:
level- the level of the store at which the change has occurred.var- variable which has changed.
-
revisitTarjan
private void revisitTarjan(IntVar x, java.util.List<IntVar> l, java.util.Map<IntVar,java.lang.Integer> dfsnum, java.util.Map<IntVar,java.lang.Integer> low, java.util.LinkedHashSet<IntVar> fdvs)
-
satisfied
public boolean satisfied()
Description copied from interface:SatisfiedPresentIt checks if the constraint is satisfied. It can return false even if constraint is satisfied but not all variables in its scope are grounded. It needs to return true if all variables in its scope are grounded and constraint is satisfied.Implementations of this interface for constraints that are not PrimitiveConstraint may require constraint imposition and consistency check as a requirement to work correctly.
- Specified by:
satisfiedin interfaceSatisfiedPresent- Returns:
- true if constraint is possible to verify that it is satisfied.
-
toString
public java.lang.String toString()
Description copied from class:ConstraintIt produces a string representation of a constraint state.- Overrides:
toStringin classConstraint
-
visitTarjan
private void visitTarjan(IntVar x, java.util.List<IntVar> l, java.util.Map<IntVar,java.lang.Integer> dfsnum, java.util.Map<IntVar,java.lang.Integer> low)
-
getGuideConstraint
public Constraint getGuideConstraint()
Description copied from class:ConstraintIt specifies a constraint which if imposed by search will enhance propagation of this constraint.- Overrides:
getGuideConstraintin classConstraint- Returns:
- Constraint enhancing propagation of this constraint.
-
getGuideValue
public int getGuideValue()
Description copied from class:ConstraintThis function provides a value which if assigned to a variable returned by getGuideVariable() will enhance propagation of this constraint.- Overrides:
getGuideValuein classConstraint- Returns:
- Value which is a base of enhancing constraint.
-
getGuideVariable
public Var getGuideVariable()
Description copied from class:ConstraintThis function provides a variable which assigned a value returned by will enhance propagation of this constraint.- Overrides:
getGuideVariablein classConstraint- Returns:
- Variable which is a base of enhancing constraint.
-
estimatePruning
int estimatePruning(IntVar x, java.lang.Integer v)
-
-