> Languages and APIs > ILOG Concert Technology for Java Users > Accessing Solution Information |
Accessing Solution Information |
INDEX PREVIOUS NEXT |
If a solution was found with the solve
method, it can be accessed and then queried using a variety of methods. The objective function can be accessed by calling
double objval = cplex.getObjValue(); |
The values of individual modeling variables for the solution are accessed by calling methods IloCplex.getValue
, for example:
double x1 = cplex.getValue(var1); |
Frequently, solution values for an array of variables are needed. Rather than having to implement a loop to query the solution values variable by variable, the method IloCplex.getValues
is provided to do so with only one function call:
double[] x = cplex.getValues(vars); |
Similarly, slack values can be queried for the constraints in the active model using the methods IloCplex.getSlack
or IloCplex.getSlacks
.
This can now be applied to solving the diet problem discussed earlier, and printing its solution.
These lines of code start by creating a new IloCplex
object and passing it, along with the raw data in another object, either to the method buildModelByColumn
or to the method buildModelByRow
. The array of variables returned by it is saved as the array Buy
. Then the method solve
is called to optimize the active model and, upon success, solution information is printed.
Copyright © 1987-2003 ILOG, S.A. All rights reserved. Legal terms. | PREVIOUS NEXT |