Hi,
to kill cplex have you tried the progress listener ?
Let me adapt the tiny
example
from docplex.mp.model import Model
from docplex.mp.progress import *
import os
mdl = Model(name='buses')
nbbus40 = mdl.integer_var(name='nbBus40')
nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(nbbus40*40 + nbbus30*30 >= 300, 'kids')
mdl.minimize(nbbus40*500 + nbbus30*400)
class pl(ProgressListener):
def __init__(self):
ProgressListener.__init__(self, ProgressClock.Gap)
def notify_progress(self, pdata):
gap = pdata.mip_gap
ms_time = 1000* pdata.time
print('-- new gap: {0:.1%}, time: {1:.0f} ms'.format(gap, ms_time))
os.abort()
print("never here")
# connect a listener to the model
mdl.add_progress_listener(pl())
mdl.solve(log_output=False,)
mdl.export("c:\\temp\\buses.lp")
for v in mdl.iter_integer_vars():
print(v," = ",v.solution_value)
------------------------------
[Alex] [Fleischer]
[EMEA CPLEX Optimization Technical Sales]
[IBM]
------------------------------
Original Message:
Sent: Thu September 02, 2021 08:54 AM
From: s charaf
Subject: Kill docplex
Hi,
I have a program that calls cplex multiple times (to solve master problems in a branch and price).
The program should stop after a timelimit, however when cplex is running the function
@contextmanager
def time_limit(seconds, msg=''):
timer = threading.Timer(seconds, lambda: _thread.interrupt_main())
timer.start()
try:
yield
except KeyboardInterrupt:
raise TimeoutException("Timed out for operation {}".format(msg))
finally:
# if the action ends in specified time, timer is canceled
timer.cancel()
I cannot kill the program as CPLEX keeps running.
I read it is possible to kill it via a callback function Is it possible to kill CPLEX from outside? however I am not sure how to use it.
Q: how to kill CPLEX/docplex from outside either by using callbacks or any other way.
#DecisionOptimization