Changing Variable Type

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:

IloModel model2(env); 
model2.add(model1); 
model2.add(IloConversion(env, x, ILOFLOAT)); 

A conversion object, that is, an instance of IloConversion, can only specify a type 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 is not a restriction, since you can remove the conversion from a model and add a new one.


Previous Page: Deleting and Removing Modeling Objects  Return to Top Next Page: Handling Errors