The type of a variable cannot be changed by calling modification methods. Instead, Concert Technology provides the modeling class IloConversion
, the objects of which allow you to override the type of a variable in a model. This design allows you to use the same variable in different models with different types. Consider for example model1
containing integer variable x
. You can then create model2
, as a copy of model1
, that treats x
as a continuous variable, with the following code:
model2.add(IloConversion(env, x, ILOFLOAT));
A conversion object, that is, an instance of IloConversion
, can specify a type only for a variable that is in a model. Converting the type more than once is an error, because there is no rule about which would have precedence. However, this convention is not too restrictive, since you can remove the conversion from a model and add a new one. To remove a conversion from a model, use the method IloExtractable::end
. To add a new one, use the methodIloModel::add
. For a sample of code using these methods in this procedure, see the documentation of the class IloConversion
in the ILOG CPLEX C++ Reference Manual.