Skip to main content
FRAMES NO FRAMES

Integer values, integrality tolerance, and round-off in CPLEX Optimizers
PREVIOUS NEXT

Tip: If you need an exact integer value, use the function IloRound to avoid the hazard of truncation.

CPLEX Optimizers implement conventional floating-point arithmetic to represent numbers. In the context of integer constraints and integral solutions, this convention means that the internal value of an integer represented as a floating-point number can be very close to integral without being the floating-point representation of that integer. This discrepancy between the floating-point representation of an integer and the expected computation of an integer can produce surprising results in some situations.

For example, consider a problem in which the internal value of the variable x is -0.99999952316284191. You might expect that value to be rounded and returned as -1 (negative one), depending on the value of the integrality tolerance of the model in the problem. However, that rounding is not applied because it could affect the feasibility of the constraints in which x appears. If you now assign this value to a variable of type integer such as IloInt, in your application, this assignment implicitly truncates the floating-point representation to the integer value 0 (zero), according to these conventions. That is, the assignment does not round the value to -1 (negative one), as you might expect.

In particular, the following methods accept an instance of IloIntVar or IloIntVarArray as an argument. When you assign the return value of these methods to an instance of IloInt (or IloIntArray) truncation (rather than rounding) can produce surprising results in your application.

PREVIOUS NEXT