| Overview | Group | Tree | Graph | Index | Concepts |

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
IloIntVar or
IloNumVar with Type = Int)
in the constructors or via a modifier (setUB,
setLB,
setBounds), they are inwardly rounded
to an integer value. LB
is rounded down and UB is rounded up.See Also:
IloBoolVar, IloIntVar, IloModel, IloNumVarArray, IloNumVar::Type
| Constructor Summary | |
|---|---|
public | IloNumVar() |
public | IloNumVar(IloNumVarI * impl) |
public | IloNumVar(const IloEnv env, IloNum lb=0, IloNum ub=IloInfinity, IloNumVar::Type type=Float, const char * name=0) |
public | IloNumVar(const IloEnv env, IloNum lowerBound, IloNum upperBound, const char * name) |
public | IloNumVar(const IloAddNumVar & var, IloNum lowerBound=0.0, IloNum upperBound=IloInfinity, IloNumVar::Type type=Float, const char * name=0) |
public | IloNumVar(const IloEnv env, const IloNumArray values, IloNumVar::Type type=Float, const char * name=0) |
public | IloNumVar(const IloAddNumVar & var, const IloNumArray values, IloNumVar::Type type=Float, const char * name=0) |
public | IloNumVar(const IloConstraint constraint) |
public | IloNumVar(const IloNumRange coll, const char * name=0) |
| Method Summary | |
|---|---|
public IloNumVarI * | getImpl() const |
public IloNum | getLB() const |
public void | getPossibleValues(IloNumArray values) const |
public IloNumVar::Type | getType() const |
public IloNum | getUB() const |
public void | setBounds(IloNum lb, IloNum ub) const |
public void | setLB(IloNum num) const |
public void | setPossibleValues(const IloNumArray values) const |
public void | setUB(IloNum num) const |
Inherited Methods from IloNumExprArg |
|---|
getImpl |
Inherited Methods from IloExtractable |
|---|
asConstraint, asIntExpr, asModel, asNumExpr, asObjective, asVariable, end, getEnv, getId, getImpl, getName, getObject, isConstraint, isIntExpr, isModel, isNumExpr, isObjective, isVariable, setName, setObject |
| Inner Enumeration | |
|---|---|
| IloNumVar::Type | An enumeration for the class IloNumVar. |
| Constructor Detail |
|---|
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 specify 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 the empty string, but you can specify a
name of your own choice.
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 the empty string, but you can specify a name
of your own choice.
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.
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 specified by the array
values. By default, its name is the empty string,
but you can specify a name of your own choice. You can use the member
function IloNumVar::setPossibleValues with instances
created by this constructor.
This constructor creates a constrained
discrete numeric variable
from var by limiting its domain to
the values specified in the array
values. You may use the member function
IloNumVar::setPossibleValues
with instances created by this constructor.
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);
This constructor creates a constrained discrete numeric variable from the given collection
This constructor creates a constrained discrete numeric variable from the given collection
| Method Detail |
|---|
This member function returns the lower bound of the invoking numeric variable.
This member function accesses the possible values of the invoking numeric
variable and puts them in the array values.
This member function returns the type of the invoking numeric variable,
specifying whether it is integer (Int) or floating-point
(Float).
This member function returns the upper bound of the invoking numeric variable.
This member function sets lb as the lower bound and
ub as the upper bound of the invoking numeric variable.
setBounds notifies Concert Technology
algorithms about this change of bounds in this numeric variable. This member function sets num as the lower bound of the
invoking numeric variable.
setLB notifies Concert Technology
algorithms about this change of bound in this numeric variable. 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.
setPossibleValues notifies Concert
Technology algorithms about this change of domain in this discrete numeric
variable. This member function sets num as the upper bound of the
invoking numeric variable.
setUB notifies Concert Technology
algorithms about this change of bound in this numeric variable. | Inner Enumeration Detail |
|---|
This nested enumeration enables you to specify 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 = 1 | |
Float = 2 | |
Bool = 3 |