Module org.maxicp

Class CPSetVarImpl

java.lang.Object
org.maxicp.cp.engine.core.CPSetVarImpl
All Implemented Interfaces:
CPSetVar, CPVar, ConcreteVar, Var

public class CPSetVarImpl extends Object implements CPSetVar
Implementation of a set variable.

A set variable is a variable that can take a set of values from a finite domain. The possible values are represented as a tri-partition of the domain.

The implementation uses a StateTriPartition to represent the possible values and a CPIntVar to represent the cardinality of the set.

  • Constructor Summary

    Constructors
    Constructor
    Description
    CPSetVarImpl(CPSolver cp, int n)
    Creates a set variable with the elements {0,...,n-1} as initial possible domain.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a variable that represents the cardinality of the set.
    void
    exclude(int v)
    Excludes a value from the set variable. throws an InconsistencyException if the value is already included in the set. calls the propagate method of the constraint
    void
    Excludes all the possible values from the set.
    int
    fillExcluded(int[] dest)
    Copies the values (in an arbitrary order) of the set of excluded elements into an array.
    int
    fillIncluded(int[] dest)
    Copies the values (in an arbitrary order) of the set of included elements into an array.
    int
    fillPossible(int[] dest)
    Copies the values (in an arbitrary order) of the set of possible elements into an array.
     
    Returns the solver of the set variable.
    void
    include(int v)
    Includes a value in the set variable. throws an InconsistencyException if the value is already excluded from the set. calls the propagate method of the constraint
    void
    Includes all the possible values in the set.
    boolean
    isExcluded(int v)
    Returns if a value is excluded from the set.
    boolean
    Returns true if the set variable is fixed.
    boolean
    isIncluded(int v)
    Returns if a value is included in the set.
    boolean
    isPossible(int v)
    Returns if a value is possible in the set.
    int
    Returns the size of the set of excluded elements
    int
    Returns the size of the set of included elements
    int
    Returns the size of the set of possible elements
    void
    Ask that the CPConstraint.propagate() method of the constraint c is called when the domain of the set variable changes (I,P or E).
    protected void
     
    int
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • CPSetVarImpl

      public CPSetVarImpl(CPSolver cp, int n)
      Creates a set variable with the elements {0,...,n-1} as initial possible domain.
      Parameters:
      cp - the solver in which the variable is created
      n - the number of values with n > 0
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface CPSetVar
    • exclude

      public void exclude(int v)
      Excludes a value from the set variable. throws an InconsistencyException if the value is already included in the set. calls the propagate method of the constraint
      Specified by:
      exclude in interface CPSetVar
      Parameters:
      v - the value to exclude
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • card

      public CPIntVar card()
      Description copied from interface: CPSetVar
      Returns a variable that represents the cardinality of the set.
      Specified by:
      card in interface CPSetVar
      Returns:
      the cardinality variable
    • include

      public void include(int v)
      Includes a value in the set variable. throws an InconsistencyException if the value is already excluded from the set. calls the propagate method of the constraint
      Specified by:
      include in interface CPSetVar
      Parameters:
      v - the value to include
    • isFixed

      public boolean isFixed()
      Returns true if the set variable is fixed. A set variable is fixed if its cardinality is fixed and the number of included values is equal to the minimum of the cardinality.
      Specified by:
      isFixed in interface CPSetVar
      Specified by:
      isFixed in interface CPVar
      Returns:
      true if the set variable is fixed, false otherwise
    • scheduleAll

      protected void scheduleAll(StateStack<CPConstraint> constraints)
    • propagateOnDomainChange

      public void propagateOnDomainChange(CPConstraint c)
      Description copied from interface: CPSetVar
      Ask that the CPConstraint.propagate() method of the constraint c is called when the domain of the set variable changes (I,P or E). If intererested also in the change of the cardinality variable, call CPIntVar.propagateOnBoundChange(CPConstraint) on the cardinality variable.
      Specified by:
      propagateOnDomainChange in interface CPSetVar
      Parameters:
      c - the constraint to notify
    • getSolver

      public CPSolver getSolver()
      Description copied from interface: CPSetVar
      Returns the solver of the set variable.
      Specified by:
      getSolver in interface CPSetVar
      Returns:
      the solver of the set variable
    • getModelProxy

      public ModelProxy getModelProxy()
      Specified by:
      getModelProxy in interface CPSetVar
      Specified by:
      getModelProxy in interface Var
    • nIncluded

      public int nIncluded()
      Description copied from interface: CPSetVar
      Returns the size of the set of included elements
      Specified by:
      nIncluded in interface CPSetVar
      Returns:
      the size of the set of included elements
    • nPossible

      public int nPossible()
      Description copied from interface: CPSetVar
      Returns the size of the set of possible elements
      Specified by:
      nPossible in interface CPSetVar
      Returns:
      the size of the set of possible elements
    • nExcluded

      public int nExcluded()
      Description copied from interface: CPSetVar
      Returns the size of the set of excluded elements
      Specified by:
      nExcluded in interface CPSetVar
      Returns:
      the size of the set of excluded elements
    • includeAll

      public void includeAll()
      Description copied from interface: CPSetVar
      Includes all the possible values in the set.
      Specified by:
      includeAll in interface CPSetVar
    • excludeAll

      public void excludeAll()
      Description copied from interface: CPSetVar
      Excludes all the possible values from the set.
      Specified by:
      excludeAll in interface CPSetVar
    • fillPossible

      public int fillPossible(int[] dest)
      Description copied from interface: CPSetVar
      Copies the values (in an arbitrary order) of the set of possible elements into an array.
      Specified by:
      fillPossible in interface CPSetVar
      Parameters:
      dest - an array large enough dest.length >= nPossible()
      Returns:
      the size of the set of possible elements
    • fillIncluded

      public int fillIncluded(int[] dest)
      Description copied from interface: CPSetVar
      Copies the values (in an arbitrary order) of the set of included elements into an array.
      Specified by:
      fillIncluded in interface CPSetVar
      Parameters:
      dest - an array large enough dest.length >= nIncluded()
      Returns:
      the size of the set of included elements
    • fillExcluded

      public int fillExcluded(int[] dest)
      Description copied from interface: CPSetVar
      Copies the values (in an arbitrary order) of the set of excluded elements into an array.
      Specified by:
      fillExcluded in interface CPSetVar
      Parameters:
      dest - an array large enough dest.length >= nExcluded()
      Returns:
      the size of the set of excluded elements
    • isPossible

      public boolean isPossible(int v)
      Description copied from interface: CPSetVar
      Returns if a value is possible in the set.
      Specified by:
      isPossible in interface CPSetVar
      Parameters:
      v - the value to check
      Returns:
      true if the value is possible, false otherwise
    • isIncluded

      public boolean isIncluded(int v)
      Description copied from interface: CPSetVar
      Returns if a value is included in the set.
      Specified by:
      isIncluded in interface CPSetVar
      Parameters:
      v - the value to check
      Returns:
      true if the value is included, false otherwise
    • isExcluded

      public boolean isExcluded(int v)
      Description copied from interface: CPSetVar
      Returns if a value is excluded from the set.
      Specified by:
      isExcluded in interface CPSetVar
      Parameters:
      v - the value to check
      Returns:
      true if the value is excluded, false otherwise