Note
Go to the end to download the full example code.
Evaluate variability of a DOcplex model#
We will evaluate variability of the instance glass4 from MIPLIB 2010 using the opti-extensions library.
Reference: Koch, Thorsten, Tobias Achterberg, Erling Andersen, Oliver Bastert, Timo Berthold, Robert E. Bixby, Emilie Danna et al. “MIPLIB 2010: Mixed integer programming library version 5.” Mathematical Programming Computation 3 (2011): 103-163.
Fetch the instance#
from pathlib import Path
from urllib.request import urlopen
Path('instances').mkdir(exist_ok=True)
name = 'glass4.mps.gz'
response = urlopen(f'https://miplib.zib.de/WebData/instances/{name}')
response_OK = True
if response.getcode() == 200:
with open(f'instances/{name}', 'wb') as fp:
fp.write(response.read())
else:
response_OK = False
print(f'Could not fetch the instance {name} from MIPLIB 2010')
Run the runseeds procedure#
from docplex.mp.model_reader import ModelReader
from opti_extensions.docplex import runseeds
if response_OK:
model = ModelReader.read('instances/glass4.mps.gz')
model.parameters.timelimit = 4
runseeds(model, count=3, log_output=True)
=== Starting variability optimization #1 ===
Tried aggregator 1 time.
MIP Presolve eliminated 4 rows and 5 columns.
MIP Presolve modified 88 coefficients.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.81 ticks)
Probing time = 0.00 sec. (0.59 ticks)
Tried aggregator 1 time.
Detecting symmetries...
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (1.08 ticks)
Probing time = 0.00 sec. (0.59 ticks)
Clique table members: 192.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 2 threads.
Root relaxation solution time = 0.00 sec. (0.48 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
* 0+ 0 3.69170e+09 8.00002e+08 78.33%
0 0 8.00002e+08 72 3.69170e+09 8.00002e+08 36 78.33%
0 0 8.00002e+08 72 3.69170e+09 Cuts: 72 130 78.33%
0 0 8.00002e+08 72 3.69170e+09 Cuts: 96 218 78.33%
* 0+ 0 3.66670e+09 8.00002e+08 78.18%
* 0+ 0 2.90003e+09 8.00002e+08 72.41%
0 2 8.00002e+08 72 2.90003e+09 8.00002e+08 218 72.41%
Elapsed time = 0.04 sec. (36.16 ticks, tree = 0.02 MB, solutions = 3)
* 90+ 65 2.55002e+09 8.00003e+08 68.63%
* 140+ 99 2.53336e+09 8.00003e+08 68.42%
* 250+ 209 2.50002e+09 8.00003e+08 68.00%
* 518+ 302 2.42002e+09 8.00003e+08 66.94%
* 518+ 302 2.40002e+09 8.00003e+08 66.67%
* 518+ 296 2.38891e+09 8.00003e+08 66.51%
* 518+ 296 2.36669e+09 8.00003e+08 66.20%
* 518+ 296 2.30002e+09 8.00003e+08 65.22%
* 518+ 416 2.28464e+09 8.00003e+08 64.98%
* 518+ 296 2.28160e+09 8.00003e+08 64.94%
* 518+ 416 2.26669e+09 8.00003e+08 64.71%
* 518+ 416 2.22225e+09 8.00003e+08 64.00%
* 518+ 416 2.21669e+09 8.00003e+08 63.91%
* 518+ 296 2.19169e+09 8.00003e+08 63.50%
* 518+ 416 2.15002e+09 8.00003e+08 62.79%
* 518+ 296 2.15002e+09 8.00003e+08 62.79%
* 1046+ 752 2.04056e+09 8.00003e+08 60.79%
1046 754 1.30001e+09 44 2.04056e+09 8.00003e+08 4808 60.79%
* 1451+ 1185 2.00002e+09 8.00003e+08 60.00%
Performing restart 1
Repeating presolve.
Tried aggregator 1 time.
MIP Presolve modified 606 coefficients.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.87 ticks)
Tried aggregator 1 time.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (1.13 ticks)
Represolve time = 0.00 sec. (3.71 ticks)
* 1452+ 0 2.00002e+09 8.00003e+08 60.00%
1452 0 8.00003e+08 132 2.00002e+09 Cuts: 198 7907 60.00%
1452 0 8.00003e+08 154 2.00002e+09 Cuts: 198 7995 60.00%
1452 0 8.00003e+08 128 2.00002e+09 Cuts: 198 8080 60.00%
1452 0 8.00004e+08 148 2.00002e+09 Cuts: 198 8189 60.00%
1452 0 8.00004e+08 128 2.00002e+09 Cuts: 198 8301 60.00%
1452 0 8.00004e+08 116 2.00002e+09 Cuts: 198 8393 60.00%
1452 0 8.00004e+08 109 2.00002e+09 Cuts: 198 8452 60.00%
1452 0 8.00005e+08 110 2.00002e+09 Cuts: 198 8558 60.00%
1452 0 8.00005e+08 135 2.00002e+09 Cuts: 198 8619 60.00%
1452 0 8.00005e+08 149 2.00002e+09 Cuts: 134 8669 60.00%
1452 0 8.00005e+08 120 2.00002e+09 Cuts: 198 8790 60.00%
1452 0 8.00005e+08 119 2.00002e+09 Cuts: 192 8914 60.00%
1452 0 8.00005e+08 91 2.00002e+09 Cuts: 135 9014 60.00%
1452 0 8.00005e+08 113 2.00002e+09 Cuts: 198 9127 60.00%
1452 0 8.00005e+08 97 2.00002e+09 Cuts: 198 9205 60.00%
1452 0 8.00005e+08 103 2.00002e+09 Cuts: 198 9283 60.00%
1452 0 8.00005e+08 98 2.00002e+09 Cuts: 191 9417 60.00%
* 1452+ 0 1.95002e+09 8.00005e+08 58.97%
* 1452+ 0 1.80001e+09 8.00005e+08 55.56%
1452 0 -1.00000e+75 0 1.80001e+09 8.00005e+08 9417 55.56%
1452 2 8.00005e+08 90 1.80001e+09 8.00005e+08 9417 55.56%
1752 179 1.40001e+09 45 1.80001e+09 8.00005e+08 10812 55.56%
2299 669 1.20001e+09 26 1.80001e+09 8.00005e+08 15543 55.56%
2572 919 8.00005e+08 66 1.80001e+09 8.00005e+08 18095 55.56%
3295 1409 1.50001e+09 22 1.80001e+09 8.00005e+08 23057 55.56%
3729 1753 1.60001e+09 53 1.80001e+09 8.01137e+08 27231 55.49%
4949 2888 1.70001e+09 50 1.80001e+09 8.18755e+08 39291 54.51%
5962 3802 9.00006e+08 79 1.80001e+09 8.33339e+08 50054 53.70%
Starting limited solution polishing.
* 6467+ 4203 1.80001e+09 8.49993e+08 52.78%
* 6472+ 4199 1.75001e+09 8.49993e+08 51.43%
* 6812+ 4184 1.75001e+09 8.50005e+08 51.43%
* 6814+ 4121 1.70001e+09 8.50005e+08 50.00%
Cover cuts applied: 1
Implied bound cuts applied: 49
Flow cuts applied: 24
Mixed integer rounding cuts applied: 196
Gomory fractional cuts applied: 34
Root node processing (before b&c):
Real time = 0.04 sec. (36.03 ticks)
Parallel b&c, 2 threads:
Real time = 3.96 sec. (3253.63 ticks)
Sync time (average) = 0.10 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 4.00 sec. (3289.66 ticks)
=== Starting variability optimization #2 ===
Tried aggregator 1 time.
MIP Presolve eliminated 4 rows and 5 columns.
MIP Presolve modified 88 coefficients.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.81 ticks)
Probing time = 0.00 sec. (0.59 ticks)
Tried aggregator 1 time.
Detecting symmetries...
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (1.08 ticks)
Probing time = 0.00 sec. (0.59 ticks)
Clique table members: 192.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 2 threads.
Root relaxation solution time = 0.00 sec. (0.48 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
* 0+ 0 3.69170e+09 8.00002e+08 78.33%
0 0 8.00002e+08 72 3.69170e+09 8.00002e+08 36 78.33%
0 0 8.00002e+08 72 3.69170e+09 Cuts: 72 130 78.33%
0 0 8.00002e+08 72 3.69170e+09 Cuts: 97 222 78.33%
0 2 8.00002e+08 72 3.69170e+09 8.00002e+08 222 78.33%
Elapsed time = 0.04 sec. (33.19 ticks, tree = 0.02 MB, solutions = 1)
* 10+ 1 3.32503e+09 8.00002e+08 75.94%
* 22+ 1 3.32501e+09 8.00002e+08 75.94%
* 108+ 82 2.53336e+09 8.00002e+08 68.42%
* 160+ 121 2.45336e+09 8.00003e+08 67.39%
* 190+ 173 2.40002e+09 8.00003e+08 66.67%
* 260+ 213 2.33002e+09 8.00003e+08 65.67%
* 336+ 234 2.10002e+09 8.00003e+08 61.91%
* 540+ 436 2.10002e+09 8.00003e+08 61.90%
* 540+ 436 2.10002e+09 8.00003e+08 61.90%
873 737 1.65002e+09 36 2.10002e+09 8.00003e+08 4219 61.90%
* 942+ 863 2.07502e+09 8.00003e+08 61.45%
* 1002+ 856 2.00835e+09 8.00003e+08 60.17%
* 1132+ 856 2.00002e+09 8.00003e+08 60.00%
* 1142+ 856 1.96002e+09 8.00003e+08 59.18%
Performing restart 1
Repeating presolve.
Tried aggregator 1 time.
MIP Presolve modified 606 coefficients.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.87 ticks)
Tried aggregator 1 time.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (1.13 ticks)
Represolve time = 0.00 sec. (3.72 ticks)
1153 0 8.00003e+08 106 1.96002e+09 Cuts: 164 6603 59.18%
1153 0 8.00003e+08 102 1.96002e+09 Cuts: 198 6678 59.18%
1153 0 8.00004e+08 94 1.96002e+09 Cuts: 198 6778 59.18%
1153 0 8.00004e+08 118 1.96002e+09 Cuts: 198 6867 59.18%
1153 0 8.00004e+08 122 1.96002e+09 Cuts: 198 6929 59.18%
1153 0 8.00004e+08 134 1.96002e+09 Cuts: 198 6986 59.18%
1153 0 8.00004e+08 117 1.96002e+09 Cuts: 198 7050 59.18%
1153 0 8.00004e+08 120 1.96002e+09 Cuts: 198 7102 59.18%
1153 0 8.00004e+08 106 1.96002e+09 Cuts: 198 7173 59.18%
1153 0 8.00005e+08 127 1.96002e+09 Cuts: 188 7217 59.18%
1153 0 8.00005e+08 127 1.96002e+09 Cuts: 177 7284 59.18%
1153 0 8.00005e+08 107 1.96002e+09 Cuts: 84 7331 59.18%
1153 0 8.00005e+08 111 1.96002e+09 Cuts: 198 7383 59.18%
1153 0 8.00005e+08 114 1.96002e+09 Cuts: 170 7443 59.18%
1153 0 8.00005e+08 112 1.96002e+09 Cuts: 153 7499 59.18%
1153 2 8.00005e+08 102 1.96002e+09 8.00005e+08 7499 59.18%
* 1345+ 89 1.93335e+09 8.00005e+08 58.62%
1358 147 1.60001e+09 23 1.93335e+09 8.00005e+08 9118 58.62%
* 1508+ 222 1.90002e+09 8.00005e+08 57.89%
* 1553+ 316 1.86668e+09 8.00005e+08 57.14%
* 1597+ 316 1.86668e+09 8.00005e+08 57.14%
* 1753+ 390 1.83335e+09 8.00005e+08 56.36%
* 1753+ 384 1.81668e+09 8.00005e+08 55.96%
* 1753+ 384 1.81113e+09 8.00005e+08 55.83%
* 1753+ 384 1.80002e+09 8.00005e+08 55.56%
1753 405 1.10001e+09 55 1.80002e+09 8.00005e+08 10819 55.56%
* 2053+ 542 1.76668e+09 8.00005e+08 54.72%
* 2053+ 542 1.72502e+09 8.00005e+08 53.62%
* 2078+ 582 1.70002e+09 8.00005e+08 52.94%
* 2253+ 633 1.64002e+09 8.00005e+08 51.22%
* 2253+ 633 1.60001e+09 8.00005e+08 50.00%
2253 633 1.60001e+09 0 1.60001e+09 8.00005e+08 13399 50.00%
2653 1006 1.00320e+09 60 1.60001e+09 8.00005e+08 18037 50.00%
3344 1527 8.00005e+08 67 1.60001e+09 8.00005e+08 24704 50.00%
4101 2228 1.10001e+09 46 1.60001e+09 8.00005e+08 37181 50.00%
4955 2880 1.00001e+09 43 1.60001e+09 8.00005e+08 49533 50.00%
* 5350+ 2994 1.60001e+09 8.00005e+08 50.00%
Cover cuts applied: 3
Implied bound cuts applied: 67
Flow cuts applied: 10
Mixed integer rounding cuts applied: 149
Gomory fractional cuts applied: 17
Root node processing (before b&c):
Real time = 0.04 sec. (33.05 ticks)
Parallel b&c, 2 threads:
Real time = 3.96 sec. (3225.72 ticks)
Sync time (average) = 0.11 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 4.00 sec. (3258.77 ticks)
=== Starting variability optimization #3 ===
Tried aggregator 1 time.
MIP Presolve eliminated 4 rows and 5 columns.
MIP Presolve modified 88 coefficients.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.81 ticks)
Probing time = 0.00 sec. (0.59 ticks)
Tried aggregator 1 time.
Detecting symmetries...
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (1.08 ticks)
Probing time = 0.00 sec. (0.59 ticks)
Clique table members: 192.
MIP emphasis: balance optimality and feasibility.
MIP search method: dynamic search.
Parallel mode: deterministic, using up to 2 threads.
Root relaxation solution time = 0.00 sec. (0.48 ticks)
Nodes Cuts/
Node Left Objective IInf Best Integer Best Bound ItCnt Gap
* 0+ 0 3.69170e+09 8.00002e+08 78.33%
0 0 8.00002e+08 72 3.69170e+09 8.00002e+08 36 78.33%
0 0 8.00002e+08 72 3.69170e+09 Cuts: 72 130 78.33%
0 0 8.00002e+08 72 3.69170e+09 Cuts: 88 216 78.33%
0 2 8.00002e+08 72 3.69170e+09 8.00002e+08 216 78.33%
Elapsed time = 0.04 sec. (31.38 ticks, tree = 0.02 MB, solutions = 1)
* 10+ 10 3.17503e+09 8.00002e+08 74.80%
* 396+ 310 3.06670e+09 8.00002e+08 73.91%
* 601+ 501 3.05002e+09 8.00002e+08 73.77%
* 601+ 463 2.97503e+09 8.00002e+08 73.11%
* 601+ 463 2.90003e+09 8.00002e+08 72.41%
* 601+ 463 2.80003e+09 8.00002e+08 71.43%
* 601+ 463 2.80003e+09 8.00002e+08 71.43%
* 601+ 463 2.75003e+09 8.00002e+08 70.91%
* 601+ 463 2.65003e+09 8.00002e+08 69.81%
* 601+ 463 2.60002e+09 8.00002e+08 69.23%
* 601+ 463 2.60002e+09 8.00002e+08 69.23%
* 688+ 514 2.60002e+09 8.00002e+08 69.23%
* 727+ 584 2.50002e+09 8.00003e+08 68.00%
* 886+ 643 2.50002e+09 8.00003e+08 68.00%
* 910+ 705 2.48336e+09 8.00003e+08 67.79%
* 911+ 705 2.36669e+09 8.00003e+08 66.20%
* 911+ 705 2.30002e+09 8.00003e+08 65.22%
* 911+ 705 2.30002e+09 8.00003e+08 65.22%
911 707 8.00005e+08 75 2.30002e+09 8.00003e+08 4635 65.22%
* 912+ 708 2.26669e+09 8.00003e+08 64.71%
* 912+ 708 2.25002e+09 8.00003e+08 64.44%
* 912+ 708 2.21252e+09 8.00003e+08 63.84%
* 912+ 708 2.20002e+09 8.00003e+08 63.64%
* 912+ 708 2.13335e+09 8.00003e+08 62.50%
* 992+ 786 2.12002e+09 8.00003e+08 62.26%
* 1093+ 876 2.05002e+09 8.00003e+08 60.98%
Performing restart 1
Repeating presolve.
Tried aggregator 1 time.
MIP Presolve modified 606 coefficients.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (0.87 ticks)
Tried aggregator 1 time.
Reduced MIP has 392 rows, 317 columns, and 1799 nonzeros.
Reduced MIP has 298 binaries, 0 generals, 0 SOSs, and 0 indicators.
Presolve time = 0.00 sec. (1.13 ticks)
Represolve time = 0.00 sec. (3.78 ticks)
* 1094+ 0 2.05002e+09 8.00003e+08 60.98%
1094 0 8.00003e+08 123 2.05002e+09 Cuts: 198 6254 60.98%
1094 0 8.00003e+08 139 2.05002e+09 Cuts: 198 6326 60.98%
1094 0 8.00004e+08 112 2.05002e+09 Cuts: 198 6411 60.98%
1094 0 8.00004e+08 146 2.05002e+09 Cuts: 198 6480 60.98%
1094 0 8.00004e+08 128 2.05002e+09 Cuts: 189 6566 60.98%
1094 0 8.00004e+08 130 2.05002e+09 Cuts: 198 6628 60.98%
1094 0 8.00004e+08 126 2.05002e+09 Cuts: 198 6677 60.98%
1094 0 8.00004e+08 128 2.05002e+09 Cuts: 174 6735 60.98%
1094 0 8.00005e+08 133 2.05002e+09 Cuts: 132 6785 60.98%
1094 0 8.00005e+08 131 2.05002e+09 Cuts: 144 6850 60.98%
1094 0 8.00005e+08 120 2.05002e+09 Cuts: 194 6916 60.98%
1094 0 8.00005e+08 116 2.05002e+09 Cuts: 198 6990 60.98%
1094 0 8.00005e+08 111 2.05002e+09 Cuts: 136 7056 60.98%
1094 0 8.00005e+08 97 2.05002e+09 Cuts: 144 7122 60.98%
1094 0 8.00005e+08 105 2.05002e+09 Cuts: 198 7177 60.98%
1094 0 8.00005e+08 102 2.05002e+09 Cuts: 85 7221 60.98%
* 1094+ 0 1.86668e+09 8.00005e+08 57.14%
1094 2 8.00005e+08 91 1.86668e+09 8.00005e+08 7221 57.14%
1294 100 8.00005e+08 80 1.86668e+09 8.00005e+08 7978 57.14%
* 1594+ 338 1.82002e+09 8.00005e+08 56.04%
* 1594+ 338 1.81668e+09 8.00005e+08 55.96%
1784 460 8.00005e+08 81 1.81668e+09 8.00005e+08 9916 55.96%
* 1794+ 524 1.80668e+09 8.00005e+08 55.72%
2196 816 1.50001e+09 26 1.80668e+09 8.00005e+08 11792 55.72%
* 2794+ 1273 1.80478e+09 8.00005e+08 55.67%
2794 1274 1.80002e+09 22 1.80478e+09 8.00005e+08 14865 55.67%
* 3124+ 1621 1.80002e+09 8.00005e+08 55.56%
3798 2102 1.75001e+09 22 1.80002e+09 8.00005e+08 19486 55.56%
* 4835+ 3025 1.80002e+09 8.00005e+08 55.56%
5119 3331 1.30001e+09 74 1.80002e+09 8.00005e+08 27308 55.56%
* 6098 3838 integral 0 1.80001e+09 8.00005e+08 30985 55.56%
6420 4180 1.40001e+09 41 1.80001e+09 8.00005e+08 33943 55.56%
Clique cuts applied: 3
Implied bound cuts applied: 30
Flow cuts applied: 13
Mixed integer rounding cuts applied: 102
Gomory fractional cuts applied: 21
Root node processing (before b&c):
Real time = 0.04 sec. (31.28 ticks)
Parallel b&c, 2 threads:
Real time = 3.97 sec. (3232.20 ticks)
Sync time (average) = 0.09 sec.
Wait time (average) = 0.00 sec.
------------
Total (root+branch&cut) = 4.00 sec. (3263.48 ticks)
====== runseeds statistics of 3 runs
exit sol objective gap iteration node runtime dettime
run code stat value (%) count count seconds ticks
1 0 107 1.70001e+09 47.06 66920 7252 4.00 3289.68
2 0 107 1.60001e+09 50.00 67525 5962 4.00 3258.79
3 0 107 1.80001e+09 55.56 42845 7394 4.00 3263.50
Exit codes:
0 : No error
Optimization status codes:
objective gap iteration node runtime dettime
value (%) count count seconds ticks
107 : time limit exceeded (3 times)
average: 1.70001e+09 50.87 59097 6869 4.00 3270.65
minimum: 1.60001e+09 47.06 42845 5962 4.00 3258.79
maximum: 1.80001e+09 55.56 67525 7394 4.00 3289.68
std dev: 1e+08 4.31 14078 789 0.00 16.64
Total running time of the script: (0 minutes 12.589 seconds)