ILOG CPLEX 11.0 User's Manual > Languages and APIs > ILOG Concert Technology for C++ Users > Accessing Solution Information > 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 an IloNumVarArray 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 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 cplex.getObjValue. Slack values are accessed with the methods getSlack and getSlacks, which take linear or quadratic 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.