|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.cpsolver.ifs.model.Model
public class Model
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 EnumerableCollection |
iAssignedVariables
|
protected EnumerableCollection |
iPerturbVariables
|
protected EnumerableCollection |
iUnassignedVariables
|
protected static DecimalFormat |
sDoubleFormat
|
protected static DecimalFormat |
sPercentageFormat
|
protected static DecimalFormat |
sTimeFormat
|
Constructor Summary | |
---|---|
Model()
Constructor |
Method Summary | |
---|---|
void |
addConstraint(Constraint constraint)
Adds a constraint to the model |
void |
addGlobalConstraint(GlobalConstraint constraint)
Adds a global constraint to the model |
void |
addModelListener(ModelListener listener)
Adds a model listener |
void |
addVariable(Variable variable)
Adds a variable to the model |
void |
afterAssigned(long iteration,
Value value)
Called after a value is assigned to its variable |
void |
afterUnassigned(long iteration,
Value value)
Called after a value is unassigned from its variable |
EnumerableCollection |
assignedVariables()
The list of assigned variables in the model |
void |
beforeAssigned(long iteration,
Value value)
Called before a value is assigned to its variable |
void |
beforeUnassigned(long iteration,
Value value)
Called before a value is unassigned from its variable |
EnumerableCollection |
bestUnassignedVariables()
The list of unassigned variables in the best ever found solution |
void |
clearBest()
Clear the best ever found assignment |
Hashtable |
conflictConstraints(Value value)
The list of constraints which are in a conflict with the given value if it is assigned to its variable. |
Set |
conflictValues(Value value)
Returns the set of confliction variables with this value, if it is assigned to its variable |
Vector |
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 |
Hashtable |
getExtendedInfo()
Extended information about current solution. |
Hashtable |
getInfo()
Returns information about the current solution. |
Hashtable |
getInfo(Vector variables)
Returns information about the current solution. |
protected Vector |
getInfoProviders()
Registered info providers (see InfoProvider ) |
Vector |
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(Vector variables)
Value of the current solution. |
Vector |
globalConstraints()
The list of global constraints in the model |
boolean |
inConflict(Value value)
Return true if the given value is in conflict with a hard constraint |
boolean |
init(Solver solver)
Model initialization |
protected void |
invalidateVariablesWithInitialValueCache()
Invalidates cache containing all variables that possess an initial value |
ModelListener |
modelListenerOfType(Class type)
The list of model listeners that are of the given class |
int |
nrAssignedVariables()
Number of assigned variables |
int |
nrUnassignedVariables()
Number of unassigned variables |
EnumerableCollection |
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. |
EnumerableCollection |
perturbVariables(Vector 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 constraint)
Removes a constraint from the model |
void |
removeGlobalConstraint(GlobalConstraint constraint)
Removes a global constraint from the model |
void |
removeModelListener(ModelListener listener)
Removes a model listener |
void |
removeVariable(Variable variable)
Removes a variable from the model |
void |
restoreBest()
Restore the best ever found assignment into the current assignment |
void |
saveBest()
Save the current assignment as the best ever found assignment |
String |
toString()
|
Vector |
unassignedHardConstraints()
The list of hard constraints which contain at least one variable that is not assigned. |
EnumerableCollection |
unassignedVariables()
The list of unassigned variables in the model |
Vector |
variables()
The list of variables in the model |
Vector |
variablesWithInitialValue()
The list of variales without initial 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 EnumerableCollection iUnassignedVariables
protected EnumerableCollection iAssignedVariables
protected EnumerableCollection iPerturbVariables
Constructor Detail |
---|
public Model()
Method Detail |
---|
public Vector variables()
public int countVariables()
public void addVariable(Variable variable)
public void removeVariable(Variable variable)
public Vector constraints()
public int countConstraints()
public void addConstraint(Constraint constraint)
public void removeConstraint(Constraint constraint)
public Vector globalConstraints()
public int countGlobalConstraints()
public void addGlobalConstraint(GlobalConstraint constraint)
public void removeGlobalConstraint(GlobalConstraint constraint)
public EnumerableCollection unassignedVariables()
public int nrUnassignedVariables()
public EnumerableCollection assignedVariables()
public int nrAssignedVariables()
public EnumerableCollection perturbVariables()
public EnumerableCollection perturbVariables(Vector variables)
public Set conflictValues(Value value)
public boolean inConflict(Value value)
public Vector variablesWithInitialValue()
protected void invalidateVariablesWithInitialValueCache()
public void beforeAssigned(long iteration, Value value)
public void beforeUnassigned(long iteration, Value value)
public void afterAssigned(long iteration, Value value)
public void afterUnassigned(long iteration, Value 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 Hashtable getInfo()
public Hashtable getExtendedInfo()
getInfo()
, but some more information (that is more expensive to compute) might be added.
public Hashtable getInfo(Vector variables)
public int getBestUnassignedVariables()
public int getBestPerturbations()
public void saveBest()
public void clearBest()
public void restoreBest()
public EnumerableCollection bestUnassignedVariables()
public double getTotalValue()
Value.toDouble()
.
public double getTotalValue(Vector variables)
Value.toDouble()
.
Only variables from the given set are considered.
public void addModelListener(ModelListener listener)
public void removeModelListener(ModelListener listener)
public boolean init(Solver solver)
public Vector getModelListeners()
public ModelListener modelListenerOfType(Class type)
public Hashtable conflictConstraints(Value value)
Constraint.computeConflicts(Value, Set)
.
public Vector unassignedHardConstraints()
protected Vector getInfoProviders()
InfoProvider
)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |