Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How you enable CBC to return best solution when timelimit? (Pyomo)

I am trying to use CBC(v2.10.3) on Pyomo to solve for a integer linear problem.

When executing the solver, I am currently setting a timelimit of 600s.

opt = SolverFactory ("cbc")

opt.options['seconds'] =600

Within this timelimit, solver manages to find multiple feasible solutions. However, when it times out at the end of the 600s, it does not return the best integer solution found. Instead it returns a non-integer solution.

Is there a way to use CBC on pyomo to return the best integer solution at the end of the timelimit?

(I am aware of setting an optimialty gap. However, it would be preferable to solve for a given time and return the best solution found.)

Cbc0010I After 144000 nodes, 17010 on tree, 51.908959 best solution, best possible 5.2447218 (566.79 seconds)
Cbc0010I After 145000 nodes, 16985 on tree, 51.908959 best solution, best possible 5.2447218 (568.59 seconds)
Cbc0010I After 146000 nodes, 17412 on tree, 51.908959 best solution, best possible 5.2447218 (576.34 seconds)
Cbc0010I After 147000 nodes, 17433 on tree, 51.908959 best solution, best possible 5.2447218 (578.44 seconds)
Cbc0010I After 148000 nodes, 17486 on tree, 51.908959 best solution, best possible 5.2447218 (580.85 seconds)
Cbc0010I After 149000 nodes, 17542 on tree, 51.908959 best solution, best possible 5.2447218 (583.95 seconds)
Cbc0010I After 150000 nodes, 17983 on tree, 51.908959 best solution, best possible 5.2447218 (592.30 seconds)
Cbc0010I After 151000 nodes, 18070 on tree, 51.908959 best solution, best possible 5.2447218 (595.20 seconds)
Cbc0010I After 152000 nodes, 18138 on tree, 51.908959 best solution, best possible 5.2447218 (599.62 seconds)
Cbc0020I Exiting on maximum time
Cbc0005I Partial search - best objective 51.908959 (best possible 5.2447218), took 2633537 iterations and 152193 nodes (600.40 seconds)
Cbc0032I Strong branching done 27294 times (118365 iterations), fathomed 967 nodes and fixed 3958 variables
Cbc0035I Maximum depth 321, 459 variables fixed on reduced cost
0  Obj 3.5097934 Primal inf 30287.686 (125) Dual inf 3.9849334e+15 (82)
Stopped - objective value 4.7188173e+14
Cuts at root node changed objective from 5.22475 to 5.24432
Probing was tried 187648 times and created 142527 cuts of which 0 were active after adding rounds of cuts (35.562 seconds)
Gomory was tried 89556 times and created 384764 cuts of which 0 were active after adding rounds of cuts (40.036 seconds)
Knapsack was tried 361 times and created 4 cuts of which 0 were active after adding rounds of cuts (0.233 seconds)
Clique was tried 361 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.001 seconds)
MixedIntegerRounding2 was tried 89572 times and created 84177 cuts of which 0 were active after adding rounds of cuts (33.927 seconds)
FlowCover was tried 361 times and created 14 cuts of which 0 were active after adding rounds of cuts (0.473 seconds)
TwoMirCuts was tried 89556 times and created 342658 cuts of which 0 were active after adding rounds of cuts (51.857 seconds)
ZeroHalf was tried 361 times and created 136 cuts of which 0 were active after adding rounds of cuts (0.365 seconds)

Result - Stopped on time limit

Objective value:                100000000000000007629769841091887003294964970946560.00000000
Lower bound:                    5.245
Gap:                            19066788138679049496143571255167978698885048565760.00
Enumerated nodes:               152193
Total iterations:               2633537
Time (CPU seconds):             600.48
Time (Wallclock seconds):       600.48

Total time (CPU seconds):       600.50   (Wallclock seconds):       600.51

Thank you for your help!

like image 849
tb_ Avatar asked Mar 09 '20 06:03

tb_


1 Answers

I had the same problem and I think I found a solution. The problem is that the solver exits with status "aborted". There are 2 ways to change the status of the solver:

  1. After solving the problem and before loading the solution, simply change the status:

    from pyomo.opt.results import SolverStatus
    ...
    optimizer = SolverFactory('cbc')
    result = optimizer.solve(prob,tee=True) 
    result.Solver.Status = SolverStatus.warning
    prob.solutions.load_from(result)   
    
  2. In the file "...\pyomo\solvers\plugins\solvers\CBCplugin.py", replace every SolverStatus.aborted with a SolverStatus.warning (in my case there were 2 lines). This prevents the solver from having an aborted status.

It works for me using pyomo==5.6.9 and cbc==2.10.3

like image 142
dtby Avatar answered Oct 14 '22 15:10

dtby