V
- VariableT
- Valuepublic class Model<V extends Variable<V,T>,T extends Value<V,T>> extends Object
MyModel model = new MyModel();
Variable a = new MyVariable("A");
model.addVariable(a);
Variable b = new MyVariable("B");
model.addVariable(b);
Variable c = new MyVariable("C");
model.addVariable(c);
Constraint constr = MyConstraint("all-different");
model.addConstraint(constr);
constr.addVariable(a);
constr.addVariable(b);
constr.addVariable(c);
solver.setInitialSolution(model);
Variable
,
Constraint
,
Solution
,
Solver
Modifier and Type | Field and Description |
---|---|
protected static DecimalFormat |
sDoubleFormat |
protected static DecimalFormat |
sPercentageFormat |
protected static DecimalFormat |
sTimeFormat |
Constructor and Description |
---|
Model()
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addConstraint(Constraint<V,T> constraint)
Adds a constraint to the model
|
void |
addCriterion(Criterion<V,T> criterion)
Register a new criterion
|
void |
addGlobalConstraint(GlobalConstraint<V,T> constraint)
Adds a global constraint to the model
|
void |
addModelListener(ModelListener<V,T> listener)
Adds a model listener
|
void |
addVariable(V variable)
Adds a variable to the model
|
void |
afterAssigned(Assignment<V,T> assignment,
long iteration,
T value)
Called after a value is assigned to its variable
|
void |
afterAssigned(long iteration,
T value)
Deprecated.
|
void |
afterUnassigned(Assignment<V,T> assignment,
long iteration,
T value)
Called after a value is unassigned from its variable
|
void |
afterUnassigned(long iteration,
T value)
Deprecated.
|
Collection<V> |
assignedVariables()
Deprecated.
|
Collection<V> |
assignedVariables(Assignment<V,T> assignment)
The list of assigned variables in the model
|
void |
beforeAssigned(Assignment<V,T> assignment,
long iteration,
T value)
Called before a value is assigned to its variable
|
void |
beforeAssigned(long iteration,
T value)
Deprecated.
|
void |
beforeUnassigned(Assignment<V,T> assignment,
long iteration,
T value)
Called before a value is unassigned from its variable
|
void |
beforeUnassigned(long iteration,
T value)
Deprecated.
|
Collection<V> |
bestUnassignedVariables()
Deprecated.
|
Collection<V> |
bestUnassignedVariables(Assignment<V,T> assignment)
The list of unassigned variables in the best ever found solution
|
void |
clearAssignmentContexts(Assignment<V,T> assignment)
Clear all assignment contexts for the given assignment
|
void |
clearBest()
Clear the best ever found assignment
|
Map<Constraint<V,T>,Set<T>> |
conflictConstraints(Assignment<V,T> assignment,
T value)
The list of constraints which are in a conflict with the given value if
it is assigned to its variable.
|
Set<T> |
conflictValues(Assignment<V,T> assignment,
T value)
Returns the set of conflicting variables with this value, if it is
assigned to its variable
|
Set<T> |
conflictValues(T value)
Deprecated.
|
List<Constraint<V,T>> |
constraints()
The list of constraints in the model
|
int |
countConstraints()
The number of constraints in the model
|
int |
countGlobalConstraints()
The number of global constraints in the model
|
int |
countVariables()
The number of variables in the model
|
void |
createAssignmentContexts(Assignment<V,T> assignment,
boolean clear)
Create all assignment contexts for the given assignment
|
InheritedAssignment<V,T> |
createInheritedAssignment(Solution<V,T> solution,
int index)
Create a new inherited assignment from the given solution
|
<C extends AssignmentContext> |
createReference(HasAssignmentContext<V,T,C> parent)
Create a reference to an assignment context for a class that is in a need of one.
|
int |
getBestPerturbations()
Returns the number of perturbation variables in the best ever found
solution
|
int |
getBestUnassignedVariables()
Returns the number of unassigned variables in the best ever found
solution
|
double |
getBestValue()
Total value of the best ever found solution -- sum of all assigned values
(see
Value.toDouble(Assignment) ). |
Collection<Criterion<V,T>> |
getCriteria()
List all registered criteria
|
Criterion<V,T> |
getCriterion(Class<? extends Criterion<V,T>> criterion)
Return a registered criterion of the given type.
|
Assignment<V,T> |
getDefaultAssignment()
Deprecated.
|
Assignment<V,T> |
getEmptyAssignment()
Returns an instance of an empty assignment (using
EmptyAssignment ) |
Map<String,String> |
getExtendedInfo()
Deprecated.
|
Map<String,String> |
getExtendedInfo(Assignment<V,T> assignment)
Extended information about current solution.
|
Map<String,String> |
getInfo()
Deprecated.
|
Map<String,String> |
getInfo(Assignment<V,T> assignment)
Returns information about the current solution.
|
Map<String,String> |
getInfo(Assignment<V,T> assignment,
Collection<V> variables)
Returns information about the current solution.
|
Map<String,String> |
getInfo(Collection<V> variables)
Deprecated.
|
protected List<InfoProvider<V,T>> |
getInfoProviders()
Registered info providers (see
InfoProvider ) |
List<ModelListener<V,T>> |
getModelListeners()
The list of model listeners
|
protected String |
getPerc(double value,
double min,
double max) |
protected String |
getPercRev(double value,
double min,
double max) |
double |
getTotalValue()
Deprecated.
|
double |
getTotalValue(Assignment<V,T> assignment)
Value of the current solution.
|
double |
getTotalValue(Assignment<V,T> assignment,
Collection<V> variables)
Value of the current solution.
|
double |
getTotalValue(Collection<V> variables)
Deprecated.
|
List<GlobalConstraint<V,T>> |
globalConstraints()
The list of global constraints in the model
|
boolean |
inConflict(Assignment<V,T> assignment,
T value)
Return true if the given value is in conflict with a hard constraint
|
boolean |
inConflict(T value)
Deprecated.
|
boolean |
init(Solver<V,T> solver)
Model initialization
|
protected void |
invalidateVariablesWithInitialValueCache()
Invalidates cache containing all variables that possess an initial value
|
ModelListener<V,T> |
modelListenerOfType(Class<ModelListener<V,T>> type)
The list of model listeners that are of the given class
|
int |
nrAssignedVariables()
Deprecated.
|
int |
nrAssignedVariables(Assignment<V,T> assignment)
Number of assigned variables
|
int |
nrUnassignedVariables()
Deprecated.
|
int |
nrUnassignedVariables(Assignment<V,T> assignment)
Number of unassigned variables
|
Collection<V> |
perturbVariables()
Deprecated.
|
Collection<V> |
perturbVariables(Assignment<V,T> assignment)
The list of perturbation variables in the model, i.e., the variables
which has an initial value but which are not assigned with this value.
|
List<V> |
perturbVariables(Assignment<V,T> assignment,
Collection<V> variables)
The list of perturbation variables in the model, i.e., the variables
which has an initial value but which are not assigned with this value.
|
List<V> |
perturbVariables(Assignment<V,T> assignment,
Collection<V> variables,
boolean includeNotAssigned)
The list of perturbation variables in the model, i.e., the variables
which has an initial value but which are not assigned with this value.
|
List<V> |
perturbVariables(Collection<V> variables)
Deprecated.
|
void |
removeConstraint(Constraint<V,T> constraint)
Removes a constraint from the model
|
void |
removeCriterion(Class<? extends Criterion<V,T>> criterion)
Unregister an existing criterion
|
void |
removeCriterion(Criterion<V,T> criterion)
Unregister an existing criterion
|
void |
removeGlobalConstraint(GlobalConstraint<V,T> constraint)
Removes a global constraint from the model
|
void |
removeModelListener(ModelListener<V,T> listener)
Removes a model listener
|
<C extends AssignmentContext> |
removeReference(HasAssignmentContext<V,T,C> parent)
Remove a reference to an assignment context for the model
|
void |
removeVariable(V variable)
Removes a variable from the model
|
protected void |
restoreBest()
Deprecated.
|
void |
restoreBest(Assignment<V,T> assignment)
Restore the best ever found assignment into the current assignment
|
protected void |
restoreBest(Assignment<V,T> assignment,
Comparator<V> assignmentOrder)
Restore the best ever found assignment into the current assignment
|
void |
saveBest()
Deprecated.
|
void |
saveBest(Assignment<V,T> assignment)
Save the current assignment as the best ever found assignment
|
void |
setBestValue(double bestValue)
Set total value of the best ever found solution
|
void |
setDefaultAssignment(Assignment<V,T> assignment)
Deprecated.
|
String |
toString() |
String |
toString(Assignment<V,T> assignment)
String representation -- returns a list of values of objective criteria
|
List<Constraint<V,T>> |
unassignedHardConstraints(Assignment<V,T> assignment)
The list of hard constraints which contain at least one variable that is
not assigned.
|
Collection<V> |
unassignedVariables()
Deprecated.
|
Collection<V> |
unassignedVariables(Assignment<V,T> assignment)
The list of unassigned variables in the model
|
List<V> |
variables()
The list of variables in the model
|
Collection<V> |
variablesWithInitialValue()
The list of variables with an initial value (i.e., variables with
Variable.getInitialAssignment() not null) |
void |
weaken(Assignment<V,T> assignment,
T value)
Weaken all weakening constraint so that the given value can be assigned without
them creating a conflict using
WeakeningConstraint.weaken(Assignment, Value) . |
protected static DecimalFormat sTimeFormat
protected static DecimalFormat sDoubleFormat
protected static DecimalFormat sPercentageFormat
public Model()
public List<V> variables()
public int countVariables()
public void addVariable(V variable)
variable
- a variablepublic void removeVariable(V variable)
variable
- a variablepublic List<Constraint<V,T>> constraints()
public int countConstraints()
public void addConstraint(Constraint<V,T> constraint)
constraint
- a constraintpublic void removeConstraint(Constraint<V,T> constraint)
constraint
- a constraintpublic List<GlobalConstraint<V,T>> globalConstraints()
public int countGlobalConstraints()
public void addGlobalConstraint(GlobalConstraint<V,T> constraint)
constraint
- a global constraintpublic void removeGlobalConstraint(GlobalConstraint<V,T> constraint)
constraint
- a global constraint@Deprecated public Collection<V> unassignedVariables()
unassignedVariables(Assignment)
or Assignment.unassignedVariables(Model)
instead.public Collection<V> unassignedVariables(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public int nrUnassignedVariables()
nrUnassignedVariables(Assignment)
or Assignment.nrUnassignedVariables(Model)
instead.public int nrUnassignedVariables(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public Collection<V> assignedVariables()
assignedVariables(Assignment)
or Assignment.assignedVariables()
instead.public Collection<V> assignedVariables(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public int nrAssignedVariables()
nrAssignedVariables(Assignment)
or Assignment.nrAssignedVariables()
instead.public int nrAssignedVariables(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public Collection<V> perturbVariables()
perturbVariables(Assignment)
instead.public Collection<V> perturbVariables(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public List<V> perturbVariables(Collection<V> variables)
perturbVariables(Assignment, Collection)
instead.variables
- sub-problempublic List<V> perturbVariables(Assignment<V,T> assignment, Collection<V> variables)
assignment
- current assignmentvariables
- sub-problempublic List<V> perturbVariables(Assignment<V,T> assignment, Collection<V> variables, boolean includeNotAssigned)
assignment
- current assignmentvariables
- sub-problemincludeNotAssigned
- when true, include not assigned variables with a hard conflict (that cannot be assigned)@Deprecated public Set<T> conflictValues(T value)
conflictValues(Assignment, Value)
instead.value
- a value to be assignedpublic Set<T> conflictValues(Assignment<V,T> assignment, T value)
assignment
- current assignmentvalue
- a value to be assigned@Deprecated public boolean inConflict(T value)
inConflict(Assignment, Value)
instead.value
- a value in questionpublic boolean inConflict(Assignment<V,T> assignment, T value)
assignment
- current assignmentvalue
- a value in questionpublic Collection<V> variablesWithInitialValue()
Variable.getInitialAssignment()
not null)protected void invalidateVariablesWithInitialValueCache()
@Deprecated public void beforeAssigned(long iteration, T value)
iteration
- current iterationvalue
- a value to be assignedpublic void beforeAssigned(Assignment<V,T> assignment, long iteration, T value)
assignment
- current assignmentiteration
- current iterationvalue
- a value to be assigned@Deprecated public void beforeUnassigned(long iteration, T value)
iteration
- current iterationvalue
- a value to be unassignedpublic void beforeUnassigned(Assignment<V,T> assignment, long iteration, T value)
assignment
- current assignmentiteration
- current iterationvalue
- a value to be unassigned@Deprecated public void afterAssigned(long iteration, T value)
iteration
- current iterationvalue
- a value that was assignedpublic void afterAssigned(Assignment<V,T> assignment, long iteration, T value)
assignment
- current assignmentiteration
- current iterationvalue
- a value that was assigned@Deprecated public void afterUnassigned(long iteration, T value)
iteration
- current iterationvalue
- a value that was unassignedpublic void afterUnassigned(Assignment<V,T> assignment, long iteration, T value)
assignment
- current assignmentiteration
- current iterationvalue
- a value that was unassignedpublic String toString(Assignment<V,T> assignment)
assignment
- current assignmentAbstractCriterion.toString(Assignment)
protected String getPercRev(double value, double min, double max)
@Deprecated public Map<String,String> getInfo()
getInfo(Assignment)
instead.public Map<String,String> getInfo(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public Map<String,String> getExtendedInfo()
getInfo(Assignment)
, but some more information (that is more
expensive to compute) might be added.
Use getExtendedInfo(Assignment)
instead.public Map<String,String> getExtendedInfo(Assignment<V,T> assignment)
getInfo(Assignment)
, but some more information (that is more
expensive to compute) might be added.assignment
- current assignment@Deprecated public Map<String,String> getInfo(Collection<V> variables)
getInfo(Assignment, Collection)
instead.variables
- sub-problempublic Map<String,String> getInfo(Assignment<V,T> assignment, Collection<V> variables)
assignment
- current assignmentvariables
- sub-problempublic int getBestUnassignedVariables()
public int getBestPerturbations()
public double getBestValue()
Value.toDouble(Assignment)
).public void setBestValue(double bestValue)
bestValue
- value of the best solution@Deprecated public void saveBest()
saveBest(Assignment)
instead.public void saveBest(Assignment<V,T> assignment)
assignment
- current assignmentpublic void clearBest()
@Deprecated protected void restoreBest()
restoreBest(Assignment)
instead.protected void restoreBest(Assignment<V,T> assignment, Comparator<V> assignmentOrder)
assignment
- current assignmentassignmentOrder
- assignment order of the variablespublic void restoreBest(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public Collection<V> bestUnassignedVariables()
bestUnassignedVariables(Assignment)
instead.public Collection<V> bestUnassignedVariables(Assignment<V,T> assignment)
assignment
- current assignment@Deprecated public double getTotalValue()
Value.toDouble(Assignment)
.
Use getTotalValue(Assignment)
instead.public double getTotalValue(Assignment<V,T> assignment)
Value.toDouble(Assignment)
.assignment
- current assignment@Deprecated public double getTotalValue(Collection<V> variables)
Value.toDouble(Assignment)
. Only variables from the given set are
considered.
Use getTotalValue(Assignment, Collection)
instead.variables
- sub-problempublic double getTotalValue(Assignment<V,T> assignment, Collection<V> variables)
Value.toDouble(Assignment)
. Only variables from the given set are
considered.assignment
- current assignmentvariables
- sub-problempublic void addModelListener(ModelListener<V,T> listener)
listener
- a model listenerpublic void removeModelListener(ModelListener<V,T> listener)
listener
- a model listenerpublic boolean init(Solver<V,T> solver)
solver
- current solverpublic List<ModelListener<V,T>> getModelListeners()
public ModelListener<V,T> modelListenerOfType(Class<ModelListener<V,T>> type)
type
- model listener typepublic Map<Constraint<V,T>,Set<T>> conflictConstraints(Assignment<V,T> assignment, T value)
Constraint.computeConflicts(Assignment, Value, Set)
.assignment
- current assignmentvalue
- given valuepublic List<Constraint<V,T>> unassignedHardConstraints(Assignment<V,T> assignment)
assignment
- current assignmentprotected List<InfoProvider<V,T>> getInfoProviders()
InfoProvider
)public void addCriterion(Criterion<V,T> criterion)
criterion
- a criterionpublic void removeCriterion(Criterion<V,T> criterion)
criterion
- a criterionpublic void removeCriterion(Class<? extends Criterion<V,T>> criterion)
criterion
- a criterionpublic Criterion<V,T> getCriterion(Class<? extends Criterion<V,T>> criterion)
criterion
- criterion typepublic Collection<Criterion<V,T>> getCriteria()
public void weaken(Assignment<V,T> assignment, T value)
WeakeningConstraint.weaken(Assignment, Value)
.
This method is handy for instance when an existing solution is being loaded
into the solver.assignment
- current assignmentvalue
- given valuepublic <C extends AssignmentContext> AssignmentContextReference<V,T,C> createReference(HasAssignmentContext<V,T,C> parent)
AssignmentContext
) can be accessed using
Assignment.getAssignmentContext(AssignmentContextReference)
.C
- assignment context typeparent
- class needing an assignment contextpublic void clearAssignmentContexts(Assignment<V,T> assignment)
assignment
- given Assignment
public <C extends AssignmentContext> AssignmentContextReference<V,T,C> removeReference(HasAssignmentContext<V,T,C> parent)
C
- assignment context typeparent
- class with an assignment contextpublic void createAssignmentContexts(Assignment<V,T> assignment, boolean clear)
assignment
- given Assignment
clear
- if true Assignment.clearContext(AssignmentContextReference)
is called first@Deprecated public Assignment<V,T> getDefaultAssignment()
Variable.getAssignment()
assignments.DefaultSingleAssignment
@Deprecated public void setDefaultAssignment(Assignment<V,T> assignment)
assignment
- current assignment to become defaultpublic Assignment<V,T> getEmptyAssignment()
EmptyAssignment
)public InheritedAssignment<V,T> createInheritedAssignment(Solution<V,T> solution, int index)
solution
- a solution that is using this modelindex
- thread index of the new assignment