Querying Solution Data

If cplex.solve() 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 as follows:

IloNum x1 = cplex.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 anIloNumVarArray var, you can use

IloNumArray x(env);
cplex.getValues(x, var);

to access the solution values for all variables in var at once. 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 for linear constraints 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 cplex.getObjValue(). Slack values are accessed with the methods getSlack() and getSlacks(), which take linear constraints as a parameter.

For LPs, solution data includes information such as dual variables and reduced cost. Such information can be queried with the methods, getDual(), getDuals(), getReducedCost(), and getReducedCosts().


Previous Page: Accessing Solution Information  Return to Top Next Page: Accessing Basis Information