Controlling Feasibility

1,158 views
Skip to first unread message

M. Emre Keskin

unread,
Dec 28, 2010, 4:29:29 AM12/28/10
to Gurobi Optimization
Hi, I have several MIP instances for which I set a 3 hour time limit
in Gurobi. For most of the instances Gurobi finds the optimal
solution, and for most of the rest it finds a feasible solution.
However, for a few problem instances Gurobi is not able to find a
feasible solution within the allowed time limit. In such situations I
want to report that no feasible solution is found in 3 hour
limitation, but I could not control whether Gurobi finds a feasible
solution or not after the time limit exceeded. So, Gurobi throws an
exception and the program terminates. Can you offer me a way of
checking whether a feasible solution is found by Gurobi? Thank you for
your interest.

rlin...@gmail.com

unread,
Dec 28, 2010, 9:13:50 AM12/28/10
to gur...@googlegroups.com
model.optimize();

if ( model.get(GRB_IntAttr_SolCount) ) {
cout << " ** Solution found! ** :) " << endl;
} else {
cout << " ** Error ** Not solution found :( !" << endl;

Ed Rothberg

unread,
Dec 28, 2010, 10:42:00 PM12/28/10
to Gurobi Optimization
> ...So, Gurobi throws an
> exception and the program terminates. Can you offer me a way of
> checking whether a feasible solution is found by Gurobi?

Another simple option is to just catch the exception...

try {
x = var.get(GRB_DoubleAttr_X);
} catch(...) {
cout << "No solution" << endl;
}

The exception doesn't have to stop the program.

Bastian Meier

unread,
Dec 29, 2010, 2:31:59 AM12/29/10
to Gurobi Optimization
> 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

satdene

unread,
Dec 29, 2010, 4:31:47 AM12/29/10
to Gurobi Optimization
Thanks for your answers. I will try "model.get(GRB_IntAttr_SolCount)"
and catching the exception. Bastian, unfortunately investigating the
model status did not work for my problem. For (optimstatus ==
GRB.Status.TIMELIMIT) it returns true, but for "all" the other status
cases it does not return true. I tried all of the status cases in
order to investigate the reason of the exception but it didn't work. I
will share the difficulties I face if I encounter one. Thanks again.

Bastian Meier

unread,
Jan 1, 2011, 3:09:37 AM1/1/11
to Gurobi Optimization
> and catching the exception. Bastian, unfortunately investigating the
> model status did not work for my problem. For (optimstatus ==
> GRB.Status.TIMELIMIT) it returns true

Sorry, i did not thought of the time limit.

Bastian

Bertan

unread,
Jan 4, 2011, 9:49:54 AM1/4/11
to Gurobi Optimization
You can also use a callback to set a flag or read the solution when a
feasible solution is found during MIP solve.

On Dec 28 2010, 4:29 am, "M. Emre Keskin" <m.emre.kes...@gmail.com>
wrote:
Reply all
Reply to author
Forward
0 new messages