Class SetVarImpl
- java.lang.Object
-
- org.chocosolver.solver.variables.impl.AbstractVariable
-
- org.chocosolver.solver.variables.impl.SetVarImpl
-
- All Implemented Interfaces:
Comparable<Variable>,Identity,SetVar,Variable
public class SetVarImpl extends AbstractVariable implements SetVar
Set variable to represent a set of integers, i.e. a value is a set- Since:
- Oct 2012
- Author:
- Jean-Guillaume Fages
-
-
Field Summary
Fields Modifier and Type Field Description protected IntVarcardinalityprotected SetDeltadeltaprotected ISetlbprotected ISetlbReadOnlyprotected booleanreactOnModificationprotected ISetubprotected ISetubReadOnly-
Fields inherited from class org.chocosolver.solver.variables.impl.AbstractVariable
mIdx, model, monitors, MSG_EMPTY, MSG_INST, name, propagators
-
-
Constructor Summary
Constructors Constructor Description SetVarImpl(String name, int[] value, Model model)Creates a fixed Set variable, equal tovalueSetVarImpl(String name, int[] ker, SetType kerType, int[] env, SetType envType, Model model)Creates a Set variableSetVarImpl(String name, ISet value, Model model)Creates a fixed Set variable, equal tovalueBeware : Use this constructor with caution (domain is directly accessible) value should be created properly and should not be modified afterwardSetVarImpl(String name, ISet lb, ISet ub, Model model)Creates a set variable, of domain[lb, ub]Beware : Use this constructor with caution (domain is directly accessible) lb and ub should be created properly (e.g. lb subset of ub) and should not be modified externally Both lb and ub should be backtrackable sets (stored sets): use SetFactory.makeStoredSet to build them
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcreateDelta()Create a delta, if necessary, in order to observe removed values of a this.protected EvtSchedulercreateScheduler()booleanforce(int element, ICause cause)Adds element to the lower bound, i.e. every solution must includeelementIntVargetCard()get the constrained cardinality variable of this set.SetDeltagetDelta()Return the delta domain of thisISetgetLB()Get SetVar Lower Bound : the set of integers that must belong to every solution (i.e. a subset of all solutions) To iterate over this set, use the following loop: ISet lbSet = getLB(); for(int i : lbSet){ ... } This object is read-only.intgetTypeAndKind()Return a MASK composed of 2 main information: TYPE and KIND.ISetgetUB()Get SetVar Upper Bound : the set of integers that may belong to a solution (i.e. a superset of all solutions) To iterate over this set, use the following loop: ISet ubSet = getUB(); for(int i : ubSet){ ... } This object is read-only.booleanhasCard()booleaninstantiateTo(int[] value, ICause cause)Enforces the set variable to contain exactly the set of integers given in parameterbooleanisInstantiated()Indicates whetherthisis instantiated (see implemtations to know what instantiation means).SetDeltaMonitormonitorDelta(ICause propagator)Allow propagator to monitor element removal/enforcing of thisvoidnotifyMonitors(IEventType event)Notify monitors of observed variable modificationsbooleanremove(int element, ICause cause)Removes element from the upper bound, i.e. the set variable cannot containelementanymorevoidsetCard(IntVar card)ensure a variable is equal to the cardinality of this set.StringtoString()-
Methods inherited from class org.chocosolver.solver.variables.impl.AbstractVariable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, compareTo, contradiction, getCause, getDindex, getEvtScheduler, getId, getIndexInPropagator, getMask, getModel, getName, getNbProps, getPIndices, getPropagator, getPropagators, getViews, isAConstant, isBool, link, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, getCause, getDindex, getEnvironment, getEvtScheduler, getIndexInPropagator, getMask, getModel, getName, getNbProps, getPIndices, getPropagator, getPropagators, getViews, isAConstant, link, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
-
-
-
-
Constructor Detail
-
SetVarImpl
public SetVarImpl(String name, int[] ker, SetType kerType, int[] env, SetType envType, Model model)
Creates a Set variable- Parameters:
name- name of the variableker- initial kernel domainkerType- data structure of the kernelenv- initial envelope domainenvType- data structure of the envelopemodel- solver of the variable.
-
SetVarImpl
public SetVarImpl(String name, ISet lb, ISet ub, Model model)
Creates a set variable, of domain[lb, ub]Beware : Use this constructor with caution (domain is directly accessible) lb and ub should be created properly (e.g. lb subset of ub) and should not be modified externally Both lb and ub should be backtrackable sets (stored sets): use SetFactory.makeStoredSet to build them- Parameters:
name- name of the variablelb- lower bound of the set variable (mandatory elements)ub- upper bound of the set variable (potential elements)model- solver of the variable.
-
SetVarImpl
public SetVarImpl(String name, ISet value, Model model)
Creates a fixed Set variable, equal tovalueBeware : Use this constructor with caution (domain is directly accessible) value should be created properly and should not be modified afterward- Parameters:
name- name of the variablevalue- value of the set variablemodel- solver of the variable.
-
-
Method Detail
-
isInstantiated
public boolean isInstantiated()
Description copied from interface:VariableIndicates whetherthisis instantiated (see implemtations to know what instantiation means).- Specified by:
isInstantiatedin interfaceVariable- Returns:
trueifthisis instantiated
-
getLB
public ISet getLB()
Description copied from interface:SetVarGet SetVar Lower Bound : the set of integers that must belong to every solution (i.e. a subset of all solutions) To iterate over this set, use the following loop: ISet lbSet = getLB(); for(int i : lbSet){ ... } This object is read-only. Use variable methodsforceto update the domain
-
getUB
public ISet getUB()
Description copied from interface:SetVarGet SetVar Upper Bound : the set of integers that may belong to a solution (i.e. a superset of all solutions) To iterate over this set, use the following loop: ISet ubSet = getUB(); for(int i : ubSet){ ... } This object is read-only. Use variable methodsremoveto update the domain
-
getCard
public IntVar getCard()
Description copied from interface:SetVarget the constrained cardinality variable of this set.- if no variable already has this role, creates a new variable, store and constraint it.
- if a variable already has this role, return it.
-
hasCard
public boolean hasCard()
-
setCard
public void setCard(IntVar card)
Description copied from interface:SetVarensure a variable is equal to the cardinality of this set.- If not call has been already performed to this set cardinality, post a constraint on the number of variables
- if this set already has a variable constrained to the cardinality, post an equality
-
force
public boolean force(int element, ICause cause) throws ContradictionExceptionDescription copied from interface:SetVarAdds element to the lower bound, i.e. every solution must includeelement- Specified by:
forcein interfaceSetVar- Parameters:
element- value to addcause- cause of value addition- Returns:
- true iff element has been added to the lower bound
- Throws:
ContradictionException
-
remove
public boolean remove(int element, ICause cause) throws ContradictionExceptionDescription copied from interface:SetVarRemoves element from the upper bound, i.e. the set variable cannot containelementanymore- Specified by:
removein interfaceSetVar- Parameters:
element- value to removecause- cause of value removal- Returns:
- true iff element has been removed from the upper bound
- Throws:
ContradictionException
-
instantiateTo
public boolean instantiateTo(int[] value, ICause cause) throws ContradictionExceptionDescription copied from interface:SetVarEnforces the set variable to contain exactly the set of integers given in parameter- Specified by:
instantiateToin interfaceSetVar- Parameters:
value- a set of integerscause- cause of instantiation- Returns:
- true iff a domain modification occurred
- Throws:
ContradictionException
-
getDelta
public SetDelta getDelta()
Description copied from interface:VariableReturn the delta domain of this
-
getTypeAndKind
public int getTypeAndKind()
Description copied from interface:VariableReturn a MASK composed of 2 main information: TYPE and KIND.
TYPE is defined in the 3 first bits : VAR ( 1 << 0), CSTE (1 << 1) or VIEW (1 << 2)
KIND is defined on the other bits : INT (1 << 3), BOOL (INT + 1 << 4), GRAPH (1 << 5) or META (1 << 6) To get the TYPE of a variable:int type = var.getTypeAndKind() & Variable.TYPE;
To get the KIND of a variable:int kind = var.getTypeAndKind() & Variable.KIND;
To check a specific type or kind of a variable:boolean isVar = (var.getTypeAndKind() & Variable.VAR) !=0; boolean isInt = (var.getTypeAndKind() & Variable.INT) !=0;- Specified by:
getTypeAndKindin interfaceVariable- Returns:
- an int representing the type and kind of the variable
-
createScheduler
protected EvtScheduler createScheduler()
- Specified by:
createSchedulerin classAbstractVariable
-
toString
public String toString()
- Overrides:
toStringin classAbstractVariable
-
createDelta
public void createDelta()
Description copied from interface:VariableCreate a delta, if necessary, in order to observe removed values of a this. If the delta already exists, has no effect.- Specified by:
createDeltain interfaceVariable
-
monitorDelta
public SetDeltaMonitor monitorDelta(ICause propagator)
Description copied from interface:SetVarAllow propagator to monitor element removal/enforcing of this- Specified by:
monitorDeltain interfaceSetVar- Parameters:
propagator- observer- Returns:
- a new SetDeltaMonitor
-
notifyMonitors
public void notifyMonitors(IEventType event) throws ContradictionException
Description copied from interface:VariableNotify monitors of observed variable modifications- Specified by:
notifyMonitorsin interfaceVariable- Parameters:
event- the event which occurred on the variable- Throws:
ContradictionException- if the monitor detects contradiction.
-
-