|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.cpsolver.ifs.model.Model<V,T>
public class Model<V extends Variable<V,T>,T extends Value<V,T>>
Generic model (definition of a problem).
It consists of variables and constraints. It has also capability of
memorizing the current and the best ever found assignment.
Example usage:
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
Field Summary | |
---|---|
protected Collection<V> |
iAssignedVariables
|
protected Collection<V> |
iPerturbVariables
|
protected Collection<V> |
iUnassignedVariables
|
protected static DecimalFormat |
sDoubleFormat
|
protected static DecimalFormat |
sPercentageFormat
|
protected static DecimalFormat |
sTimeFormat
|
Constructor Summary | |
---|---|
Model()
Constructor |
Method Summary | |
---|---|
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(long iteration,
T value)
Called after a value is assigned to its variable |
void |
afterUnassigned(long iteration,
T value)
Called after a value is unassigned from its variable |
Collection<V> |
assignedVariables()
The list of assigned variables in the model |
void |
beforeAssigned(long iteration,
T value)
Called before a value is assigned to its variable |
void |
beforeUnassigned(long iteration,
T value)
Called before a value is unassigned from its variable |
Collection<V> |
bestUnassignedVariables()
The list of unassigned variables in the best ever found solution |
void |
clearBest()
Clear the best ever found assignment |
Map<Constraint<V,T>,Set<T>> |
conflictConstraints(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(T value)
Returns the set of conflicting variables with this value, if it is assigned to its variable |
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 |
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 |
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. |
Map<String,String> |
getExtendedInfo()
Extended information about current solution. |
Map<String,String> |
getInfo()
Returns information about the current solution. |
Map<String,String> |
getInfo(Collection<V> variables)
Returns information about the current solution. |
protected List<InfoProvider<V>> |
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()
Value of the current solution. |
double |
getTotalValue(Collection<V> variables)
Value of the current solution. |
List<GlobalConstraint<V,T>> |
globalConstraints()
The list of global constraints in the model |
boolean |
inConflict(T value)
Return true if the given value is in conflict with a hard constraint |
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()
Number of assigned variables |
int |
nrUnassignedVariables()
Number of unassigned variables |
Collection<V> |
perturbVariables()
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)
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. |
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 |
void |
removeVariable(V variable)
Removes a variable from the model |
void |
restoreBest()
|
protected void |
restoreBest(Comparator<V> assignmentOrder)
Restore the best ever found assignment into the current assignment |
void |
saveBest()
Save the current assignment as the best ever found assignment |
String |
toString()
|
List<Constraint<V,T>> |
unassignedHardConstraints()
The list of hard constraints which contain at least one variable that is not assigned. |
Collection<V> |
unassignedVariables()
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 without initial value |
void |
weaken(T value)
Weaken all weakening constraint so that the given value can be assigned without them creating a conflict using WeakeningConstraint.weaken(Value) . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static DecimalFormat sTimeFormat
protected static DecimalFormat sDoubleFormat
protected static DecimalFormat sPercentageFormat
protected Collection<V extends Variable<V,T>> iUnassignedVariables
protected Collection<V extends Variable<V,T>> iAssignedVariables
protected Collection<V extends Variable<V,T>> iPerturbVariables
Constructor Detail |
---|
public Model()
Method Detail |
---|
public List<V> variables()
public int countVariables()
public void addVariable(V variable)
public void removeVariable(V variable)
public List<Constraint<V,T>> constraints()
public int countConstraints()
public void addConstraint(Constraint<V,T> constraint)
public void removeConstraint(Constraint<V,T> constraint)
public List<GlobalConstraint<V,T>> globalConstraints()
public int countGlobalConstraints()
public void addGlobalConstraint(GlobalConstraint<V,T> constraint)
public void removeGlobalConstraint(GlobalConstraint<V,T> constraint)
public Collection<V> unassignedVariables()
public int nrUnassignedVariables()
public Collection<V> assignedVariables()
public int nrAssignedVariables()
public Collection<V> perturbVariables()
public List<V> perturbVariables(Collection<V> variables)
public Set<T> conflictValues(T value)
public boolean inConflict(T value)
public Collection<V> variablesWithInitialValue()
protected void invalidateVariablesWithInitialValueCache()
public void beforeAssigned(long iteration, T value)
public void beforeUnassigned(long iteration, T value)
public void afterAssigned(long iteration, T value)
public void afterUnassigned(long iteration, T value)
public String toString()
toString
in class Object
protected String getPerc(double value, double min, double max)
protected String getPercRev(double value, double min, double max)
public Map<String,String> getInfo()
public Map<String,String> getExtendedInfo()
getInfo()
, but some more information (that is more
expensive to compute) might be added.
public Map<String,String> getInfo(Collection<V> variables)
public int getBestUnassignedVariables()
public int getBestPerturbations()
public void saveBest()
public void clearBest()
protected void restoreBest(Comparator<V> assignmentOrder)
public void restoreBest()
public Collection<V> bestUnassignedVariables()
public double getTotalValue()
Value.toDouble()
.
public double getTotalValue(Collection<V> variables)
Value.toDouble()
. Only variables from the given set are
considered.
public void addModelListener(ModelListener<V,T> listener)
public void removeModelListener(ModelListener<V,T> listener)
public boolean init(Solver<V,T> solver)
public List<ModelListener<V,T>> getModelListeners()
public ModelListener<V,T> modelListenerOfType(Class<ModelListener<V,T>> type)
public Map<Constraint<V,T>,Set<T>> conflictConstraints(T value)
Constraint.computeConflicts(Value, Set)
.
public List<Constraint<V,T>> unassignedHardConstraints()
protected List<InfoProvider<V>> getInfoProviders()
InfoProvider
)
public void addCriterion(Criterion<V,T> criterion)
public void removeCriterion(Criterion<V,T> criterion)
public void removeCriterion(Class<? extends Criterion<V,T>> criterion)
public Criterion<V,T> getCriterion(Class<? extends Criterion<V,T>> criterion)
public Collection<Criterion<V,T>> getCriteria()
public void weaken(T value)
WeakeningConstraint.weaken(Value)
.
This method is handy for instance when an existing solution is being loaded
into the solver.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |