Download ILOG CPLEX 7.5 User`s Manual

Transcript
<functionhead>
Changing Variable Type
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.
Handling Errors
In Concert Technology two kinds of errors are distinguished:
1. Programming errors, such as:
●
accessing empty handle objects
●
mixing modeling objects from different environments
●
accessing Concert Technology array elements beyond an array’s size
●
passing arrays of incompatible size to functions.
Such errors are usually an oversight of the programmer. Once they are recognized and
fixed there is usually no danger of corrupting an application. In a production version, it is
not necessary to handle these kinds of errors.
In Concert Technology such error conditions are handled using assert statements. If
compiled without -DNDEBUG, the error check is performed and the code aborts with an
error message indicating which assertion failed. A production version should then be
compiled with the -DNDEBUG compiler option, which removes all the checking. In other
words, no CPU cycles are consumed for checking the assertions.
2. Runtime errors, such as memory exhaustion.
A correct program assumes that such failures can occur and therefore must be treated,
even in a production version. In Concert Technology, if such an error condition occurs,
an exception is thrown.
ILOG CPLEX 7.5 — U
SER
’S MA
NUAL
43
Using Concert
Technology
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: