I am using to solve my model Pyomo/CBC combination. But rarely, CBC Gap shows 1.#j and pyomo generate an error. Hence, it doesn't get solution. How can I solve this problem?
Screen output:
Result - Stopped on time limit
Objective value: 26848000.00000000
Lower bound: 0.000
Gap: 1.#J
Enumerated nodes: 336653
Total iterations: 620783
Time (CPU seconds): 62.14
Time (Wallclock seconds): 62.14
Total time (CPU seconds): 62.15 (Wallclock seconds): 62.15
ERROR:writeSql:could not convert string to float: '1.#J'
Traceback (most recent call last):
.
.
.
opt_success = opt.solve(model, tee=True)
File "C:\Users\python\AppData\Local\Programs\Python\Python37\lib\site-packages
\pyomo\opt\base\solvers.py", line 605, in solve
result = self._postsolve()
File "C:\Users\python\AppData\Local\Programs\Python\Python37\lib\site-packages
\pyomo\solvers\plugins\solvers\CBCplugin.py", line 870, in _postsolve
results = super(CBCSHELL, self)._postsolve()
File "C:\Users\python\AppData\Local\Programs\Python\Python37\lib\site-packages
\pyomo\opt\solver\shellcmd.py", line 270, in _postsolve
results = self.process_output(self._rc)
File "C:\Users\python\AppData\Local\Programs\Python\Python37\lib\site-packages
\pyomo\opt\solver\shellcmd.py", line 327, in process_output
results = self.process_logfile()
File "C:\Users\python\AppData\Local\Programs\Python\Python37\lib\site-packages
\pyomo\solvers\plugins\solvers\CBCplugin.py", line 563, in process_logfile
gap = float(tokens[1])
ValueError: could not convert string to float: '1.#J'
Error <class 'ValueError'> value could not convert string to float: '1.#J' diger
<traceback object at 0x000000000D0F0288>
My solution is changing CBCplugin.py related line with try-except. But I can not predict potential side effects on pyomo.
My answer: I changed CBCplugin.py, line 563:
gap = float(tokens[1])
with:
try:
gap = float(tokens[1])
except:
gap = 0.0