Module org.chocosolver.solver
Class SetView<V extends Variable>
- java.lang.Object
-
- org.chocosolver.solver.variables.impl.AbstractVariable
-
- org.chocosolver.solver.variables.view.AbstractView<V>
-
- org.chocosolver.solver.variables.view.SetView<V>
-
- All Implemented Interfaces:
java.lang.Comparable<Variable>
,ICause
,Identity
,SetVar
,Variable
,IView<V>
- Direct Known Subclasses:
SetBoolsView
,SetDifferenceView
,SetGraphView
,SetIntersectionView
,SetIntsView
,SetUnionView
public abstract class SetView<V extends Variable> extends AbstractView<V> implements SetVar
An abstract class for set views over other variables.- Since:
- 01/03/2021
- Author:
- Dimitri Justeau-Allaire
-
-
Field Summary
Fields Modifier and Type Field Description protected IntVar
cardinality
-
Fields inherited from class org.chocosolver.solver.variables.view.AbstractView
variables
-
-
Method Summary
All Methods Instance Methods Abstract 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()
protected abstract boolean
doForceSetElement(int element)
Action to execute on observed variables when this view requires to force an element to its lower boundprotected abstract boolean
doRemoveSetElement(int element)
Action to execute on observed variables when this view requires to remove an element from its upper boundvoid
explain(int p, ExplanationForSignedClause clause)
Clausal explanation for this cause.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.int
getTypeAndKind()
Return a MASK composed of 2 main information: TYPE and KIND.boolean
hasCard()
void
justifyEvent(IntEventType mask, int one, int two, int three)
This methods is related to explanations, it binds an event occurring on the observed variable to the view.boolean
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.-
Methods inherited from class org.chocosolver.solver.variables.view.AbstractView
getVariables
-
Methods inherited from class org.chocosolver.solver.variables.impl.AbstractVariable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, compareTo, contradiction, equals, forEachPropagator, getCause, getEvtScheduler, getId, getMask, getModel, getName, getNbProps, getNbViews, getView, hashCode, instantiationWorldIndex, isAConstant, isBool, isScheduled, link, notifyMonitors, notifyPropagators, notifyViews, recordWorldIndex, removeMonitor, schedule, schedulePropagators, storeEvents, streamPropagators, subscribeView, swapOnPassivate, toString, unlink, unschedule
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.chocosolver.solver.ICause
forEachIntVar
-
Methods inherited from interface org.chocosolver.solver.variables.view.IView
getNbObservedVariables, notify
-
Methods inherited from interface org.chocosolver.solver.variables.SetVar
getDelta, getDomainSize, getLB, getUB, getValue, instantiateTo, monitorDelta
-
Methods inherited from interface org.chocosolver.solver.variables.Variable
addMonitor, asBoolVar, asIntVar, asRealVar, asSetVar, clearEvents, contradiction, forEachPropagator, getCause, getEnvironment, getEvtScheduler, getMask, getModel, getName, getNbProps, getNbViews, getView, instantiationWorldIndex, isAConstant, isInstantiated, isScheduled, link, notifyMonitors, notifyPropagators, notifyViews, recordWorldIndex, removeMonitor, schedule, schedulePropagators, storeEvents, streamPropagators, subscribeView, swapOnPassivate, unlink, unschedule
-
-
-
-
Field Detail
-
cardinality
protected IntVar cardinality
-
-
Constructor Detail
-
SetView
protected SetView(java.lang.String name, V... variables)
Create a set view.- Parameters:
name
- name of the variablevariables
- observed variables
-
-
Method Detail
-
doRemoveSetElement
protected abstract boolean doRemoveSetElement(int element) throws ContradictionException
Action to execute on observed variables when this view requires to remove an element from its upper bound- Parameters:
element
- element to remove from the set view- Returns:
- true if at least one of the observed variables has been modified
- Throws:
ContradictionException
-
doForceSetElement
protected abstract boolean doForceSetElement(int element) throws ContradictionException
Action to execute on observed variables when this view requires to force an element to its lower bound- Parameters:
element
- element to force to the set view- Returns:
- true if at least one of the observed variables has been modified
- Throws:
ContradictionException
-
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
- if adding element fails
-
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
- if removing element fails
-
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
-
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
-
justifyEvent
public void justifyEvent(IntEventType mask, int one, int two, int three)
Description copied from interface:IView
This methods is related to explanations, it binds an event occurring on the observed variable to the view.- Specified by:
justifyEvent
in interfaceIView<V extends Variable>
- Parameters:
mask
- type of modificationone
- an inttwo
- an intthree
- an int
-
explain
public void explain(int p, ExplanationForSignedClause clause)
Description copied from interface:ICause
Clausal explanation for this cause.This method must filled explanations with inferred literals. These literals are inferred from the analysis of (a subset of) conflicting nodes stored in front, the implication graph ig and the current node in conflict, not yet contained in front.
Optionally, this method can update front by looking for a predecessor of any node that seems more relevant than the declared one.
-
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
-
-