NO FRAMES

Class IloNumVar

Definition file: ilconcert/iloexpression.h

An instance of this class represents a numeric variable in a model. A numeric variable may be either an integer variable or a floating-point variable; that is, a numeric variable has a type, a value of the nested enumeration IloNumVar::Type. By default, its type is Float. It also has a lower and upper bound. A numeric variable cannot assume values less than its lower bound, nor greater than its upper bound.

If you are looking for a class of variables that can assume only constrained integer values, consider the class IloIntVar. If you are looking for a class of binary decision variables that can assume only the values 0 (zero) or 1 (one), then consider the class IloBoolVar.

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.

Programming Hint

For each enumerated value in the nested enumeration IloNumVar::Type, Concert Technology offers an equivalent predefined C++ #define to make programming easier. For example, in your applications, you may write either statement:

 IloNumVar x(env, 0, 17, IloNumVar::Int); // using the enumeration

 IloNumVar x(env, 0, 17, ILOINT);         // using the #define
 
Note
When numerical bounds are given to an integer variable (an IloIntVar or an IloNumVar with Type = Int) in the constructors of via a modifier (setUB, setLB, setBounds), they are inward rounded to an integer value. LB is rounded down and UB is rounded up.

See Also:

Constructor Summary
public IloNumVar()
public IloNumVar(IloNumVar::ImplClass *)
public IloNumVar(const IloEnv, IloNum, IloNum, IloNumVar::Type, const char *)
public IloNumVar(const IloEnv, IloNum, IloNum, const char *)
public IloNumVar(const IloAddNumVar &, IloNum, IloNum, IloNumVar::Type, const char *)
public IloNumVar(const IloEnv, const IloNumArray, IloNumVar::Type, const char *)
public IloNumVar(const IloAddNumVar &, const IloNumArray, IloNumVar::Type, const char *)
public IloNumVar(const IloConstraint)
Method Summary
public IloNumVar::ImplClass *getImpl()
public IloNumgetLB()
public voidgetPossibleValues(IloNumArray)
public IloNumVar::TypegetType()
public IloNumgetUB()
public voidsetBounds(IloNum, IloNum)
public voidsetLB(IloNum)
public voidsetPossibleValues(const IloNumArray)
public voidsetUB(IloNum)
Inherited Methods from IloNumExprArg
getImpl
Inherited Methods from IloExtractable
end, getEnv, getId, getImpl, getName, getObject, setName, setObject
Inner Enumeration
IloNumVar::Type
Constructor Detail

IloNumVar

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

IloNumVar

public IloNumVar(IloNumVar::ImplClass * impl)
This constructor creates a handle object from a pointer to an implementation object.

IloNumVar

public IloNumVar(const IloEnv env, IloNum lb, IloNum ub, IloNumVar::Type type, const char * name)

This constructor creates a constrained numeric variable and makes it part of the environment env. By default, the numeric variable ranges from 0.0 (zero) to the symbolic constant IloInfinity, but you can indicate other upper and lower bounds yourself. By default, the numeric variable assumes floating-point values. However, you can constrain it to be an integer by setting its type = Int. By default, its name is indicated by the empty string, but you can indicate a name of your own choice.


IloNumVar

public IloNumVar(const IloEnv env, IloNum lowerBound, IloNum upperBound, const char * name)

This constructor creates a constrained numeric variable and makes it part of the environment env. The bounds of the variable are set by lowerBound and upperBound. By default, its name is indicated by the empty string, but you can indicate a name of your own choice.


IloNumVar

public IloNumVar(const IloAddNumVar & var, IloNum lowerBound, IloNum upperBound, IloNumVar::Type type, const char * name)

This constructor creates a constrained numeric variable in column format. For more information on adding columns to a model, refer to the concept Column-Wise Modeling.


IloNumVar

public IloNumVar(const IloEnv env, const IloNumArray values, IloNumVar::Type type, const char * name)

This constructor creates a constrained discrete numeric variable and makes it part of the environment env. The new discrete variable will be limited to values in the set indicated by the array values. By default, its name is indicated by the empty string, but you can indicate a name of your own choice. You can use the member function IloNumVar::setPossibleValues with instances created by this constructor.


IloNumVar

public IloNumVar(const IloAddNumVar & var, const IloNumArray values, IloNumVar::Type type, const char * name)

This constructor creates a constrained discrete numeric variable from var by limiting its domain to the values indicated in the array values. You may use the member function IloNumVar::setPossibleValues with instances created by this constructor.


IloNumVar

public IloNumVar(const IloConstraint constraint)

This constructor creates a constrained numeric variable which is equal to the truth value of constraint. The truth value of constraint is either 0 for IloFalse or 1 for IloTrue. You can use this constructor to cast a constraint to a constrained numeric variable. That constrained numeric variable can then be used like any other constrained numeric variable. It is thus possible to express sums of constraints, for example. The following line expresses the idea that all three variables cannot be equal:

 model.add((x != y) + (y != z) + (z != x) >= 2);
 

Method Detail

getImpl

public IloNumVar::ImplClass * getImpl()
This member function returns a pointer to the implementation object of the invoking handle.

getLB

public IloNum getLB()

This member function returns the lower bound of the invoking numeric variable.


getPossibleValues

public void getPossibleValues(IloNumArray values)

This member function accesses the possible values of the invoking numeric variable and puts them in the array values.


getType

public IloNumVar::Type getType()

This member function returns the type of the invoking numeric variable, indicating whether it is integer (Int) or floating-point (Float).


getUB

public IloNum getUB()

This member function returns the upper bound of the invoking numeric variable.


setBounds

public void setBounds(IloNum lb, IloNum ub)

This member function sets lb as the lower bound and ub as the upper bound of the invoking numeric variable.

Note
The member function setBounds notifies Concert Technology algorithms about this change of bounds in this numeric variable.

setLB

public void setLB(IloNum num)

This member function sets num as the lower bound of the invoking numeric variable.

Note
The member function setLB notifies Concert Technology algorithms about this change of bound in this numeric variable.

setPossibleValues

public void setPossibleValues(const IloNumArray values)

This member function sets values as the domain of the invoking discrete numeric variable. This member function can be called only on instances of IloNumVar that have been created with one of the two discrete constructors; that is, instances of IloNumVar which have been defined by an explicit array of discrete values.

Note
The member function setPossibleValues notifies Concert Technology algorithms about this change of domain in this discrete numeric variable.

setUB

public void setUB(IloNum num)

This member function sets num as the upper bound of the invoking numeric variable.

Note
The member function setUB notifies Concert Technology algorithms about this change of bound in this numeric variable.

Inner Enumeration Detail

Enumeration Type

Definition file: ilconcert/iloexpression.h

This nested enumeration enables you to indicate whether an instance of IloNumVar is of type integer (Int), Boolean (Bool), or floating-point (Float).

Programming Hint

For each enumerated value in IloNumVar::Type, there is a predefined equivalent C++ #define in the Concert Technology include files to make programming easier. For example, instead of writing IloNumVar::Int in your application, you can write ILOINT. Likewise, ILOFLOAT is defined for IloNumVar::Float and ILOBOOL for IloNumVar::Bool.

See Also:

Fields
Int
Float
Bool