V - VariableT - Valuepublic abstract class AssignmentAbstract<V extends Variable<V,T>,T extends Value<V,T>> extends Object implements Assignment<V,T>
Assignment object. It contains an instance of
a given assignment context holder (see AssignmentContextHolder) and
implements the assignment logic. But the actual process of storing and retrieving values
is left on the assignment implementation.Assignment| Modifier and Type | Field and Description |
|---|---|
protected AssignmentContextHolder<V,T> |
iContexts |
protected boolean |
iHasInitialzedContext |
| Constructor and Description |
|---|
AssignmentAbstract(AssignmentContextHolder<V,T> contexts)
Constructor
|
| Modifier and Type | Method and Description |
|---|---|
T |
assign(long iteration,
T value)
Assign the given value to its variable.
|
protected T |
assign(long iteration,
V variable,
T value)
Assigns a variable with the given value.
|
Collection<T> |
assignedValues()
The list of assigned values in the assignment.
|
<C extends AssignmentContext> |
clearContext(AssignmentContextReference<V,T,C> reference)
Clear an assignment context that is associated with the given a reference.
|
protected void |
ensureInitializedContext(V variable)
Ensure that the model, all criteria, all global constraints and all the related constraints have their assignment contexts initialized.
|
<C extends AssignmentContext> |
getAssignmentContext(AssignmentContextReference<V,T,C> reference)
Assignment context for a reference.
|
int |
getIndex()
Assignment index.
|
T |
getValue(V variable)
Checks if the variable is
ConstantVariable, returns getValueInternal(Variable)
if the variable is not a constant. |
protected abstract T |
getValueInternal(V variable)
Returns assignment of a variable, null if not assigned.
|
int |
nrAssignedVariables()
Number of assigned variables in this assignment.
|
int |
nrUnassignedVariables(Model<V,T> model)
Number of assigned variables in the assignment.
|
protected abstract void |
setValueInternal(long iteration,
V variable,
T value)
Sets an assignment to a variable (unassigns a variable if the given value is null).
|
T |
unassign(long iteration,
V variable)
Unassign the given variable.
|
T |
unassign(long iteration,
V variable,
T value)
Unassign the given variable, but only if the current assignment differs from the given value.
|
Collection<V> |
unassignedVariables(Model<V,T> model)
The list of variables of the model that have no value in this assignment.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitassignedVariables, getIterationprotected boolean iHasInitialzedContext
public AssignmentAbstract(AssignmentContextHolder<V,T> contexts)
contexts - an instance of the assignment context holderpublic T getValue(V variable)
ConstantVariable, returns getValueInternal(Variable)
if the variable is not a constant.protected abstract T getValueInternal(V variable)
variable - a variable in questionprotected abstract void setValueInternal(long iteration, V variable, T value)
iteration - current iterationvariable - a variable to be assignedvalue - new assignment, null if to be unassignedprotected T assign(long iteration, V variable, T value)
setValueInternal(long, Variable, Value) to store the new
assignment.iteration - current iterationvariable - a variablevalue - one of its values, null if the variable is to be unassignedpublic T assign(long iteration, T value)
AssignmentVariable.assign(int, Value).public T unassign(long iteration, V variable)
AssignmentVariable.unassign(int).public T unassign(long iteration, V variable, T value)
AssignmentVariable.unassign(int).public int nrAssignedVariables()
AssignmentModel.nrAssignedVariables().nrAssignedVariables in interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>public Collection<T> assignedValues()
AssignmentAssignment.getValue(Variable) for all assigned variables in this assignment.assignedValues in interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>public Collection<V> unassignedVariables(Model<V,T> model)
AssignmentAssignment.getValue(Variable) is null in this assignment.
Replacement for Model.unassignedVariables()unassignedVariables in interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>model - existing model (the assignment does not keep track about all existing variables, that is what the Model.variables() is for)public int nrUnassignedVariables(Model<V,T> model)
AssignmentModel.nrUnassignedVariables().nrUnassignedVariables in interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>model - existing model (the assignment does not keep track about all existing variables, that is what the Model.variables() is for)public <C extends AssignmentContext> C getAssignmentContext(AssignmentContextReference<V,T,C> reference)
AssignmentConstraintWithContext).getAssignmentContext in interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>C - assignment context typereference - a reference (which can be stored within the model, e.g., as an instance variable of a constraint)AssignmentContextpublic <C extends AssignmentContext> void clearContext(AssignmentContextReference<V,T,C> reference)
AssignmentclearContext in interface Assignment<V extends Variable<V,T>,T extends Value<V,T>>C - assignment context typereference - a reference (which can be stored within the model, e.g., as an instance variable of a constraint)public int getIndex()
Assignmentprotected void ensureInitializedContext(V variable)
variable - a variable to be changed