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.9
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) boolean
int
It counts the number of executions of the consistency function.(package private) static final boolean
(package private) static final boolean
(package private) LinkedHashSet
<IntVar> int
It computes how many times did consistency execution has been re-executed due to narrowing event at the end of the consistency function.(package private) boolean
(package private) int
(package private) IntVar
(package private) static AtomicInteger
(package private) boolean
IntVar[]
It specifies all variables which have to have different values.(package private) boolean
(package private) int
(package private) boolean
(package private) Integer[]
(package private) Map
<Integer, SimpleArrayList<IntVar>> (package private) LinkedHashSet
<IntVar> (package private) int
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
ConstructorsConstructorDescriptionAlldistinct
(List<? extends IntVar> list) It constructs an alldistinct constraint.Alldistinct
(IntVar[] list) It constructs an alldistinct constraint. -
Method Summary
Modifier and TypeMethodDescriptionvoid
consistency
(Store store) It is a (most probably incomplete) consistency function which removes the values from variables domains.(package private) int
estimatePruning
(IntVar x, Integer v) (package private) int
int
It specifies a constraint which if imposed by search will enhance propagation of this constraint.int
This function provides a value which if assigned to a variable returned by getGuideVariable() will enhance propagation of this constraint.This function provides a variable which assigned a value returned by will enhance propagation of this constraint.private boolean
void
It imposes the constraint in a given store.private void
markReachableVariables
(LinkedHashSet<IntVar> variablesReachableFromFreeValues, Integer value) void
queueVariable
(int level, Var var) This is a function called to indicate which variable in a scope of constraint has changed.void
removeLevel
(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 void
revisitTarjan
(IntVar x, List<IntVar> l, Map<IntVar, Integer> dfsnum, Map<IntVar, Integer> low, LinkedHashSet<IntVar> fdvs) boolean
It checks if the constraint is satisfied.toString()
It produces a string representation of a constraint state.private void
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 Details
-
debugAll
static final boolean debugAll- See Also:
-
debugPruning
static final boolean debugPruning- See Also:
-
idNumber
-
backtrackOccured
boolean backtrackOccured -
consistencyChecks
public int consistencyChecksIt counts the number of executions of the consistency function. -
fullConsistencyPassesWithNarrowingEvent
public int fullConsistencyPassesWithNarrowingEventIt computes how many times did consistency execution has been re-executed due to narrowing event at the end of the consistency function. -
freeVariables
LinkedHashSet<IntVar> freeVariables -
impositionFailure
boolean impositionFailure -
matching
-
maximumMatchingNotRecomputed
boolean maximumMatchingNotRecomputed -
n
int n -
nStamp
-
permutationConsistency
boolean permutationConsistency -
potentialFreeValues
Integer[] potentialFreeValues -
scc
-
sccStamp
-
stampNotGroundedVariables
-
stampReachability
-
stamps
-
stampValues
-
valueIndex
-
valueMapVariable
Map<Integer,SimpleArrayList<IntVar>> valueMapVariable -
variableQueue
LinkedHashSet<IntVar> variableQueue -
vn
int vn -
list
It specifies all variables which have to have different values. -
guideVariable
IntVar guideVariable -
guideValue
int guideValue -
greedy
boolean greedy
-
-
Constructor Details
-
Alldistinct
It constructs an alldistinct constraint.- Parameters:
list
- an array of variables.
-
Alldistinct
It constructs an alldistinct constraint.- Parameters:
list
- arraylist of variables.
-
-
Method Details
-
removeLevel
public void removeLevel(int level) Description copied from interface:Stateful
This 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:
removeLevel
in interfaceStateful
- Parameters:
level
- the level which is being removed.
-
consistency
Description copied from class:Constraint
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.- Specified by:
consistency
in classConstraint
- Parameters:
store
- constraint store within which the constraint consistency is being checked.
-
getDefaultConsistencyPruningEvent
public int getDefaultConsistencyPruningEvent()- Specified by:
getDefaultConsistencyPruningEvent
in classConstraint
-
hopcroftKarpMaximumMatching
private boolean hopcroftKarpMaximumMatching() -
impose
Description copied from class:Constraint
It imposes the constraint in a given store.- Overrides:
impose
in classConstraint
- Parameters:
store
- the constraint store to which the constraint is imposed to.
-
markReachableVariables
private void markReachableVariables(LinkedHashSet<IntVar> variablesReachableFromFreeValues, Integer value) -
queueVariable
Description copied from class:Constraint
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.- Overrides:
queueVariable
in classConstraint
- Parameters:
level
- the level of the store at which the change has occurred.var
- variable which has changed.
-
revisitTarjan
-
satisfied
public boolean satisfied()Description copied from interface:SatisfiedPresent
It 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:
satisfied
in interfaceSatisfiedPresent
- Returns:
- true if constraint is possible to verify that it is satisfied.
-
toString
Description copied from class:Constraint
It produces a string representation of a constraint state.- Overrides:
toString
in classConstraint
-
visitTarjan
-
getGuideConstraint
Description copied from class:Constraint
It specifies a constraint which if imposed by search will enhance propagation of this constraint.- Overrides:
getGuideConstraint
in classConstraint
- Returns:
- Constraint enhancing propagation of this constraint.
-
getGuideValue
public int getGuideValue()Description copied from class:Constraint
This function provides a value which if assigned to a variable returned by getGuideVariable() will enhance propagation of this constraint.- Overrides:
getGuideValue
in classConstraint
- Returns:
- Value which is a base of enhancing constraint.
-
getGuideVariable
Description copied from class:Constraint
This function provides a variable which assigned a value returned by will enhance propagation of this constraint.- Overrides:
getGuideVariable
in classConstraint
- Returns:
- Variable which is a base of enhancing constraint.
-
estimatePruning
-
estimatePruningRecursive
-