NO FRAMES

Class IloConversion

Definition file: ilconcert/iloexpression.h
For ILOG CPLEX: a means to change the type of a numeric variable.

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:

 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 the class IloCplex in the ILOG CPLEX Reference Manual.

See Also:

Constructor Summary
public IloConversion()
public IloConversion(IloConversionI * impl)
public IloConversion(const IloEnv env, const IloNumVar var, IloNumVar::Type t, const char * name=0)
public IloConversion(const IloEnv env, const IloNumVarArray vars, IloNumVar::Type t, const char * name=0)
public IloConversion(const IloEnv env, const IloIntVarArray vars, IloNumVar::Type t, const char * name=0)
Method Summary
public IloConversionI *getImpl() const
Inherited Methods from IloExtractable
asConstraint, asIntExpr, asModel, asNumExpr, asObjective, asVariable, end, getEnv, getId, getImpl, getName, getObject, isConstraint, isIntExpr, isModel, isNumExpr, isObjective, isVariable, setName, setObject
Constructor Detail

IloConversion

public IloConversion()
This constructor creates an empty handle. You must initialize it before you use it.

IloConversion

public IloConversion(IloConversionI * impl)
This constructor creates a handle object from a pointer to an implementation object.

IloConversion

public IloConversion(const IloEnv env, const IloNumVar var, IloNumVar::Type t, const char * name=0)

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 specified by t. You may use the argument name to name the type conversion so that you can refer to it by a string identifier.


IloConversion

public IloConversion(const IloEnv env, const IloNumVarArray vars, IloNumVar::Type t, const char * name=0)

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 specified by t. You may use the argument name to name the type conversion so that you can refer to it by a string identifier.


IloConversion

public IloConversion(const IloEnv env, const IloIntVarArray vars, IloNumVar::Type t, const char * name=0)

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 specified by t. You may use the argument name to name the type conversion so that you can refer to it by a string identifier.


Method Detail

getImpl

public IloConversionI * getImpl() const
This member function returns a pointer to the implementation object of the invoking handle.