Reputation: 1
I am programming a mathematical model in Java using the Cplex library and I wanted to know if there are predefined functions to determine if the solution obtained with Cplex is feasible or optimal.
Thanks a lot for your help.
Upvotes: 0
Views: 399
Reputation: 4465
The IloCplex.solve() method returns:
A Boolean value reporting whether a feasible solution has been found. This solution is not necessarily optimal. If false is returned, a feasible solution may still be present, but IloCplex has not been able to prove its feasibility.
You can check IloCplex.getStatus() to determine if the solve was feasible, optimal, etc.
There are many examples that come with CPLEX that show how to check these models. For example, consider the following snippet from LPex1.java:
// solve the model and display the solution if one was found
if ( cplex.solve() ) {
double[] x = cplex.getValues(var[0]);
double[] dj = cplex.getReducedCosts(var[0]);
double[] pi = cplex.getDuals(rng[0]);
double[] slack = cplex.getSlacks(rng[0]);
cplex.output().println("Solution status = " + cplex.getStatus());
cplex.output().println("Solution value = " + cplex.getObjValue());
int nvars = x.length;
for (int j = 0; j < nvars; ++j) {
cplex.output().println("Variable " + j +
": Value = " + x[j] +
" Reduced cost = " + dj[j]);
}
int ncons = slack.length;
for (int i = 0; i < ncons; ++i) {
cplex.output().println("Constraint " + i +
": Slack = " + slack[i] +
" Pi = " + pi[i]);
}
}
Upvotes: 1