1
$\begingroup$

I am trying to figure out what is the correct use of cplex callbacks in pyomo. In particular I am looking for the translation of the following example from gurobi to cplex:

from gurobipy import GRB
import pyomo.environ as pe
from pyomo.core.expr.taylor_series import taylor_series_expansion

m = pe.ConcreteModel()
m.x = pe.Var(bounds=(0, 4))
m.y = pe.Var(within=pe.Integers, bounds=(0, None))
m.obj = pe.Objective(expr=2*m.x + m.y)
m.cons = pe.ConstraintList()  # for the cutting planes

def _add_cut(xval):
    # a function to generate the cut
    m.x.value = xval
    return m.cons.add(m.y >= taylor_series_expansion((m.x - 2)**2))

_add_cut(0)  # start with 2 cuts at the bounds of x
_add_cut(4)  # this is an arbitrary choice

opt = pe.SolverFactory('gurobi_persistent')
opt.set_instance(m)
opt.set_gurobi_param('PreCrush', 1)
opt.set_gurobi_param('LazyConstraints', 1)

def my_callback(cb_m, cb_opt, cb_where):
    if cb_where == GRB.Callback.MIPSOL:
        cb_opt.cbGetSolution(vars=[m.x, m.y])
        if m.y.value < (m.x.value - 2)**2 - 1e-6:
            cb_opt.cbLazy(_add_cut(m.x.value))

opt.set_callback(my_callback)
opt.solve()
$\endgroup$
2
  • $\begingroup$ Did you found the solution? I know this question is very old but this is my problem too. $\endgroup$ Jun 18 at 15:44
  • $\begingroup$ @MaryamEsfahani, Pyomo has an interactive forum and also a google group you could ask your question there. Also, there are cloud-based optimization solvers like optilogic with a focus on pyomo that might help you to get an answer to your question. $\endgroup$
    – A.Omidi
    Jun 19 at 11:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.