net.sf.cpsolver.ifs.model
Class Model

java.lang.Object
  extended by net.sf.cpsolver.ifs.model.Model
Direct Known Subclasses:
ConstantModel, CSPModel, ExamModel, JobShopModel, MultiModel, RPPModel, StructuredCSPModel, StudentSctBBTest, StudentSectioningModel, TimetableModel

public class Model
extends Object

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:

Version:
IFS 1.1 (Iterative Forward Search)
Copyright (C) 2006 Tomáš Müller
muller@unitime.org
Lazenska 391, 76314 Zlin, Czech Republic

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
See Also:
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

sTimeFormat

protected static DecimalFormat sTimeFormat

sDoubleFormat

protected static DecimalFormat sDoubleFormat

sPercentageFormat

protected static DecimalFormat sPercentageFormat

iUnassignedVariables

protected EnumerableCollection iUnassignedVariables

iAssignedVariables

protected EnumerableCollection iAssignedVariables

iPerturbVariables

protected EnumerableCollection iPerturbVariables
Constructor Detail

Model

public Model()
Constructor

Method Detail

variables

public Vector variables()
The list of variables in the model


countVariables

public int countVariables()
The number of variables in the model


addVariable

public void addVariable(Variable variable)
Adds a variable to the model


removeVariable

public void removeVariable(Variable variable)
Removes a variable from the model


constraints

public Vector constraints()
The list of constraints in the model


countConstraints

public int countConstraints()
The number of constraints in the model


addConstraint

public void addConstraint(Constraint constraint)
Adds a constraint to the model


removeConstraint

public void removeConstraint(Constraint constraint)
Removes a constraint from the model


globalConstraints

public Vector globalConstraints()
The list of global constraints in the model


countGlobalConstraints

public int countGlobalConstraints()
The number of global constraints in the model


addGlobalConstraint

public void addGlobalConstraint(GlobalConstraint constraint)
Adds a global constraint to the model


removeGlobalConstraint

public void removeGlobalConstraint(GlobalConstraint constraint)
Removes a global constraint from the model


unassignedVariables

public EnumerableCollection unassignedVariables()
The list of unassigned variables in the model


nrUnassignedVariables

public int nrUnassignedVariables()
Number of unassigned variables


assignedVariables

public EnumerableCollection assignedVariables()
The list of assigned variables in the model


nrAssignedVariables

public int nrAssignedVariables()
Number of assigned variables


perturbVariables

public 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.


perturbVariables

public 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. Only variables from the given set are considered.


conflictValues

public Set conflictValues(Value value)
Returns the set of confliction variables with this value, if it is assigned to its variable


inConflict

public boolean inConflict(Value value)
Return true if the given value is in conflict with a hard constraint


variablesWithInitialValue

public Vector variablesWithInitialValue()
The list of variales without initial value


invalidateVariablesWithInitialValueCache

protected void invalidateVariablesWithInitialValueCache()
Invalidates cache containing all variables that possess an initial value


beforeAssigned

public void beforeAssigned(long iteration,
                           Value value)
Called before a value is assigned to its variable


beforeUnassigned

public void beforeUnassigned(long iteration,
                             Value value)
Called before a value is unassigned from its variable


afterAssigned

public void afterAssigned(long iteration,
                          Value value)
Called after a value is assigned to its variable


afterUnassigned

public void afterUnassigned(long iteration,
                            Value value)
Called after a value is unassigned from its variable


toString

public String toString()
Overrides:
toString in class Object

getPerc

protected String getPerc(double value,
                         double min,
                         double max)

getPercRev

protected String getPercRev(double value,
                            double min,
                            double max)

getInfo

public Hashtable getInfo()
Returns information about the current solution. Information from all model listeners and constraints is also included.


getExtendedInfo

public Hashtable getExtendedInfo()
Extended information about current solution. Similar to getInfo(), but some more information (that is more expensive to compute) might be added.


getInfo

public Hashtable getInfo(Vector variables)
Returns information about the current solution. Information from all model listeners and constraints is also included. Only variables from the given set are considered.


getBestUnassignedVariables

public int getBestUnassignedVariables()
Returns the number of unassigned variables in the best ever found solution


getBestPerturbations

public int getBestPerturbations()
Returns the number of perturbation variables in the best ever found solution


saveBest

public void saveBest()
Save the current assignment as the best ever found assignment


clearBest

public void clearBest()
Clear the best ever found assignment


restoreBest

public void restoreBest()
Restore the best ever found assignment into the current assignment


bestUnassignedVariables

public EnumerableCollection bestUnassignedVariables()
The list of unassigned variables in the best ever found solution


getTotalValue

public double getTotalValue()
Value of the current solution. It is the sum of all assigned values, i.e., Value.toDouble().


getTotalValue

public double getTotalValue(Vector variables)
Value of the current solution. It is the sum of all assigned values, i.e., Value.toDouble(). Only variables from the given set are considered.


addModelListener

public void addModelListener(ModelListener listener)
Adds a model listener


removeModelListener

public void removeModelListener(ModelListener listener)
Removes a model listener


init

public boolean init(Solver solver)
Model initialization


getModelListeners

public Vector getModelListeners()
The list of model listeners


modelListenerOfType

public ModelListener modelListenerOfType(Class type)
The list of model listeners that are of the given class


conflictConstraints

public Hashtable conflictConstraints(Value value)
The list of constraints which are in a conflict with the given value if it is assigned to its variable. This means the constraints, which adds a value into the set of conflicting values in Constraint.computeConflicts(Value, Set).


unassignedHardConstraints

public Vector unassignedHardConstraints()
The list of hard constraints which contain at least one variable that is not assigned.


getInfoProviders

protected Vector getInfoProviders()
Registered info providers (see InfoProvider)