Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

CPLEX callbacks

16 views
Skip to first unread message

Amin Moghimy Fam

unread,
Feb 17, 2025, 10:22:56 AMFeb 17
to Pyomo Forum
Dear all,

I have been searching to implement CPLEX callbacks using pyomo. I have the CPLEX for academic use and I create the solver as below:
opt = SolverFactory('cplex')
Then, I enable the callbacks and try to do something like this:
def StopCriterion(solver, model):
        if solver.get_num_nodes() > -1:
            print(aaaaaaaaaaaaaaaaaaaaa)
opt._allow_callbacks = True
opt.set_callback('MIPInfoCallback', StopCriterion)
However, I fail to get any result. My final goal is to enable a function to be able to terminate cplex at any time and get the most up to date results.

Is there any way to implement it?

Ahmad Heidari

unread,
Mar 12, 2025, 10:43:08 AMMar 12
to Pyomo Forum
Hello Amin, 

I hope you are doing well.

Unfortunately, when the solver does not achieve a feasible solution, it does not produce meaningful results. To address this issue, you may consider adjusting certain solver parameters. For instance, you can specify the following criteria:

solver = SolverFactory('gurobi')
solver.options['NonConvex'] = 2
solver.options['MIPGap'] = 0.1
solver.options['MIPGapAbs'] = 0.1

# ... (other parameters)

However, it is important to note that unless the solver successfully converges, it will continue running and may not terminate automatically.


Please let me know if further explanation is needed. 

Reply all
Reply to author
Forward
0 new messages