java.lang.Object
org.maxicp.cp.engine.core.CPSetVarImpl
- All Implemented Interfaces:
CPSetVar,CPVar,ConcreteVar,Var
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
ConstructorsConstructorDescriptionCPSetVarImpl(CPSolver cp, int n) Creates a set variable with the elements{0,...,n-1}as initial possible domain. -
Method Summary
Modifier and TypeMethodDescriptioncard()Returns a variable that represents the cardinality of the set.voidexclude(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 constraintvoidExcludes all the possible values from the set.intfillExcluded(int[] dest) Copies the values (in an arbitrary order) of the set of excluded elements into an array.intfillIncluded(int[] dest) Copies the values (in an arbitrary order) of the set of included elements into an array.intfillPossible(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.voidinclude(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 constraintvoidIncludes all the possible values in the set.booleanisExcluded(int v) Returns if a value is excluded from the set.booleanisFixed()Returns true if the set variable is fixed.booleanisIncluded(int v) Returns if a value is included in the set.booleanisPossible(int v) Returns if a value is possible in the set.intReturns the size of the set of excluded elementsintReturns the size of the set of included elementsintReturns the size of the set of possible elementsvoidAsk that theCPConstraint.propagate()method of the constraint c is called when the domain of the set variable changes (I,P or E).protected voidscheduleAll(StateStack<CPConstraint> constraints) intsize()toString()
-
Constructor Details
-
CPSetVarImpl
Creates a set variable with the elements{0,...,n-1}as initial possible domain.- Parameters:
cp- the solver in which the variable is createdn- the number of values withn > 0
-
-
Method Details
-
size
public int size() -
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 -
toString
-
card
Description copied from interface:CPSetVarReturns a variable that represents the cardinality of the set. -
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 -
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. -
scheduleAll
-
propagateOnDomainChange
Description copied from interface:CPSetVarAsk that theCPConstraint.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, callCPIntVar.propagateOnBoundChange(CPConstraint)on the cardinality variable.- Specified by:
propagateOnDomainChangein interfaceCPSetVar- Parameters:
c- the constraint to notify
-
getSolver
Description copied from interface:CPSetVarReturns the solver of the set variable. -
getModelProxy
- Specified by:
getModelProxyin interfaceCPSetVar- Specified by:
getModelProxyin interfaceVar
-
nIncluded
public int nIncluded()Description copied from interface:CPSetVarReturns the size of the set of included elements -
nPossible
public int nPossible()Description copied from interface:CPSetVarReturns the size of the set of possible elements -
nExcluded
public int nExcluded()Description copied from interface:CPSetVarReturns the size of the set of excluded elements -
includeAll
public void includeAll()Description copied from interface:CPSetVarIncludes all the possible values in the set.- Specified by:
includeAllin interfaceCPSetVar
-
excludeAll
public void excludeAll()Description copied from interface:CPSetVarExcludes all the possible values from the set.- Specified by:
excludeAllin interfaceCPSetVar
-
fillPossible
public int fillPossible(int[] dest) Description copied from interface:CPSetVarCopies the values (in an arbitrary order) of the set of possible elements into an array.- Specified by:
fillPossiblein interfaceCPSetVar- Parameters:
dest- an array large enoughdest.length >= nPossible()- Returns:
- the size of the set of possible elements
-
fillIncluded
public int fillIncluded(int[] dest) Description copied from interface:CPSetVarCopies the values (in an arbitrary order) of the set of included elements into an array.- Specified by:
fillIncludedin interfaceCPSetVar- Parameters:
dest- an array large enoughdest.length >= nIncluded()- Returns:
- the size of the set of included elements
-
fillExcluded
public int fillExcluded(int[] dest) Description copied from interface:CPSetVarCopies the values (in an arbitrary order) of the set of excluded elements into an array.- Specified by:
fillExcludedin interfaceCPSetVar- Parameters:
dest- an array large enoughdest.length >= nExcluded()- Returns:
- the size of the set of excluded elements
-
isPossible
public boolean isPossible(int v) Description copied from interface:CPSetVarReturns if a value is possible in the set.- Specified by:
isPossiblein interfaceCPSetVar- 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:CPSetVarReturns if a value is included in the set.- Specified by:
isIncludedin interfaceCPSetVar- 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:CPSetVarReturns if a value is excluded from the set.- Specified by:
isExcludedin interfaceCPSetVar- Parameters:
v- the value to check- Returns:
- true if the value is excluded, false otherwise
-