Querying solution data
Describes methods available in the C++ API to query data about the solution after optimization.
If getValue returns IloTrue , a feasible solution has been found and
solution values for model variables are available to be queried. For
example, the solution value for the numeric variable var1
can be accessed like this:
IloNum x1 =
getValue(var1);
However, querying solution values variable by variable
may result in ugly code. Here, the use of Concert Technology arrays
provides a much more compact way of accessing the solution values.
Assuming your variables are stored in an array of numeric variables
(IloNumVarArray) named var ,
use lines like these to access the solution values for all variables
in var simultaneously:
IloNumArray x(env);
getValues(x,
var);
Value x[i] contains the solution
value for variable var[i].
Solution data is not restricted to the solution values
of variables. It also includes values of slack variables in constraints
(whether the constraints are linear or quadratic) and the objective
value. If the extracted model does not contain an objective object, IloCplex assumes a 0 expression objective. The
objective value is returned by calling method getObjValue.
Slack values are accessed with the methods getSlack and getSlacks,
which take a linear constraint, a quadratic constraint, or an array
of constraints as a parameter.
For LPs and QPs, solution data includes information such as dual variables and reduced cost. Such information can be queried with the methods, getDual, getDuals, getReducedCost, and getReducedCosts.