> Languages and APIs > ILOG Concert Technology for Java Users > Optimizing the Diet Problem in Java > Modifying the Model |
Modifying the Model |
INDEX PREVIOUS NEXT |
An important feature of ILOG CPLEX is that you can modify a previously created model to consider different scenarios. Furthermore, depending on the optimization model and algorithm used, ILOG CPLEX will save as much information from a previous solution as possible when optimizing a modified model.
The most important modification method is IloModel.add
, for adding modeling objects to the active model. Conversely, IloModel.remove
can be used to remove a previously added modeling object from a model.
When adding a modeling object such as a ranged constraint to a model, all the variables used by that modeling object implicitly become part of the model as well. However, when removing a modeling object, no variables are implicitly removed from the model. Instead, variables can only be explicitly removed from a model by calling IloModel.delete
. This will cause the specified variables to be deleted from the model, and thus from all modeling objects in the model that are using these variables. In other words, deleting variables from a model may implicitly modify other modeling objects in that model.
The API of specific modeling objects may provide modification methods. For example, variable bounds can be changed using methods IloNumVar.setLB
and IloNumVar.setUB
. Similarly the bounds of ranged constraints can be changed using IloRange.setLB
and IloRange.setUB
.
Because not all the optimizers that implement the IloModeler
interface support the ability to modify a model, modification methods are implemented in IloMPModeler
. These methods are for manipulating the linear expressions in ranged constraints and objective functions used with IloCplex
. The methods IloMPModeler.setLinearCoef
, IloMPModeler.setLinearCoefs
, and IloMPModeler.addToExpr
apply in this situation.
The type of a variable cannot be changed. However, it can be overwritten for a particular model by adding an IloConversion
object, which allows you to specify new types for variables within that model. When ILOG CPLEX finds a conversion object in the active model, it uses the variable types specified in the conversion object instead of the original type specified for the optimization. For example, in a model containing the following lines, ILOG CPLEX will only generate solutions where variable x
is an integer (within tolerances), yet the type returned by x.getType
will remain IloNumVarType.Float
.
IloNumVar x = cplex.numVar(0.0, 1.0); cplex.add(cplex.conversion(x, IloNumVarType.Int)); |
A variable can only be used in at most one conversion object, or the model will no longer be unambiguously defined. This does not imply that the type of a variable can only be changed once and never again after that. Instead, you can remove the conversion object and add a new one to implement consecutive variable type changes.
Copyright © 1987-2003 ILOG, S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |