Overview | Group | Tree | Graph | Index | Concepts |
An instance of this class offers you a means to change the type of a
numeric variable. For example, in a model (an instance of IloModel
) extracted for an algorithm (such as an instance of
the class IloCplex
), you may want to convert the type of a
given numeric variable (an instance of IloNumVar
) from
ILOFLOAT
to ILOINT
or to ILOBOOL
(or
from IloNumVar::Float
to IloNumVar::Int
or to
IloNumVar::Bool
). Such a change is known as a conversion.
After you create a conversion, you must explicitly add it to the model in
order for it to be taken into account. To do so, use the member function
IloModel::add
or the template IloAdd
. Then extract the model for an algorithm (such as an
instance of IloCplex
) with the member function IloAlgorithm::extract
.
Multiple Type Conversions of the Same Variable
You can convert the type of a numeric variable in a model. To do so,
create an instance of IloConversion
and add it to the
model. You can also convert the type of a numeric variable after the model
has been extracted for an algorithm (such as an instance of
IloCplex
, documented in the ILOG CPLEX Reference Manual).
An instance of IloCplex
will not accept more than one type
conversion of the same variable. That is, you can change the type once, but
not twice, in a single instance of IloCplex
. Attempts to
convert the type of the same variable more than once will throw the
exception IloCplex::MultipleConversionException
, documented in
the ILOG CPLEX Reference Manual.
In situations where you want to change the type of a numeric variable more than once (for example, from Boolean to integer to floating-point), there are these possibilities:
IloExtractable::end
to delete it and optionally add a new
conversion.IloNumVar x(env, 0, 10, ILOBOOL); IloRange rng = (x <= 10); IloModel mdl1(env); mdl1.add(rng); mdl1.add(IloConversion(env, x, ILOINT)); IloCplex cplex1(mdl1); IloModel mdl2(env); mdl2.add(rng); mdl2.add(IloConversion(env, x, ILOFLOAT)); IloCplex cplex2(mdl2);
Most member functions in this class contain assert
statements. For an explanation of the macro NDEBUG
(a way to
turn on or turn off these assert
statements), see the concept
Assert and NDEBUG.
See Also:
IloModel, IloCplex documented in the ILOG CPLEX Reference Manual
Constructor Summary | |
---|---|
public | IloConversion() |
public | IloConversion(IloConversion::ImplClass *) |
public | IloConversion(const IloEnv, const IloNumVar, IloNumVar::Type, const char *) |
public | IloConversion(const IloEnv, const IloNumVarArray, IloNumVar::Type, const char *) |
public | IloConversion(const IloEnv, const IloIntVarArray, IloNumVar::Type, const char *) |
Method Summary | |
---|---|
public IloConversion::ImplClass * | getImpl() |
Inherited Methods from IloExtractable |
---|
end, getEnv, getId, getImpl, getName, getObject, setName, setObject |
Constructor Detail |
---|
This constructor accepts a numeric variable and a type; it creates a
handle to a type conversion to change the type of the variable
var
to the type indicated by t
. You may use the
parameter name
to name the type conversion so that you can
refer to it by a string identifier.
This constructor accepts an array of numeric variables and a type; it
creates a handle to a type conversion to change the type of each variable in
the array vars
to the type indicated by t
. You may
use the parameter name
to name the type conversion so that you
can refer to it by a string identifier.
This constructor accepts an array of integer variables and a type; it
creates a handle to a type conversion to change the type of each variable in
the array vars
to the type indicated by t
. You may
use the parameter name
to name the type conversion so that you
can refer to it by a string identifier.
Method Detail |
---|