Skip to content

Commit 77127db

Browse files
committed
do not cut call generator in gurobi in lp relax not available
Former-commit-id: 34663b4 [formerly a68acab] Former-commit-id: 1d09503
1 parent ff8a803 commit 77127db

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

examples/queens-lazy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def col(vname: str) -> str:
3434

3535

3636
# number of queens
37-
n = 8
37+
n = 60
3838

3939
queens = Model('queens', MAXIMIZE)
4040

mip/gurobi.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@
249249
GRBgetstrattr = grblib.GRBgetstrattr
250250
GRBsetstrattr = grblib.GRBsetstrattr
251251

252-
GRB_CB_MIPSOL = 4
253-
GRB_CB_MIPNODE = 5
252+
GRB_CB_MIPSOL = 4
253+
GRB_CB_MIPNODE = 5
254254

255255
GRB_CB_PRE_COLDEL = 1000
256256
GRB_CB_PRE_ROWDEL = 1001
@@ -505,6 +505,17 @@ def callback(p_model: CData,
505505
(where == GRB_CB_MIPSOL and
506506
hasattr(self.model.cuts_generator, 'lazy_constraints') and
507507
self.model.cuts_generator.lazy_constraints):
508+
if (where == GRB_CB_MIPNODE):
509+
st = ffi.new("int *")
510+
st[0] = 0
511+
512+
error = GRBcbget(p_cbdata, where,
513+
GRB_CB_MIPNODE_STATUS, st)
514+
if error:
515+
raise Exception("Could not get gurobi status")
516+
if st[0] != GRB_OPTIMAL:
517+
return 0
518+
508519
mgc = ModelGurobiCB(p_model, p_cbdata, where)
509520
self.model.cuts_generator.generate_cuts(mgc)
510521

@@ -1153,6 +1164,9 @@ def __init__(self, model: Model, grb_model: CData = ffi.NULL,
11531164
self._status = OptimizationStatus.LOADED
11541165
self._where = where
11551166

1167+
if where not in [4, 5]:
1168+
return
1169+
11561170
# pre-allocate temporary space to query names
11571171
self.__name_space = ffi.new("char[{}]".format(MAX_NAME_SIZE))
11581172
# in cut generation

0 commit comments

Comments
 (0)