- 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
-
-
Constructor Summary
Constructors Constructor Description SetVarImpl(String name, int[] value, Model model)
Creates a fixed Set variable, equal tovalue
SetVarImpl(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 tovalue
Beware : 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 void
createDelta()
Create a delta, if necessary, in order to observe removed values of a this.protected EvtScheduler
createScheduler()
boolean
force(int element, ICause cause)
Adds element to the lower bound, i.e. every solution must includeelement
IntVar
getCard()
get the constrained cardinality variable of this set.SetDelta
getDelta()
Return the delta domain of thisISet
getLB()
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.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. 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.boolean
hasCard()
boolean
instantiateTo(int[] value, ICause cause)
Enforces the set variable to contain exactly the set of integers given in parameterboolean
isInstantiated()
Indicates whetherthis
is instantiated (see implemtations to know what instantiation means).SetDeltaMonitor
monitorDelta(ICause propagator)
Allow propagator to monitor element removal/enforcing of thisboolean
remove(int element, ICause cause)
Removes element from the upper bound, i.e. the set variable cannot containelement
anymorevoid
setCard(IntVar card)
ensure a variable is equal to the cardinality of this set.String
toString()
-
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, getNbViews, getPIndices, getPropagator, getPropagators, getView, isAConstant, isBool, link, notifyMonitors, 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, getNbViews, getPIndices, getPropagator, getPropagators, getView, isAConstant, link, notifyMonitors, 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 tovalue
Beware : 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:Variable
Indicates whetherthis
is instantiated (see implemtations to know what instantiation means).- Specified by:
isInstantiated
in interfaceVariable
- Returns:
true
ifthis
is instantiated
-
getLB
public ISet getLB()
Description copied from interface:SetVar
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. Use variable methodsforce
to update the domain
-
getUB
public ISet getUB()
Description copied from interface:SetVar
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. Use variable methodsremove
to update the domain
-
getCard
public IntVar getCard()
Description copied from interface:SetVar
get 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:SetVar
ensure 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 ContradictionException
Description copied from interface:SetVar
Adds element to the lower bound, i.e. every solution must includeelement
- Specified by:
force
in 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 ContradictionException
Description copied from interface:SetVar
Removes element from the upper bound, i.e. the set variable cannot containelement
anymore- Specified by:
remove
in 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 ContradictionException
Description copied from interface:SetVar
Enforces the set variable to contain exactly the set of integers given in parameter- Specified by:
instantiateTo
in 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:Variable
Return the delta domain of this
-
getTypeAndKind
public int getTypeAndKind()
Description copied from interface:Variable
Return 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:
getTypeAndKind
in interfaceVariable
- Returns:
- an int representing the type and kind of the variable
-
createScheduler
protected EvtScheduler createScheduler()
- Specified by:
createScheduler
in classAbstractVariable
-
toString
public String toString()
- Overrides:
toString
in classAbstractVariable
-
createDelta
public void createDelta()
Description copied from interface:Variable
Create a delta, if necessary, in order to observe removed values of a this. If the delta already exists, has no effect.- Specified by:
createDelta
in interfaceVariable
-
monitorDelta
public SetDeltaMonitor monitorDelta(ICause propagator)
Description copied from interface:SetVar
Allow propagator to monitor element removal/enforcing of this- Specified by:
monitorDelta
in interfaceSetVar
- Parameters:
propagator
- observer- Returns:
- a new SetDeltaMonitor
-
-