coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
527 stars 92 forks source link

Gurobi does not use the max_mip_gap value #57

Closed brokkelkamp closed 4 years ago

brokkelkamp commented 4 years ago

Hi,

I've set the max_mip_gap property to 1e-10 m.max_mip_gap = 1e-10 but Gurobi does not seem to use it as it still quits with

Optimal solution found (tolerance 1.00e-04)
Best objective 7.999600000000e+04, best bound 8.000000000000e+04, gap 0.0050%

Using CBC it does find an optimal solution (with value 80000) Should I set it in a different way?

h-g-s commented 4 years ago

Hello,

Besides max_mip_gap (relative value) there is also max_mip_gap_abs,  could you check this property also ?

Em 2/15/20 2:38 PM, brokkelkamp escreveu:

Hi,

I've set the max_mip_gap property to 1e-10 |m.max_mip_gap = 1e-10| but Gurobi does not seem to use it as it still quits with

|Optimal solution found (tolerance 1.00e-04) Best objective 7.999600000000e+04, best bound 8.000000000000e+04, gap 0.0050% |

Using CBC it does find an optimal solution (with value 80000) Should I set it in a different way?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/coin-or/python-mip/issues/57?email_source=notifications&email_token=AB4VZOW757IPCLYTUJK2U6DRDASB5A5CNFSM4KV2WFMKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4INZFTYQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4VZOWKVZ6CHVPSEOXK6MTRDASB5ANCNFSM4KV2WFMA.

--

Haroldo Gambini Santos Computing Department Universidade Federal de Ouro Preto - UFOP email: haroldo@ufop.edu.br home/research page: www.decom.ufop.br/haroldo

It has long been an axiom of mine that the little things are infinitely the most important. -- Sir Arthur Conan Doyle, "A Case of Identity"

brokkelkamp commented 4 years ago

Hi Haroldo,

Yes, I've tried that but it doesn't change anything.

Best, Ruben

tuliotoffolo commented 4 years ago

Dear @brokkelkamp, would you be able to share your code? If so, I can take a look to see what is happening with the mip_gap parameter.

tabatabai commented 4 years ago

Hi everyone,

I can confirm this issue. I'm using Gurobi 9.0 and python-mip 1.9.0. This is a program for computing solutions of a hard combinatorial problem (OEIS A004045) where the specified value m.max_mip_gap = 0.5 is ignored by the Gurobi model.

import mip
import itertools as it

def neighbors(vec):
    result = []
    for i, v in enumerate(vec):
        new = list(vec)
        new[i] = 1 - v
        result.append(tuple(new))
    return result

m = mip.Model(sense=mip.MINIMIZE, solver_name=mip.GRB)
m.emphasis = 2  # focus on optimality proving
m.threads = 4

n = 8
vectors = {x: m.add_var(var_type=mip.BINARY) for x in it.product(range(2), repeat=n)}
for vec in vectors:
    m += vectors[vec] + mip.xsum([vectors[neighbor] for neighbor in neighbors(vec)]) >= 2

m.objective = mip.xsum(vectors.values())

m.max_mip_gap = 0.5
m.optimize()

Thanks for checking out the issue!

Kind regards, Paul

nick-gorman commented 4 years ago

Hi,

I think I'm also getting this issue, with GUROBI 9.0.2, and mip 1.11 on linux I can't seem to force the gap down using min_max_gap or min_max_gap_abs to the lower gap I'm getting with CBC.

nick-gorman commented 4 years ago

I think I have a solution to this.

If I reach inside the mip model and update the min_max_gap directly then they seem to have desired effect.

mip_model = Model("market", solver_name=GUROBI)

mip_model.solver.set_mip_gap_abs(1e-13)
mip_model.solver.set_mip_gap(1e-22)

Using a the debugger it seems that these methods don't get called when I just set the properties on the model, could this be the issue @h-g-s , @tuliotoffolo ?

h-g-s commented 4 years ago

Hi @nick-gorman , thanks for point out! commiting fix to master, cheers