V - VariableT - Valuepublic abstract class AbstractCriterion<V extends Variable<V,T>,T extends Value<V,T>> extends Object implements Criterion<V,T>, HasAssignmentContext<V,T,AbstractCriterion.ValueContext>, CanHoldContext
Criterion except of the Criterion.getValue(Assignment, Value, Set).| Modifier and Type | Class and Description |
|---|---|
class |
AbstractCriterion.ValueContext
Assignment context holding current value and the cached bounds.
|
protected static class |
AbstractCriterion.ValueUpdateType
Defines how the overall value of the criterion should be automatically updated (using
Criterion.getValue(Value, Set)). |
| Modifier and Type | Field and Description |
|---|---|
protected double |
iBest |
protected boolean |
iDebug |
protected double |
iWeight |
protected static DecimalFormat |
sDoubleFormat |
protected static DecimalFormat |
sPercentFormat |
sMaxSize| Constructor and Description |
|---|
AbstractCriterion() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterAssigned(Assignment<V,T> assignment,
long iteration,
T value)
Called after a value is assigned to its variable (
Value.variable()). |
void |
afterUnassigned(Assignment<V,T> assignment,
long iteration,
T value)
Called after a value is unassigned from its variable (
Value.variable()). |
void |
beforeAssigned(Assignment<V,T> assignment,
long iteration,
T value)
Called before a value is assigned to its variable (
Value.variable()). |
void |
beforeUnassigned(Assignment<V,T> assignment,
long iteration,
T value)
Called before a value is unassigned from its variable (
Value.variable()). |
void |
bestRestored(Assignment<V,T> assignment)
Notification that the current solution has been restored from the best.
|
void |
bestSaved(Assignment<V,T> assignment)
Notification that the current solution has been saved to the best.
|
protected void |
clearCache()
Clear bounds cache
|
protected double[] |
computeBounds(Assignment<V,T> assignment)
Compute bounds (bounds are being cached by default).
|
void |
configure(DataProperties properties)
Configure the criterion if needed
|
void |
constraintAdded(Constraint<V,T> constraint)
Constraint is added to the model
|
void |
constraintRemoved(Constraint<V,T> constraint)
Constraint is removed from the model
|
AbstractCriterion.ValueContext |
createAssignmentContext(Assignment<V,T> assignment)
Create a new assignment context for the given assignment.
|
String |
getAbbreviation()
Abbreviated name of the criterion for
Object.toString(). |
AssignmentContextReference<V,T,AbstractCriterion.ValueContext> |
getAssignmentContextReference()
Returns an assignment context reference
|
double |
getBest()
Best value (value of the criterion in the best solution)
|
double[] |
getBounds()
Deprecated.
|
double[] |
getBounds(Assignment<V,T> assignment)
Bounds (minimum and maximum) estimate for the value
|
double[] |
getBounds(Assignment<V,T> assignment,
Collection<V> variables)
Value bounds (minimum and maximum) of the criterion on a part of the problem
|
double[] |
getBounds(Collection<V> variables)
Deprecated.
|
AssignmentContext[] |
getContext()
An array of
CanHoldContext.sMaxSize assignment contexts |
AbstractCriterion.ValueContext |
getContext(Assignment<V,T> assignment)
Returns an assignment context associated with this criterion.
|
void |
getExtendedInfo(Assignment<V,T> assignment,
Map<String,String> info)
Extended information about current solution.
|
void |
getInfo(Assignment<V,T> assignment,
Map<String,String> info)
Adds some information into the table with information about the solution
|
void |
getInfo(Assignment<V,T> assignment,
Map<String,String> info,
Collection<V> variables)
Adds some information into the table with information about the solution,
only consider variables from the given set
|
Model<V,T> |
getModel()
Returns current model
|
String |
getName()
Criterion name
|
protected String |
getPerc(double value,
double min,
double max) |
String |
getPercentage(Assignment<V,T> assignment)
Return formatted value of this criterion, as percentage when possible
|
protected String |
getPercRev(double value,
double min,
double max) |
double |
getValue(Assignment<V,T> assignment)
Current value of the criterion (optimization objective)
|
double |
getValue(Assignment<V,T> assignment,
Collection<V> variables)
Value of a part of the problem (given by the collection of variables)
|
double |
getValue(Collection<V> variables)
Deprecated.
|
double |
getValue(T value,
Set<T> conflicts)
Deprecated.
|
AbstractCriterion.ValueUpdateType |
getValueUpdateType() |
double |
getWeight()
Weight of the criterion
|
double |
getWeightDefault(DataProperties config)
Defines default weight (when
getWeightName() parameter is not present in the criterion). |
double |
getWeightedBest()
Weighted best value of the objective (value in the best solution).
|
double |
getWeightedValue()
Deprecated.
|
double |
getWeightedValue(Assignment<V,T> assignment)
Weighted value of the objectives
|
double |
getWeightedValue(Assignment<V,T> assignment,
Collection<V> variables)
Weighted value of a part of the problem (given by the collection of variables)
|
double |
getWeightedValue(Assignment<V,T> assignment,
T value,
Set<T> conflicts)
Weighted value of a proposed assignment (including hard conflicts)
|
double |
getWeightedValue(Collection<V> variables)
Deprecated.
|
double |
getWeightedValue(T value,
Set<T> conflicts)
Deprecated.
|
String |
getWeightName()
Defines weight name (to be used to get the criterion weight from the configuration).
|
void |
inc(Assignment<V,T> assignment,
double value)
Outside update of the criterion (usefull when the criterion is driven by a set of constraints).
|
void |
inc(double value)
Deprecated.
|
boolean |
init(Solver<V,T> solver)
Notification that the model was initialized by the solver.
|
void |
setAssignmentContextReference(AssignmentContextReference<V,T,AbstractCriterion.ValueContext> reference)
Store an assignment context reference that was given for the class by the
Model.createReference(HasAssignmentContext). |
void |
setModel(Model<V,T> model)
called when the criterion is added to a model
|
void |
setValueUpdateType(AbstractCriterion.ValueUpdateType iValueUpdateType) |
String |
toString(Assignment<V,T> assignment)
Simple text representation of the criterion and its value.
|
void |
variableAdded(V variable)
Variable is added to the model
|
void |
variableRemoved(V variable)
Variable is removed from the model
|
protected double iBest
protected double iWeight
protected static DecimalFormat sDoubleFormat
protected static DecimalFormat sPercentFormat
protected boolean iDebug
public AbstractCriterion()
public String getWeightName()
public double getWeightDefault(DataProperties config)
getWeightName() parameter is not present in the criterion).config - solver configurationpublic void setModel(Model<V,T> model)
Criterionpublic void configure(DataProperties properties)
Criterionpublic boolean init(Solver<V,T> solver)
ModelListenerpublic AbstractCriterion.ValueContext getContext(Assignment<V,T> assignment)
HasAssignmentContext.createAssignmentContext(Assignment) method. From that time on,
this context is kept with the assignment and automatically updated by calling the
AssignmentConstraintContext.assigned(Assignment, Value) and AssignmentConstraintContext.unassigned(Assignment, Value)
whenever a variable is changed as given by the AbstractCriterion.ValueUpdateType.getContext in interface HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,AbstractCriterion.ValueContext>assignment - given assignmentpublic AbstractCriterion.ValueContext createAssignmentContext(Assignment<V,T> assignment)
HasAssignmentContextcreateAssignmentContext in interface HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,AbstractCriterion.ValueContext>assignment - an assignment for which there needs to be an assignment contextpublic AssignmentContextReference<V,T,AbstractCriterion.ValueContext> getAssignmentContextReference()
HasAssignmentContextgetAssignmentContextReference in interface HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,AbstractCriterion.ValueContext>Model.createReference(HasAssignmentContext) during initializationpublic void setAssignmentContextReference(AssignmentContextReference<V,T,AbstractCriterion.ValueContext> reference)
HasAssignmentContextModel.createReference(HasAssignmentContext).setAssignmentContextReference in interface HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,AbstractCriterion.ValueContext>reference - reference provided by the model by calling Model.createReference(HasAssignmentContext) during initializationpublic AssignmentContext[] getContext()
CanHoldContextCanHoldContext.sMaxSize assignment contextsgetContext in interface CanHoldContextpublic double getValue(Assignment<V,T> assignment)
Criterionpublic double getBest()
Criterionpublic double getValue(Assignment<V,T> assignment, Collection<V> variables)
Criterionpublic double getWeight()
Criterionpublic double getWeightedBest()
Criterionpublic double getWeightedValue(Assignment<V,T> assignment)
Criterionpublic double getWeightedValue(Assignment<V,T> assignment, T value, Set<T> conflicts)
Criterionpublic double getWeightedValue(Assignment<V,T> assignment, Collection<V> variables)
Criterionprotected double[] computeBounds(Assignment<V,T> assignment)
assignment - current assignmentpublic double[] getBounds(Assignment<V,T> assignment)
Criterionpublic double[] getBounds(Assignment<V,T> assignment, Collection<V> variables)
Criterionpublic void beforeAssigned(Assignment<V,T> assignment, long iteration, T value)
ModelListenerValue.variable()).beforeAssigned in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>assignment - current assignmentiteration - current iterationvalue - value to be assignedpublic void afterAssigned(Assignment<V,T> assignment, long iteration, T value)
ModelListenerValue.variable()).afterAssigned in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>assignment - current assignmentiteration - current iterationvalue - value to be assignedpublic void beforeUnassigned(Assignment<V,T> assignment, long iteration, T value)
ModelListenerValue.variable()).beforeUnassigned in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>assignment - current assignmentiteration - current iterationvalue - value to be unassignedpublic void afterUnassigned(Assignment<V,T> assignment, long iteration, T value)
ModelListenerValue.variable()).afterUnassigned in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>assignment - current assignmentiteration - current iterationvalue - value to be unassignedpublic void bestSaved(Assignment<V,T> assignment)
Criterionpublic void bestRestored(Assignment<V,T> assignment)
Criterionpublic void inc(Assignment<V,T> assignment, double value)
Criterionprotected void clearCache()
public void variableAdded(V variable)
ModelListenervariableAdded in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>variable - added variablepublic void variableRemoved(V variable)
ModelListenervariableRemoved in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>variable - removed variablepublic void constraintAdded(Constraint<V,T> constraint)
ModelListenerconstraintAdded in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>constraint - added constraintpublic void constraintRemoved(Constraint<V,T> constraint)
ModelListenerconstraintRemoved in interface ModelListener<V extends Variable<V,T>,T extends Value<V,T>>constraint - removed constraintprotected String getPercRev(double value, double min, double max)
public void getInfo(Assignment<V,T> assignment, Map<String,String> info)
InfoProviderpublic void getInfo(Assignment<V,T> assignment, Map<String,String> info, Collection<V> variables)
InfoProviderpublic String getPercentage(Assignment<V,T> assignment)
assignment - current assignmentpublic void getExtendedInfo(Assignment<V,T> assignment, Map<String,String> info)
ExtendedInfoProviderInfoProvider.getInfo(Assignment, Map), but some more information (that is more
expensive to compute) might be added.getExtendedInfo in interface ExtendedInfoProvider<V extends Variable<V,T>,T extends Value<V,T>>assignment - current assignmentinfo - extended info@Deprecated public double getWeightedValue()
CriterionCriterion.getWeightedValue(Assignment) instead.@Deprecated public double[] getBounds()
CriterionCriterion.getBounds(Assignment) instead.@Deprecated public double getWeightedValue(T value, Set<T> conflicts)
CriterionCriterion.getWeightedValue(Assignment, Value, Set) instead.@Deprecated public double getValue(T value, Set<T> conflicts)
CriterionCriterion.getValue(Assignment, Value, Set) instead.@Deprecated public double getWeightedValue(Collection<V> variables)
CriterionCriterion.getWeightedValue(Assignment, Collection) instead.@Deprecated public double getValue(Collection<V> variables)
CriterionCriterion.getValue(Assignment, Collection) instead.@Deprecated public double[] getBounds(Collection<V> variables)
CriterionCriterion.getBounds(Assignment, Collection) instead.@Deprecated public void inc(double value)
CriterionCriterion.inc(Assignment, double) instead.public String getAbbreviation()
Object.toString().public String toString(Assignment<V,T> assignment)
getAbbreviation()
and x is the current value getValue(Assignment).public AbstractCriterion.ValueUpdateType getValueUpdateType()
public void setValueUpdateType(AbstractCriterion.ValueUpdateType iValueUpdateType)