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) boolean
backtrackOccured
int
consistencyChecks
It counts the number of executions of the consistency function.(package private) static boolean
debugAll
(package private) static boolean
debugPruning
(package private) java.util.LinkedHashSet<IntVar>
freeVariables
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.(package private) boolean
greedy
(package private) int
guideValue
(package private) IntVar
guideVariable
(package private) static java.util.concurrent.atomic.AtomicInteger
idNumber
(package private) boolean
impositionFailure
IntVar[]
list
It specifies all variables which have to have different values.(package private) java.util.Map<IntVar,TimeStamp<java.lang.Integer>>
matching
(package private) boolean
maximumMatchingNotRecomputed
(package private) int
n
(package private) TimeStamp<java.lang.Integer>
nStamp
(package private) boolean
permutationConsistency
(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) int
vn
-
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 void
consistency(Store store)
It is a (most probably incomplete) consistency function which removes the values from variables domains.(package private) int
estimatePruning(IntVar x, java.lang.Integer v)
(package private) int
estimatePruningRecursive(IntVar xVar, java.lang.Integer v, java.util.List<IntVar> exploredX, java.util.List<java.lang.Integer> exploredV)
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.private boolean
hopcroftKarpMaximumMatching()
void
impose(Store store)
It imposes the constraint in a given store.private void
markReachableVariables(java.util.LinkedHashSet<IntVar> variablesReachableFromFreeValues, java.lang.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, 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)
boolean
satisfied()
It checks if the constraint is satisfied.java.lang.String
toString()
It produces a string representation of a constraint state.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)
-
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: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
public void consistency(Store store)
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
public void impose(Store store)
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(java.util.LinkedHashSet<IntVar> variablesReachableFromFreeValues, java.lang.Integer value)
-
queueVariable
public void queueVariable(int level, Var var)
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
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: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
public java.lang.String toString()
Description copied from class:Constraint
It produces a string representation of a constraint state.- Overrides:
toString
in 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: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
public Var 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
int estimatePruning(IntVar x, java.lang.Integer v)
-
-