public class SetVarImpl extends AbstractVariable implements SetVar
Modifier and Type | Field and Description |
---|---|
protected IntVar |
cardinality |
protected SetDelta |
delta |
protected ISet |
lb |
protected ISet |
lbReadOnly |
protected boolean |
reactOnModification |
protected ISet |
ub |
protected ISet |
ubReadOnly |
mIdx, model, monitors, MSG_EMPTY, MSG_INST, name, propagators
Constructor and Description |
---|
SetVarImpl(String name,
int[] value,
Model model)
Creates a fixed Set variable, equal to
value |
SetVarImpl(String name,
int[] ker,
SetType kerType,
int[] env,
SetType envType,
Model model)
Creates a Set variable
|
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. |
SetVarImpl(String name,
ISet value,
Model model)
Creates a fixed Set variable, equal to
value
Beware : Use this constructor with caution (domain is directly accessible)
value should be created properly and should not be modified afterward |
Modifier and Type | Method and Description |
---|---|
void |
createDelta()
Create a delta, if necessary, in order to observe removed values of a this.
|
boolean |
force(int element,
ICause cause)
Adds element to the lower bound, i.e.
|
IntVar |
getCard()
get the constrained cardinality variable of this set.
|
SetDelta |
getDelta()
Return the delta domain of this
|
ISet |
getLB()
Get SetVar Lower Bound : the set of integers that must belong to every solution (i.e.
|
int |
getTypeAndKind()
Return a MASK composed of 2 main information: TYPE and KIND.
|
ISet |
getUB()
Get SetVar Upper Bound : the set of integers that may belong to a solution (i.e.
|
boolean |
hasCard() |
boolean |
instantiateTo(int[] value,
ICause cause)
Enforces the set variable to contain exactly the set of integers given in parameter
|
boolean |
isInstantiated()
Indicates whether
this is instantiated (see implemtations to know what instantiation means). |
SetDeltaMonitor |
monitorDelta(ICause propagator)
Allow propagator to monitor element removal/enforcing of this
|
void |
notifyMonitors(IEventType event)
Notify monitors of observed variable modifications
|
boolean |
remove(int element,
ICause cause)
Removes element from the upper bound, i.e.
|
void |
setCard(IntVar card)
ensure a variable is equal to the cardinality of this set.
|
String |
toString() |
_schedIter, addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, compareTo, contradiction, getCause, getDindex, getId, getIndexInPropagator, getMask, getModel, getName, getNbProps, getPIndices, getPropagator, getPropagators, getViews, isAConstant, isBool, link, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
_schedIter, addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, getCause, getDindex, getEnvironment, getIndexInPropagator, getMask, getModel, getName, getNbProps, getPIndices, getPropagator, getPropagators, getViews, isAConstant, link, notifyPropagators, notifyViews, removeMonitor, setPIndice, storeEvents, subscribeView, swapOnActivate, swapOnPassivate, unlink
compareTo
protected final ISet lb
protected final ISet ub
protected final ISet lbReadOnly
protected final ISet ubReadOnly
protected SetDelta delta
protected boolean reactOnModification
protected IntVar cardinality
public SetVarImpl(String name, int[] ker, SetType kerType, int[] env, SetType envType, Model model)
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.public SetVarImpl(String name, ISet lb, ISet ub, Model model)
[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 themname
- 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.public SetVarImpl(String name, ISet value, Model model)
value
Beware : Use this constructor with caution (domain is directly accessible)
value should be created properly and should not be modified afterwardname
- name of the variablevalue
- value of the set variablemodel
- solver of the variable.public boolean isInstantiated()
Variable
this
is instantiated (see implemtations to know what instantiation means).isInstantiated
in interface Variable
true
if this
is instantiatedpublic ISet getLB()
SetVar
force
to update the domainpublic ISet getUB()
SetVar
remove
to update the domainpublic IntVar getCard()
SetVar
public boolean hasCard()
public void setCard(IntVar card)
SetVar
public boolean force(int element, ICause cause) throws ContradictionException
SetVar
element
force
in interface SetVar
element
- value to addcause
- cause of value additionContradictionException
public boolean remove(int element, ICause cause) throws ContradictionException
SetVar
element
anymoreremove
in interface SetVar
element
- value to removecause
- cause of value removalContradictionException
public boolean instantiateTo(int[] value, ICause cause) throws ContradictionException
SetVar
instantiateTo
in interface SetVar
value
- a set of integerscause
- cause of instantiationContradictionException
public SetDelta getDelta()
Variable
public int getTypeAndKind()
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;
getTypeAndKind
in interface Variable
public String toString()
toString
in class AbstractVariable
public void createDelta()
Variable
createDelta
in interface Variable
public SetDeltaMonitor monitorDelta(ICause propagator)
SetVar
monitorDelta
in interface SetVar
propagator
- observerpublic void notifyMonitors(IEventType event) throws ContradictionException
Variable
notifyMonitors
in interface Variable
event
- the event which occurred on the variableContradictionException
- if the monitor detects contradiction.Copyright © 2018. All rights reserved.