javax.constraints.impl
Class BasicVarSet

java.lang.Object
  extended by javax.constraints.impl.CommonBase
      extended by javax.constraints.impl.AbstractConstrainedVariable
          extended by javax.constraints.impl.BasicVarSet
All Implemented Interfaces:
ConstrainedVariable, VarSet

public class BasicVarSet
extends AbstractConstrainedVariable
implements VarSet

This class represents a basic implementation of constrained set variables.


Constructor Summary
BasicVarSet(Problem problem, int[] values, java.lang.String name)
           
BasicVarSet(Problem problem, int min, int max, java.lang.String name)
           
BasicVarSet(Problem problem, java.util.Set set, java.lang.String name)
           
 
Method Summary
 boolean contains(java.util.Set setOfValues)
           
 Constraint doNotIntersectWith(VarSet varSet)
           
 Var getCardinality()
           
 java.util.Set getPossibleSet()
           
 java.util.Set getRequiredSet()
           
 Var getRequiredVar(int value)
           
 Var[] getRequiredVars()
           
 java.util.Set getValue()
           
 java.util.Set getValueSet()
           
 void init()
           
 VarSet intersection(VarSet varSet)
          Creates a new set variable that is an intersection of this set variable with the "varSet" passed as a parameter.
 boolean isBound()
           
 boolean isPossible(int value)
           
 boolean isRequired(int value)
           
 void remove(int value)
          Removes the "value' from the possible set
 void require(int value)
          Adds the "value" to the required set
 void setEmpty(boolean flag)
          Sets the cardinality of this set variable to be equals 0 if the flag is true, and to be more or equal 1 if the flag is false.
 void setValue(java.util.Set set)
          Instantiates this set variable with the constant "set" of integers.
 java.lang.String toString()
           
 VarSet union(VarSet varSet)
          Creates a new set variable that is an union of this set variable with the "varSet" passed as a parameter.
 
Methods inherited from class javax.constraints.impl.CommonBase
getImpl, getName, getObject, getProblem, setImpl, setName, setObject
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.constraints.ConstrainedVariable
getImpl, getName, getObject, getProblem, setImpl, setName, setObject
 

Constructor Detail

BasicVarSet

public BasicVarSet(Problem problem,
                   int[] values,
                   java.lang.String name)
            throws java.lang.Exception
Throws:
java.lang.Exception

BasicVarSet

public BasicVarSet(Problem problem,
                   int min,
                   int max,
                   java.lang.String name)
            throws java.lang.Exception
Throws:
java.lang.Exception

BasicVarSet

public BasicVarSet(Problem problem,
                   java.util.Set set,
                   java.lang.String name)
            throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

contains

public boolean contains(java.util.Set setOfValues)
Specified by:
contains in interface VarSet
Returns:
true if the possible set contains "setOfValues"

doNotIntersectWith

public Constraint doNotIntersectWith(VarSet varSet)
                              throws java.lang.Exception
Throws:
java.lang.Exception

getCardinality

public Var getCardinality()
Specified by:
getCardinality in interface VarSet
Returns:
an integer constraint variable that represents a number of elements in the domain of this variable when it is instantiated

getPossibleSet

public java.util.Set getPossibleSet()
Specified by:
getPossibleSet in interface VarSet
Returns:
the possible set

getRequiredSet

public java.util.Set getRequiredSet()
Specified by:
getRequiredSet in interface VarSet
Returns:
the required set

getRequiredVar

public Var getRequiredVar(int value)
                   throws java.lang.Exception
Throws:
java.lang.Exception

getRequiredVars

public Var[] getRequiredVars()

getValue

public java.util.Set getValue()
                       throws java.lang.Exception
Specified by:
getValue in interface VarSet
Returns:
a Set of integers in the required set
Throws:
java.lang.Exception - if this set variable in not bound

getValueSet

public java.util.Set getValueSet()

init

public void init()
          throws java.lang.Exception
Throws:
java.lang.Exception

intersection

public VarSet intersection(VarSet varSet)
                    throws java.lang.Exception
Description copied from interface: VarSet
Creates a new set variable that is an intersection of this set variable with the "varSet" passed as a parameter.

Specified by:
intersection in interface VarSet
Returns:
a set variable
Throws:
java.lang.Exception

isBound

public boolean isBound()
Specified by:
isBound in interface VarSet
Returns:
true when all elements in the domain are required

isPossible

public boolean isPossible(int value)
Specified by:
isPossible in interface VarSet
Returns:
true if the "value" belongs to the possible set

isRequired

public boolean isRequired(int value)
Specified by:
isRequired in interface VarSet
Returns:
true if the "value" belongs to the required set

remove

public void remove(int value)
            throws java.lang.Exception
Description copied from interface: VarSet
Removes the "value' from the possible set

Specified by:
remove in interface VarSet
Throws:
java.lang.Exception

require

public void require(int value)
             throws java.lang.Exception
Description copied from interface: VarSet
Adds the "value" to the required set

Specified by:
require in interface VarSet
Throws:
java.lang.Exception - if the value is outside of the possible set

setEmpty

public void setEmpty(boolean flag)
Description copied from interface: VarSet
Sets the cardinality of this set variable to be equals 0 if the flag is true, and to be more or equal 1 if the flag is false.

Specified by:
setEmpty in interface VarSet

setValue

public void setValue(java.util.Set set)
              throws java.lang.Exception
Description copied from interface: VarSet
Instantiates this set variable with the constant "set" of integers. All integers that do not belong to the "set" will be removed from the possible set.

Specified by:
setValue in interface VarSet
Throws:
java.lang.Exception - if some values in the "set' are not possible

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

union

public VarSet union(VarSet varSet)
Description copied from interface: VarSet
Creates a new set variable that is an union of this set variable with the "varSet" passed as a parameter.

Specified by:
union in interface VarSet
Returns:
a set variable