this is part of my code that I am adding lazy constraint inside the callback function (any variable that has the MIPNODE in the beginning of the name, is just the value of that variable inside the MIPSOL and is just wrong naming):
MIPNODE_expr_tmp = model._teta[s] - (quicksum(model._Cost[(s,(i,j))] + (model._d[(s,(i,j))] * model._x_master[(i,j)]) for (i,j) in model._P[s,model._l[s]]))
MIPNODE_expr_tmp2 = MIPNODE_master_teta[s] - (quicksum(model._Cost[(s,(i,j))] + model._d[(s,(i,j))] * MIPNODE_master_x_hat[(i,j)] for (i,j) in model._P[s,model._l[s]]))
if MIPNODE_expr_tmp2 > 1E-5:
# add lazy cut
print("**************************lazzzzzzzzzzzzzzzzzzzzzzzzzzzy")
model.cbLazy(MIPNODE_expr_tmp <= 0)
model._flag = 0
Before coming to callback, I send the list of variable to callback like this:
m1._x_master = x_master
m1._teta = teta
x_master and teta are the name of variable list when I was defining them in model.
now when inside the callback, algorithm try to add a lazy constrain, an error happens that I don't know why:
************* WE ARE IN MIPSOL *****************
**************************lazzzzzzzzzzzzzzzzzzzzzzzzzzzy
Exception gurobipy.GurobiError: GurobiError() in 'gurobipy.callbackstub' ignored