NO FRAMES

Class IloNumVar

Definition file: ilconcert/iloexpression.h
An instance of this class represents a numeric variable in a model.

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 numeric bounds are given to an integer variable (an instance of 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:

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 IloNumgetLB() const
public voidgetPossibleValues(IloNumArray values) const
public IloNumVar::TypegetType() const
public IloNumgetUB() const
public voidsetBounds(IloNum lb, IloNum ub) const
public voidsetLB(IloNum num) const
public voidsetPossibleValues(const IloNumArray values) const
public voidsetUB(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 nested enumeration.
Constructor Detail

IloNumVar

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

IloNumVar

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

IloNumVar

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

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.


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 the empty string, but you can specify a name of your own choice.


IloNumVar

public IloNumVar(const IloAddNumVar & var, IloNum lowerBound=0.0, IloNum upperBound=IloInfinity, IloNumVar::Type type=Float, const char * name=0)

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=Float, const char * name=0)

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.


IloNumVar

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

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.


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);
 

IloNumVar

public IloNumVar(const IloNumRange coll, const char * name=0)

This constructor creates a constrained discrete numeric variable from the given collection


Method Detail

getImpl

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

getLB

public IloNum getLB() const

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


getPossibleValues

public void getPossibleValues(IloNumArray values) const

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


getType

public IloNumVar::Type getType() const

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


getUB

public IloNum getUB() const

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


setBounds

public void setBounds(IloNum lb, IloNum ub) const

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) const

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) const

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) const

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
nested enumeration.

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
Float
Bool