Gurobi example¶
[1]:
from optiwindnet.importer import load_repository
from optiwindnet.svg import svgplot
from optiwindnet.mesh import make_planar_embedding
from optiwindnet.interarraylib import G_from_S
from optiwindnet.heuristics import constructor
from optiwindnet.MILP import solver_factory, ModelOptions
Initialize Gwynt y Mor¶
[2]:
locations = load_repository()
[3]:
L = locations.gwynt
capacity = 6
[4]:
svgplot(L)
[4]:
Optimize Gwynt y Mor¶
[5]:
P, A = make_planar_embedding(L)
Initial heuristic solution to warm-start the solver:
[6]:
Sʹ = constructor(A, capacity=capacity)
Gʹ = G_from_S(Sʹ, A)
svgplot(Gʹ)
[6]:
[7]:
solver = solver_factory('gurobi')
[8]:
solver.set_problem(
P, A,
capacity=Sʹ.graph['capacity'],
model_options=ModelOptions(
topology="branched",
feeder_route="segmented",
feeder_limit="unlimited",
),
warmstart=Sʹ,
)
Set parameter WLSAccessID
Set parameter WLSSecret
Set parameter LicenseID to value 937681
Set parameter MIPFocus to value 1
Academic license 937681 - for non-commercial use only - registered to ma___@dtu.dk
[9]:
solver.solve(
mip_gap=0.005,
time_limit=90,
verbose=True,
)
Set parameter TimeLimit to value 90
Set parameter MIPGap to value 0.005
Gurobi Optimizer version 13.0.2 build v13.0.2rc1 (linux64 - "Debian GNU/Linux forky/sid")
CPU model: 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 8 physical cores, 16 logical processors, using up to 16 threads
Non-default parameters:
TimeLimit 90
MIPGap 0.005
MIPFocus 1
Academic license 937681 - for non-commercial use only - registered to ma___@dtu.dk
Optimize a model with 5938 rows, 3976 columns and 22544 nonzeros (Min)
Model fingerprint: 0xf57374e8
Model has 1988 linear objective coefficients
Variable types: 0 continuous, 3976 integer (1988 binary)
Coefficient statistics:
Matrix range [1e+00, 6e+00]
Objective range [4e+02, 1e+04]
Bounds range [1e+00, 6e+00]
RHS range [1e+00, 2e+02]
Loaded user MIP start with objective 136103
Presolve removed 757 rows and 0 columns
Presolve time: 0.03s
Presolved: 5181 rows, 3976 columns, 19044 nonzeros
Variable types: 0 continuous, 3976 integer (1988 binary)
Root relaxation: objective 1.252287e+05, 4730 iterations, 0.08 seconds (0.10 work units)
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 125228.749 0 310 136103.285 125228.749 7.99% - 0s
H 0 0 136065.07661 125228.749 7.96% - 0s
H 0 0 135994.94515 125228.749 7.92% - 0s
H 0 0 135395.43711 125228.749 7.51% - 0s
H 0 0 135009.41580 125228.749 7.24% - 0s
H 0 0 133571.28698 125228.749 6.25% - 0s
0 0 125519.360 0 492 133571.287 125519.360 6.03% - 0s
H 0 0 133569.54874 125519.360 6.03% - 0s
H 0 0 133338.08445 125519.360 5.86% - 0s
H 0 0 133107.51091 125519.360 5.70% - 0s
H 0 0 133106.63501 125519.360 5.70% - 0s
H 0 0 133105.73725 125519.360 5.70% - 0s
H 0 0 133094.66555 125519.360 5.69% - 0s
0 0 125641.091 0 514 133094.666 125641.091 5.60% - 0s
0 0 125648.829 0 524 133094.666 125648.829 5.59% - 0s
0 0 125649.955 0 539 133094.666 125649.955 5.59% - 0s
0 0 125650.150 0 544 133094.666 125650.150 5.59% - 0s
H 0 0 133094.50473 125650.150 5.59% - 0s
0 0 125994.529 0 557 133094.505 125994.529 5.33% - 1s
0 0 126000.172 0 534 133094.505 126000.172 5.33% - 1s
0 0 126021.660 0 541 133094.505 126021.660 5.31% - 1s
0 0 126027.963 0 530 133094.505 126027.963 5.31% - 1s
0 0 126029.213 0 538 133094.505 126029.213 5.31% - 1s
0 0 126029.240 0 537 133094.505 126029.240 5.31% - 1s
H 0 0 133093.72744 126164.177 5.21% - 1s
H 0 0 133093.37507 126164.177 5.21% - 1s
H 0 0 133093.27941 126164.177 5.21% - 1s
0 0 126164.177 0 578 133093.279 126164.177 5.21% - 1s
H 0 0 133093.11131 126164.177 5.21% - 1s
H 0 0 133093.10756 126164.177 5.21% - 1s
H 0 0 133092.96500 126164.177 5.21% - 1s
H 0 0 133092.52885 126164.177 5.21% - 1s
H 0 0 132600.01602 126209.885 4.82% - 2s
H 0 0 132521.18150 126209.885 4.76% - 2s
0 0 126269.057 0 539 132521.181 126269.057 4.72% - 2s
0 0 126279.293 0 568 132521.181 126279.293 4.71% - 2s
0 0 126279.356 0 558 132521.181 126279.356 4.71% - 2s
0 0 126279.356 0 566 132521.181 126279.356 4.71% - 2s
0 0 126279.356 0 570 132521.181 126279.356 4.71% - 2s
0 0 126279.356 0 574 132521.181 126279.356 4.71% - 2s
H 0 0 132520.86101 126279.356 4.71% - 2s
0 0 126374.883 0 574 132520.861 126374.883 4.64% - 2s
0 0 126406.943 0 600 132520.861 126406.943 4.61% - 2s
H 0 0 132519.77567 126415.813 4.61% - 3s
0 0 126415.813 0 559 132519.776 126415.813 4.61% - 3s
0 0 126418.298 0 578 132519.776 126418.298 4.60% - 3s
0 0 126419.292 0 582 132519.776 126419.292 4.60% - 3s
0 0 126419.465 0 586 132519.776 126419.465 4.60% - 3s
0 0 126419.528 0 593 132519.776 126419.528 4.60% - 3s
0 0 126448.915 0 565 132519.776 126448.915 4.58% - 3s
0 0 126448.915 0 565 132519.776 126448.915 4.58% - 3s
0 0 126448.915 0 565 132519.776 126448.915 4.58% - 3s
H 0 0 132519.75379 126448.920 4.58% - 4s
H 0 2 132516.53326 126448.920 4.58% - 7s
0 2 126448.920 0 565 132516.533 126448.920 4.58% - 7s
H 5 8 132367.98692 126456.755 4.47% 194 7s
H 39 49 132101.60251 126473.190 4.26% 353 8s
H 70 73 132100.74907 126473.190 4.26% 387 9s
H 74 91 132099.47785 126473.190 4.26% 389 9s
H 78 91 132098.71285 126473.190 4.26% 397 9s
H 100 103 132097.98574 126473.190 4.26% 393 9s
102 111 126797.575 12 548 132097.986 126473.190 4.26% 397 10s
H 107 111 132097.53363 126473.190 4.26% 397 10s
H 108 111 132066.71259 126473.190 4.24% 396 10s
H 113 122 131722.50062 126473.190 3.99% 394 10s
H 135 148 131533.92609 126473.190 3.85% 389 10s
H 147 156 131532.80521 126473.190 3.85% 371 10s
H 192 201 131532.28920 126473.190 3.85% 350 11s
H 239 242 131526.97267 126473.190 3.84% 328 12s
H 289 295 131526.91727 126473.190 3.84% 312 14s
337 367 127924.573 32 452 131526.917 126473.190 3.84% 289 15s
H 353 367 131492.15273 126473.190 3.82% 281 15s
H 396 404 131489.68530 126473.190 3.82% 267 15s
H 486 495 130987.99225 126473.190 3.45% 244 16s
H 517 522 130421.69673 126473.190 3.03% 240 16s
H 522 535 130421.40259 126473.190 3.03% 239 17s
H 528 535 130421.07013 126473.190 3.03% 237 17s
H 529 535 130420.63186 126473.190 3.03% 238 17s
H 552 590 130183.15438 126473.190 2.85% 237 17s
H 633 620 130183.13248 126473.190 2.85% 224 18s
H 647 656 130182.59835 126473.190 2.85% 223 19s
H 689 652 129836.98743 126473.190 2.59% 215 19s
H 727 681 129835.86569 126473.190 2.59% 213 19s
742 688 128394.541 67 385 129835.866 126473.190 2.59% 212 20s
H 744 688 129824.12067 126473.190 2.58% 211 20s
H 800 775 129823.58653 126473.190 2.58% 212 21s
H 1068 982 129822.97843 126473.190 2.58% 200 23s
H 1101 1067 129822.43901 126476.407 2.58% 199 23s
H 1107 1067 129822.22532 126476.407 2.58% 199 23s
H 1183 1075 129812.75274 126476.407 2.57% 197 24s
1191 1141 126761.012 10 555 129812.753 126476.407 2.57% 196 25s
H 1194 1141 129809.57955 126476.407 2.57% 196 25s
H 1212 1141 129809.41873 126476.407 2.57% 196 25s
H 1243 1133 129785.07555 126476.407 2.55% 195 25s
H 1261 1279 129783.61579 126476.407 2.55% 194 25s
H 1427 1429 129783.19459 126476.407 2.55% 189 25s
H 1444 1429 129781.71314 126476.407 2.55% 188 25s
H 1509 1429 129780.91265 126476.407 2.55% 183 25s
H 1509 1429 129780.20513 126476.407 2.55% 183 25s
H 1619 1429 129779.86058 126496.487 2.53% 178 25s
H 1619 1428 129768.11557 126496.487 2.52% 178 26s
H 1625 1360 129536.13568 126496.487 2.35% 178 27s
H 1636 1299 129535.84482 126514.366 2.33% 176 28s
1650 1308 128970.574 38 639 129535.845 126571.633 2.29% 175 30s
1652 1309 129313.722 47 587 129535.845 126575.279 2.29% 175 35s
H 1873 1413 129535.13967 126617.766 2.25% 222 39s
1947 1457 127106.865 26 570 129535.140 126617.766 2.25% 231 40s
2182 1650 127288.124 32 458 129535.140 126617.766 2.25% 250 45s
2449 1775 128058.955 39 429 129535.140 126624.389 2.25% 261 50s
3034 2020 128792.887 58 378 129535.140 126642.660 2.23% 258 55s
4124 2528 127170.627 46 497 129535.140 126644.291 2.23% 244 60s
4970 2985 128283.078 126 412 129535.140 126644.291 2.23% 243 65s
5206 3176 128311.710 131 425 129535.140 126644.291 2.23% 241 70s
6810 4813 127692.463 58 467 129535.140 126663.451 2.22% 229 75s
H 7758 5306 129476.29287 126663.451 2.17% 227 77s
8682 6097 126776.184 27 529 129476.293 126663.451 2.17% 229 81s
9398 6421 129032.023 49 388 129476.293 126663.451 2.17% 229 85s
10079 6940 127186.904 41 517 129476.293 126663.451 2.17% 224 90s
Cutting planes:
Gomory: 65
Lift-and-project: 18
Cover: 5
MIR: 487
StrongCG: 15
Flow cover: 372
Flow path: 7
GUB cover: 4
Zero half: 2
Mod-K: 1
Network: 28
RLT: 4
Relax-and-lift: 12
Explored 10213 nodes (2309181 simplex iterations) in 90.02 seconds (99.60 work units)
Thread count was 16 (of 16 available processors)
Solution count 10: 129476 129535 129536 ... 129783
Time limit reached
Best objective 1.294762928720e+05, best bound 1.266634506565e+05, gap 2.1725%
[9]:
SolutionInfo(runtime=90.02284598350525, bound=126663.45065652042, objective=129476.29287204682, relgap=0.02172476638874854, termination='maxTimeLimit')
OptiWindNet uses pyomo’s gurobi_persistent interface with manage_env=True, so:
the Gurobi license is held only between
set_problem()andget_solution(), then releasedoptions that must be set at Gurobi environment creation (such as
threadlimit) can be passed by assigning them tosolver.optionsbefore callingset_problem()
Example:
solver.options.update(threadlimit=8)
solver.set_problem(...)
solver.solve(...)
[10]:
S, G = solver.get_solution()
[11]:
svgplot(G)
[11]: