Class 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 Details

    • debugAll

      static final boolean debugAll
      See Also:
    • debugPruning

      static final boolean debugPruning
      See Also:
    • idNumber

      static 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

      LinkedHashSet<IntVar> freeVariables
    • impositionFailure

      boolean impositionFailure
    • matching

    • maximumMatchingNotRecomputed

      boolean maximumMatchingNotRecomputed
    • n

      int n
    • nStamp

    • permutationConsistency

      boolean permutationConsistency
    • potentialFreeValues

      Integer[] potentialFreeValues
    • scc

    • sccStamp

    • stampNotGroundedVariables

      TimeStamp<Integer> stampNotGroundedVariables
    • stampReachability

      TimeStamp<Integer> stampReachability
    • stamps

    • stampValues

      TimeStamp<Integer> stampValues
    • valueIndex

      Map<Integer,Integer> valueIndex
    • valueMapVariable

      Map<Integer,SimpleArrayList<IntVar>> valueMapVariable
    • variableQueue

      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 Details

    • Alldistinct

      public Alldistinct(IntVar[] list)
      It constructs an alldistinct constraint.
      Parameters:
      list - an array of variables.
    • Alldistinct

      public Alldistinct(List<? extends IntVar> list)
      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 interface Stateful
      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 class Constraint
      Parameters:
      store - constraint store within which the constraint consistency is being checked.
    • getDefaultConsistencyPruningEvent

      public int getDefaultConsistencyPruningEvent()
      Specified by:
      getDefaultConsistencyPruningEvent in class Constraint
    • 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 class Constraint
      Parameters:
      store - the constraint store to which the constraint is imposed to.
    • markReachableVariables

      private void markReachableVariables(LinkedHashSet<IntVar> variablesReachableFromFreeValues, 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 class Constraint
      Parameters:
      level - the level of the store at which the change has occurred.
      var - variable which has changed.
    • revisitTarjan

      private void revisitTarjan(IntVar x, List<IntVar> l, Map<IntVar,Integer> dfsnum, Map<IntVar,Integer> low, 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 interface SatisfiedPresent
      Returns:
      true if constraint is possible to verify that it is satisfied.
    • toString

      public String toString()
      Description copied from class: Constraint
      It produces a string representation of a constraint state.
      Overrides:
      toString in class Constraint
    • visitTarjan

      private void visitTarjan(IntVar x, List<IntVar> l, Map<IntVar,Integer> dfsnum, Map<IntVar,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 class Constraint
      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 class Constraint
      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 class Constraint
      Returns:
      Variable which is a base of enhancing constraint.
    • estimatePruning

      int estimatePruning(IntVar x, Integer v)
    • estimatePruningRecursive

      int estimatePruningRecursive(IntVar xVar, Integer v, List<IntVar> exploredX, List<Integer> exploredV)