choco.cp.model
Class CPModel

java.lang.Object
  extended by choco.cp.model.CPModel
All Implemented Interfaces:
IPretty, Model, Serializable
Direct Known Subclasses:
ASAPCPModel, CarSeqModel, CPModel2, NSPModel, Picross, RackConfig, RackConfig2, RuleModel, SimpleSchedule

public class CPModel
extends Object
implements Model

A model is a global structure containing variables bound by listeners as well as solutions or strategy parameters

See Also:
Serialized Form

Field Summary
protected  TIHIterator<Constraint> _iterator
           
protected  ComponentConstraintWithSubConstraints clausesStore
           
protected  DeterministicIndicedList<Variable> constantVars
          All the constant vars in the model
protected  DeterministicIndicedList<Constraint> constraints
          All the constraint of the model
protected  Boolean defDecExp
          Decomposed expression
protected  DeterministicIndicedList<IntegerExpressionVariable> expVars
          All the search intVars in the model.
protected  DeterministicIndicedList<RealVariable> floatVars
          All the float vars in the model.
protected  DeterministicIndicedList<IntegerVariable> intVars
          All the search intVars in the model.
protected static Logger LOGGER
           
protected  int nbBoolVar
           
static Properties properties
          Properties file
protected  DeterministicIndicedList<SetVariable> setVars
          All the set intVars in the model.
protected  DeterministicIndicedList<MultipleVariables> storedMultipleVariables
           
 
Constructor Summary
CPModel()
          Constructor.
CPModel(int nbCstrs, int nbIntVars, int nbSetVars, int nbRealVars, int nbCsts, int nbExpVars, int nbMultVars)
          Constructor.
 
Method Summary
 void addConstraint(Constraint... c)
          Deprecated.  
 void addConstraint(Constraint c)
          Add one constraint to the model.
 void addConstraint(String options, Constraint... c)
          Deprecated.  
 void addConstraint(String options, Constraint c)
          Add one constraint to the model.
 void addConstraints(Constraint... c)
          Add one or more constraint to the model.
 void addConstraints(String options, Constraint... tabc)
          Add constraints to the model
 void addOptions(String options, IOptions... element)
           
 void addVariable(String options, Variable... v)
          Deprecated.  
 void addVariable(String options, Variable v)
          Add one variable with options to the model
 void addVariable(Variable... v)
          Deprecated.  
 void addVariable(Variable v)
          Add a variable to the model
 void addVariables(String options, Variable... tabv)
          Add variables to CPModel.
 void addVariables(Variable... tabv)
          Add variables to the model.
 String constraintsToString()
          Create and return a string representation of the constraints of the Model
 boolean contains(Constraint c)
           
 IntegerConstantVariable getConstantVar(int i)
          Returns a constant variable.
 Constraint getConstraint(int i)
          Network management: Retrieve a constraint by its index.
 DisposableIterator<Constraint> getConstraintByType(ConstraintType t)
          Return an iterator over constraint of a certain type
 Iterator<Constraint> getConstraintIterator()
          Return an iterator over the constraints of the model
 Iterator<Variable> getConstVarIterator()
          Retrieves an iterator over constantes variables of the model
 Boolean getDefaultExpressionDecomposition()
          Return the default expression decomposition
 Iterator<IntegerExpressionVariable> getExprVarIterator()
           
 Iterator<Constraint> getIntConstraintIterator()
          Deprecated.  
 IntegerVariable getIntVar(int i)
          Network management: Retrieve a variable by its index (all integer variables of the model are numbered in sequence from 0 on)
 int getIntVarIndex(IntDomainVar c)
          Deprecated. 
 int getIntVarIndex(IntVar c)
          Deprecated. 
 Iterator<IntegerVariable> getIntVarIterator()
          Retrieves an iterator over IntegerVariables of the model
 Iterator<MultipleVariables> getMultipleVarIterator()
          Retrieves an iterator over MultipleVariables of the model (if stored)
 int getNbBoolVar()
          return the number of boolean variable (with binary domain) of the model
 int getNbConstantVars()
          Returns the number of variables modelling constant.
 int getNbConstraintByType(ConstraintType t)
          Return the number of constraint of a certain type
 int getNbConstraints()
          retrieving the total number of constraint
 int getNbIntVars()
          retrieving the total number of variables
 int getNbRealVars()
          Returns the number of variables modelling real numbers.
 int getNbSetVars()
          Returns the number of variables modelling real numbers.
 int getNbStoredMultipleVars()
          Returns the number of stored multiple variables.
 int getNbTotVars()
          Return the total numbers of variables of the model
 RealVariable getRealVar(int i)
          Returns a real variable.
 Iterator<RealVariable> getRealVarIterator()
          Retrieves an iterator over RealVariables of the model
 SetVariable getSetVar(int i)
          Returns a set variable.
 Iterator<SetVariable> getSetVarIterator()
          Retrieves an iterator over SetVariables of the model
 MultipleVariables getStoredMultipleVar(int i)
          Returns a multiple variable.
 String pretty()
          pretty printing of the object.
static CPModel readFromFile(File file)
          Restore flatten CPModel from the given file.
 void remove(Object ob)
           
 void removeConstraint(Constraint c)
          Remove a constraint from the model.
 void removeConstraints()
          Empty this by removing everry added constraints.
protected
<E extends Variable>
void
removeVariable(E v, DeterministicIndicedList<E> vars)
          Deprecated. 
 void removeVariable(Variable... v)
          Deprecated.  
 void removeVariable(Variable v)
          Remove one variable from the model (also remove constraints linked to the variable)
 void removeVariables(Variable... v)
          Remove one or more variables from the model (also remove constraints linked to the variables)
protected
<E extends Variable>
void
remVariable(E v)
           
 void setDefaultExpressionDecomposition(Boolean defDecExp)
          Set the default expression decomposition (BEWARE : it only concerns expression without particular decomposition option) If decomposedExp is set to false: Every expression is then used to check a tuple in a dynamic way just like a nary relation that is defined without listing all the possible tuples.
 String solutionToString()
          Return a string representation of a solution. !!
 String varsToString()
          Create and return a string representation of the variables of the Model
static File writeInFile(CPModel model)
          Kicks off the serialization mechanism and flatten the model into a file in the default temporary-file directory.
static void writeInFile(CPModel model, File file)
          Kicks off the serialization mechanism and flatten the model into the given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

protected static final Logger LOGGER

constraints

protected final DeterministicIndicedList<Constraint> constraints
All the constraint of the model


intVars

protected final DeterministicIndicedList<IntegerVariable> intVars
All the search intVars in the model.


nbBoolVar

protected int nbBoolVar

setVars

protected final DeterministicIndicedList<SetVariable> setVars
All the set intVars in the model.


floatVars

protected final DeterministicIndicedList<RealVariable> floatVars
All the float vars in the model.


constantVars

protected final DeterministicIndicedList<Variable> constantVars
All the constant vars in the model


expVars

protected final DeterministicIndicedList<IntegerExpressionVariable> expVars
All the search intVars in the model.


storedMultipleVariables

protected final DeterministicIndicedList<MultipleVariables> storedMultipleVariables

defDecExp

protected Boolean defDecExp
Decomposed expression


clausesStore

protected ComponentConstraintWithSubConstraints clausesStore

_iterator

protected TIHIterator<Constraint> _iterator

properties

public static final Properties properties
Properties file

Constructor Detail

CPModel

public CPModel()
Constructor. Create srtuctures for a model of constraint programming.


CPModel

public CPModel(int nbCstrs,
               int nbIntVars,
               int nbSetVars,
               int nbRealVars,
               int nbCsts,
               int nbExpVars,
               int nbMultVars)
Constructor. Create srtuctures for a model of constraint programming.

Parameters:
nbCstrs - estimated number of constraints
nbIntVars - estimated number of integer variables
nbSetVars - estimated number of set variables
nbRealVars - estimated number of real variables
nbCsts - estimated number of constants
nbExpVars - estimated number of expression variables
nbMultVars - estimated number of multiples variables
Method Detail

removeConstraints

public void removeConstraints()
Empty this by removing everry added constraints. A consequence is that every variables declared will also be removed properly.
This method must be called when this becomes obsolet and variables or constraints are shared between mutliple models. This prevents from alive references of useless constraints within variables which consequences can be slowing down execution and large memory usage with useless calls to gc.


pretty

public String pretty()
Description copied from interface: IPretty
pretty printing of the object. This String is not constant and may depend on the context.

Specified by:
pretty in interface IPretty
Returns:
a readable string representation of the object

varsToString

public String varsToString()
Description copied from interface: Model
Create and return a string representation of the variables of the Model

Specified by:
varsToString in interface Model
Returns:
a string print of variables of the model

constraintsToString

public String constraintsToString()
Description copied from interface: Model
Create and return a string representation of the constraints of the Model

Specified by:
constraintsToString in interface Model
Returns:
a string print of the constraints of the Model

solutionToString

public String solutionToString()
Description copied from interface: Model
Return a string representation of a solution. !! Beware, not really correct!! Use Solver API instead

Specified by:
solutionToString in interface Model
Returns:
a string represenstation of the variables of the model
See Also:
IPretty.pretty()

getIntVarIndex

@Deprecated
public int getIntVarIndex(IntDomainVar c)
Deprecated. 

Description copied from interface: Model
Retrieves the index of an IntDomainVar

Specified by:
getIntVarIndex in interface Model
Parameters:
c - Solver variable
Returns:
the indexe of the solver variable in the model.

getIntVarIndex

@Deprecated
public int getIntVarIndex(IntVar c)
Deprecated. 

Description copied from interface: Model
Return the index of the intVar in the model

Specified by:
getIntVarIndex in interface Model
Parameters:
c - the int var
Returns:
the index

getDefaultExpressionDecomposition

public Boolean getDefaultExpressionDecomposition()
Description copied from interface: Model
Return the default expression decomposition

Specified by:
getDefaultExpressionDecomposition in interface Model
Returns:
the default expression decomposition

setDefaultExpressionDecomposition

public void setDefaultExpressionDecomposition(Boolean defDecExp)
Description copied from interface: Model
Set the default expression decomposition (BEWARE : it only concerns expression without particular decomposition option) If decomposedExp is set to false: Every expression is then used to check a tuple in a dynamic way just like a nary relation that is defined without listing all the possible tuples. The expression is then propagated using the GAC3rm algorithm. This is very powerful as arc-consistency is obtained on the corresponding constraints. If decomposedExp is set to true, every expression will be decomposed automatically by introducing intermediate variables and eventually the generic reifiedIntConstraint if reified operators are present in the expression. By doing so, the level of pruning will decrease but expressions of larger arity involving large domains can be represented.

Specified by:
setDefaultExpressionDecomposition in interface Model
Parameters:
defDecExp - the new default expression decomposition

getIntVar

public final IntegerVariable getIntVar(int i)
Network management: Retrieve a variable by its index (all integer variables of the model are numbered in sequence from 0 on)

Specified by:
getIntVar in interface Model
Parameters:
i - index of the variable in the model
Returns:
IntegerVariable

getNbIntVars

public final int getNbIntVars()
retrieving the total number of variables

Specified by:
getNbIntVars in interface Model
Returns:
the total number of variables in the model

getRealVar

public final RealVariable getRealVar(int i)
Returns a real variable.

Specified by:
getRealVar in interface Model
Parameters:
i - index of the variable
Returns:
the i-th real variable

getNbRealVars

public final int getNbRealVars()
Returns the number of variables modelling real numbers.

Specified by:
getNbRealVars in interface Model
Returns:
int

getSetVar

public final SetVariable getSetVar(int i)
Returns a set variable.

Specified by:
getSetVar in interface Model
Parameters:
i - index of the variable
Returns:
the i-th real variable

getNbSetVars

public final int getNbSetVars()
Returns the number of variables modelling real numbers.

Specified by:
getNbSetVars in interface Model
Returns:
int

getNbTotVars

public int getNbTotVars()
Description copied from interface: Model
Return the total numbers of variables of the model

Specified by:
getNbTotVars in interface Model
Returns:
total number of variables of the model
See Also:
Model.getNbTotVars()

getConstantVar

public IntegerConstantVariable getConstantVar(int i)
Returns a constant variable.

Specified by:
getConstantVar in interface Model
Parameters:
i - index of the variable
Returns:
the i-th real variable

getNbConstantVars

public int getNbConstantVars()
Returns the number of variables modelling constant.

Specified by:
getNbConstantVars in interface Model
Returns:
int

getNbStoredMultipleVars

public int getNbStoredMultipleVars()
Description copied from interface: Model
Returns the number of stored multiple variables.

Specified by:
getNbStoredMultipleVars in interface Model
Returns:
int

getStoredMultipleVar

public MultipleVariables getStoredMultipleVar(int i)
Description copied from interface: Model
Returns a multiple variable.

Specified by:
getStoredMultipleVar in interface Model
Parameters:
i - index of the variable
Returns:
the i-th stored multiple variable

getNbConstraints

public final int getNbConstraints()
retrieving the total number of constraint

Specified by:
getNbConstraints in interface Model
Returns:
the total number of constraints in the model

getConstraint

public final Constraint getConstraint(int i)
Network management: Retrieve a constraint by its index.

Specified by:
getConstraint in interface Model
Parameters:
i - index of the constraint in the model
Returns:
Constraint

getIntConstraintIterator

@Deprecated
public Iterator<Constraint> getIntConstraintIterator()
Deprecated. 

Return an iterator over the integer constraints of the model

Specified by:
getIntConstraintIterator in interface Model
Returns:
an iterator over the integer constraints of the model
See Also:
getConstraintIterator()

getConstraintIterator

public Iterator<Constraint> getConstraintIterator()
Return an iterator over the constraints of the model

Specified by:
getConstraintIterator in interface Model
Returns:
an iterator over the constraints of the model

getConstraintByType

public DisposableIterator<Constraint> getConstraintByType(ConstraintType t)
Description copied from interface: Model
Return an iterator over constraint of a certain type

Specified by:
getConstraintByType in interface Model
Parameters:
t - type
Returns:
iterator over constraint of type t

getNbConstraintByType

public int getNbConstraintByType(ConstraintType t)
Description copied from interface: Model
Return the number of constraint of a certain type

Specified by:
getNbConstraintByType in interface Model
Parameters:
t - the type of constraint
Returns:
a integer

addOptions

public void addOptions(String options,
                       IOptions... element)
Specified by:
addOptions in interface Model

addVariable

public void addVariable(Variable v)
Add a variable to the model

Specified by:
addVariable in interface Model
Parameters:
v - a variable

This method use default options. But User can define its own one. See CPModel.addVariable(String options, Variable... tabv) for more details.


addVariable

public void addVariable(String options,
                        Variable v)
Add one variable with options to the model

Specified by:
addVariable in interface Model
Parameters:
options - define options of the variables

This method use default options. But User can define its own one. See CPModel.addVariable(String options, Variable... tabv) for more details.

v - one or more variables

addVariable

@Deprecated
public void addVariable(Variable... v)
Deprecated. 

Add one or more variables to the model

Specified by:
addVariable in interface Model
Parameters:
v - one or more variables
See Also:
Model.addVariables(choco.kernel.model.variables.Variable[])

addVariable

@Deprecated
public void addVariable(String options,
                                   Variable... v)
Deprecated. 

Add one or more variables to the model with particular options

Specified by:
addVariable in interface Model
Parameters:
options - defines options of the variables
v - one or more variables
See Also:
Model.addVariables(String, choco.kernel.model.variables.Variable[])

addVariables

public void addVariables(Variable... tabv)
Add variables to the model.

Specified by:
addVariables in interface Model
Parameters:
tabv - : variables to add

This method use default options. But User can define its own one. See CPModel.addVariable(String options, Variable... tabv) for more details.


addVariables

public void addVariables(String options,
                         Variable... tabv)
Add variables to CPModel.

Specified by:
addVariables in interface Model
Parameters:
options - : String that allows user to precise som parameters to the model concerning the variable tabv
tabv - : variables to add

For IntegerVariable, available options are :

  • choco.Options.V_ENUM to force Solver to create enumerated domain variables (default options if options is empty)
  • choco.Options.V_BOUND to force Solver to create bounded domain variables
  • choco.Options.V_BTREE to force Solver to create binary tree domain variables
  • choco.Options.V_BLIST to force Solver to create bipartite list domain variables
  • choco.Options.V_LINK to force Solver to create linked list domain variables

For SetVariable, available options are :

  • choco.Options.V_ENUM to force Solver to create set variables with enumerated caridinality (default options if options is empty)
  • choco.Options.V_BOUND to force Solver to create set variables with bounded cardinality
No options are available concerning Real variables.

Options for decisionnal/undecisionnal variables

  • choco.Options.V_DECISION to force variable to be a decisional one
  • choco.Options.V_NO_DECISION to force variable to be removed from the pool of decisionnal variables
Options for optimization
  • choco.Options.V_OBJECTIVE to define the variable to optimize

getNbBoolVar

public int getNbBoolVar()
return the number of boolean variable (with binary domain) of the model

Returns:
int

removeVariable

@Deprecated
protected <E extends Variable> void removeVariable(E v,
                                                              DeterministicIndicedList<E> vars)
Deprecated. 


remVariable

protected <E extends Variable> void remVariable(E v)

remove

public void remove(Object ob)

removeConstraint

public void removeConstraint(Constraint c)
Description copied from interface: Model
Remove a constraint from the model. (Also remove variable if not even linked to existant constraints).

Specified by:
removeConstraint in interface Model
Parameters:
c - the constraint to remove

removeVariable

@Deprecated
public void removeVariable(Variable... v)
Deprecated. 

Remove one or more variables from the model (also remove constraints linked to the variables)

Specified by:
removeVariable in interface Model
Parameters:
v - variables to remove
See Also:
Model.removeVariables(choco.kernel.model.variables.Variable[])

removeVariable

public void removeVariable(Variable v)
Remove one variable from the model (also remove constraints linked to the variable)

Specified by:
removeVariable in interface Model
Parameters:
v - the variable to remove

removeVariables

public void removeVariables(Variable... v)
Remove one or more variables from the model (also remove constraints linked to the variables)

Specified by:
removeVariables in interface Model
Parameters:
v - variables to remove

addConstraint

@Deprecated
public void addConstraint(Constraint... c)
Deprecated. 

Add one or more constraint to the model. Also add variables to the model if necessary.

Specified by:
addConstraint in interface Model
Parameters:
c - one or more constraint
See Also:
Model.addConstraints(choco.kernel.model.constraints.Constraint[])

addConstraint

@Deprecated
public void addConstraint(String options,
                                     Constraint... c)
Deprecated. 

Add one or more constraint to the model. Also add variables to the model if necessary.

Specified by:
addConstraint in interface Model
Parameters:
options - defines options of the constraint
c - one or more constraint
See Also:
Model.addConstraints(choco.kernel.model.constraints.Constraint[])

addConstraint

public void addConstraint(Constraint c)
Add one constraint to the model. Also add variables to the model if necessary.

Specified by:
addConstraint in interface Model
Parameters:
c - one constraint

addConstraints

public void addConstraints(Constraint... c)
Add one or more constraint to the model. Also add variables to the model if necessary.

Specified by:
addConstraints in interface Model
Parameters:
c - one or more constraint

addConstraint

public void addConstraint(String options,
                          Constraint c)
Add one constraint to the model. Also add variables to the model if necessary.

Specified by:
addConstraint in interface Model
Parameters:
options - defines options of the constraint
c - one constraint

addConstraints

public void addConstraints(String options,
                           Constraint... tabc)
Add constraints to the model

Specified by:
addConstraints in interface Model
Parameters:
options - : options of constraint
tabc - : constraints to add

Options of CPModel must be prefixed with cp. The following options are available:

    cp:decomp to force decomposition on particular expression constraint

getIntVarIterator

public Iterator<IntegerVariable> getIntVarIterator()
Description copied from interface: Model
Retrieves an iterator over IntegerVariables of the model

Specified by:
getIntVarIterator in interface Model
Returns:
an iterator over IntegerVariables of the model

getRealVarIterator

public Iterator<RealVariable> getRealVarIterator()
Description copied from interface: Model
Retrieves an iterator over RealVariables of the model

Specified by:
getRealVarIterator in interface Model
Returns:
an iterator over RealVariables of the model

getSetVarIterator

public Iterator<SetVariable> getSetVarIterator()
Description copied from interface: Model
Retrieves an iterator over SetVariables of the model

Specified by:
getSetVarIterator in interface Model
Returns:
an iterator over SetVariables of the model

getConstVarIterator

public Iterator<Variable> getConstVarIterator()
Description copied from interface: Model
Retrieves an iterator over constantes variables of the model

Specified by:
getConstVarIterator in interface Model
Returns:
an iterator over constantes variables of the model

getExprVarIterator

public Iterator<IntegerExpressionVariable> getExprVarIterator()

getMultipleVarIterator

public Iterator<MultipleVariables> getMultipleVarIterator()
Description copied from interface: Model
Retrieves an iterator over MultipleVariables of the model (if stored)

Specified by:
getMultipleVarIterator in interface Model
Returns:
an iterator over IntegerVariables of the model

contains

public boolean contains(Constraint c)
Specified by:
contains in interface Model

writeInFile

public static void writeInFile(CPModel model,
                               File file)
                        throws IOException
Kicks off the serialization mechanism and flatten the model into the given file.

Parameters:
model - to flatten
file - scope file
Throws:
IOException - if an I/O exception occurs.

writeInFile

public static File writeInFile(CPModel model)
                        throws IOException
Kicks off the serialization mechanism and flatten the model into a file in the default temporary-file directory.

Parameters:
model - to flatten
file - scope file
Throws:
IOException - if an I/O exception occurs.

readFromFile

public static CPModel readFromFile(File file)
                            throws IOException,
                                   ClassNotFoundException
Restore flatten CPModel from the given file.

Parameters:
file - input file
Returns:
a CPModel
Throws:
IOException - if an I/O exception occurs.
ClassNotFoundException - if wrong flattened object.


Copyright © 2012. All Rights Reserved.