> Another simple option is to just catch the exception...
>
> try {
> x = var.get(GRB_DoubleAttr_X);
> } catch(...) {
> cout << "No solution" << endl;
> }
>
There are many more possible reasons for an exception. With reference
to the Gurobi Manual "Status" is the right attribut to check whether a
feasible solution has been found.
Code snippet from example MIP2.java(can be found via Google "Mip2.java
Gurobi"):
int optimstatus = model.get(GRB.IntAttr.Status);
if (optimstatus == GRB.Status.OPTIMAL) {
objval = model.get(GRB.DoubleAttr.ObjVal);
System.out.println("Optimal objective: " + objval);
} else if (optimstatus == GRB.Status.INF_OR_UNBD) {
System.out.println("Model is infeasible or unbounded");
return;
} else if (optimstatus == GRB.Status.INFEASIBLE) {
System.out.println("Model is infeasible");
return;
}
...
You can find the Optimization Status Codes in the Gurobi Manual.
Basti