public class SetVarImpl extends AbstractVariable implements SetVar
Modifier and Type | Field and Description |
---|---|
protected SetDelta |
delta |
protected ISet |
envelope |
protected ISet |
kernel |
protected int |
max |
protected int |
min |
protected boolean |
reactOnModification |
_plugexpl, mIdx, modificationEvents, monitors, MSG_BOUND, MSG_EMPTY, MSG_INST, MSG_LOW, MSG_REMOVE, MSG_UNKNOWN, MSG_UPP, name, solver
Constructor and Description |
---|
SetVarImpl(String name,
int[] env,
SetType envType,
int[] ker,
SetType kerType,
Solver solver)
Creates a Set variable
|
SetVarImpl(String name,
int min,
int max,
Solver solver)
Creates a Set variable
|
Modifier and Type | Method and Description |
---|---|
boolean |
addToKernel(int element,
ICause cause)
Adds element to the kernel, i.e. enforces that the set variable
will contain element in every solution
|
void |
contradiction(ICause cause,
IEventType event,
String message)
Throws a contradiction exception based on
|
void |
createDelta()
Create a delta, if necessary, in order to observe removed values of a this.
|
SetVar |
duplicate()
Duplicate
this . |
void |
duplicate(Solver solver,
gnu.trove.map.hash.THashMap<Object,Object> identitymap)
Duplicate
this (which naturally adds it into solver ). |
boolean |
envelopeContains(int i)
Test whether element is present or not in the envelope
|
SetDelta |
getDelta()
Return the delta domain of this
|
int |
getEnvelopeFirst()
Get the first element currently in the envelope domain of
this . |
int |
getEnvelopeNext()
Get the next element in the envelope domain of
this . |
int |
getEnvelopeSize()
Get the number of elements in the envelope domain of
this . |
int |
getKernelFirst()
Get the first element currently in the kernel domain of
this . |
int |
getKernelNext()
Get the next element in the kernel domain of
this . |
int |
getKernelSize()
Get the number of elements in the kernel domain of
this . |
int |
getTypeAndKind()
Return a MASK composed of 2 main information: TYPE and KIND.
|
int[] |
getValues()
Retrieves the current value of the variable if instantiated, otherwise the lower bound (kernel).
|
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). |
boolean |
kernelContains(int i)
Test whether element is present or not in the kernel
|
SetDeltaMonitor |
monitorDelta(ICause propagator)
Allow propagator to monitor element removal/enforcing of this
|
void |
notifyMonitors(IEventType event)
Notify monitors of observed variable modifications
|
boolean |
removeFromEnvelope(int element,
ICause cause)
Removes element from the envelop, i.e. the set variable cannot contain element anymore
|
String |
toString() |
addMonitor, compareTo, getId, getIndexInPropagator, getName, getNbProps, getPIndices, getPropagator, getPropagators, getSolver, getViews, isBool, link, notifyPropagators, notifyViews, recordMask, removeMonitor, subscribeView, unlink
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addMonitor, getIndexInPropagator, getName, getNbProps, getPIndices, getPropagator, getPropagators, getSolver, getViews, link, notifyPropagators, notifyViews, recordMask, removeMonitor, subscribeView, unlink
compareTo
protected ISet envelope
protected ISet kernel
protected SetDelta delta
protected int min
protected int max
protected boolean reactOnModification
public SetVarImpl(String name, int[] env, SetType envType, int[] ker, SetType kerType, Solver solver)
name
- name of the variableenv
- initial envelope domainenvType
- data structure of the envelopeker
- initial kernel domainkerType
- data structure of the kernelsolver
- 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 boolean addToKernel(int element, ICause cause) throws ContradictionException
SetVar
addToKernel
in interface SetVar
element
- value to addcause
- cause of value additionContradictionException
public boolean removeFromEnvelope(int element, ICause cause) throws ContradictionException
SetVar
removeFromEnvelope
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 int[] getValues()
SetVar
public int getKernelFirst()
SetVar
this
.
Returns END
if the set is empty.
Note that elements are not sorted.
To iterate over elements that are present in the kernel, do the following loop:
for(int e=getKernelFirst(); e!=SetVar.END; e=getKernelNext()){
// something
}
getKernelFirst
in interface SetVar
END
if it is empty.public int getKernelNext()
SetVar
this
.
Returns END
once all elements have been visited.
To iterate over elements that are present in the kernel, do the following loop:
for(int e=getKernelFirst(); e!=SetVar.END; e=getKernelNext()){
// something
}
getKernelNext
in interface SetVar
END
otherwise.public int getKernelSize()
SetVar
this
.getKernelSize
in interface SetVar
public boolean kernelContains(int i)
SetVar
kernelContains
in interface SetVar
i
- value to testpublic int getEnvelopeFirst()
SetVar
this
.
Returns END
if the set is empty.
Note that elements are not sorted.
To iterate over elements that are present in the envelope, do the following loop:
for(int e=getEnvelopeFirst(); e!=SetVar.END; e=getEnvelopeNext()){
// something
}
getEnvelopeFirst
in interface SetVar
END
if it is empty.public int getEnvelopeNext()
SetVar
this
.
Returns END
once all elements have been visited.
To iterate over elements that are present in the envelope, do the following loop:
for(int e=getEnvelopeFirst(); e!=SetVar.END; e=getEnvelopeNext()){
// something
}
getEnvelopeNext
in interface SetVar
END
otherwise.public int getEnvelopeSize()
SetVar
this
.getEnvelopeSize
in interface SetVar
public boolean envelopeContains(int i)
SetVar
envelopeContains
in interface SetVar
i
- value to testpublic 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 void duplicate(Solver solver, gnu.trove.map.hash.THashMap<Object,Object> identitymap)
Variable
this
(which naturally adds it into solver
).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
public void contradiction(ICause cause, IEventType event, String message) throws ContradictionException
Variable
contradiction
in interface Variable
cause
- ICause causing the exceptionevent
- event causing the contradictionmessage
- the detailed message @throws ContradictionException expected behaviorContradictionException
Copyright © 2015. All rights reserved.