Explicitly linearizing product of binary variables worsens performance
AnsweredI am modeling a non-permutation flow shop model that includes sequence dependent setup times. As a part of the model, I get the non-linear expression
\[\sum_{j'\in\mathcal{J}}\sum_{j\in\mathcal{J}}x_{i,j',k}\cdot x_{i,j,k+1}\],
where \(x_{i,j',k}, x_{i,j,k+1}\) are binary variables. At first, I did not explicitly linearize this and just fed it to Gurobi's solver in the form of
quicksum(x[i, j1, k] * x[i, j2, k + 1] for j1 in range(J) for j2 in range(J))
I then linearized this by introducing a binary variable \(z_{i,j',j,k,k+1} = x_{i,j',k}\cdot x_{i,j,k+1}\). This means that I added the following constraints:
\[\begin{align}
&z_{i,j',j,k,k+1}\leq x_{i,j',k}\\
&z_{i,j',j,k,k+1}\leq x_{i,j,k+1}\\
&z_{i,j',j,k,k+1}\geq x_{i,j',k} + x_{i,j,k+1}-1.
\end{align}\]
Instead of the non-linear expression, I then use
\[ \sum_{j'\in\mathcal{J}}\sum_{j\in\mathcal{J}}z_{i,j',j,k,k+1}, \]
and adjust the coding accordingly.
However, I noticed that when doing this, the model performance worsens. The first and second log file of the model without and with (respectively) linearization is as follows:
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 23974.8571 0 129 68698.5714 23974.8571 65.1% - 0s
H 0 0 68683.571429 23974.8571 65.1% - 0s
H 0 0 68447.142857 23974.8571 65.0% - 0s
0 0 23974.8571 0 114 68447.1429 23974.8571 65.0% - 0s
H 0 0 59665.428571 23974.8571 59.8% - 0s
0 0 23974.8571 0 114 59665.4286 23974.8571 59.8% - 0s
0 0 23974.8571 0 110 59665.4286 23974.8571 59.8% - 0s
0 0 23974.8571 0 113 59665.4286 23974.8571 59.8% - 0s
H 0 0 54059.714286 23974.8571 55.7% - 0s
H 0 0 52184.714286 23974.8571 54.1% - 0s
H 0 0 51184.714286 23974.8571 53.2% - 0s
H 0 0 51084.714286 23974.8571 53.1% - 0s
0 0 23974.8571 0 115 51084.7143 23974.8571 53.1% - 0s
H 0 0 47952.000000 23974.8571 50.0% - 0s
0 0 23974.8571 0 115 47952.0000 23974.8571 50.0% - 0s
0 0 23974.8571 0 110 47952.0000 23974.8571 50.0% - 0s
0 0 23974.8571 0 110 47952.0000 23974.8571 50.0% - 0s
H 0 0 44996.285714 23974.8571 46.7% - 1s
0 0 23974.8571 0 110 44996.2857 23974.8571 46.7% - 1s
0 0 23974.8571 0 110 44996.2857 23974.8571 46.7% - 1s
H 0 0 44449.571428 23974.8571 46.1% - 1s
0 2 23974.8571 0 110 44449.5714 23974.8571 46.1% - 1s
H 33 36 44228.000000 23974.8571 45.8% 76.4 1s
H 36 36 44207.714286 23974.8571 45.8% 70.7 1s
H 62 74 43163.714286 23974.8571 44.5% 54.0 1s
H 96 104 42818.285714 23974.8571 44.0% 40.1 1s
H 131 149 42642.571429 23974.8571 43.8% 33.6 1s
H 151 160 42531.714286 23974.8571 43.6% 32.3 1s
H 154 160 40649.285714 23974.8571 41.0% 33.5 1s
H 259 273 40596.428571 23974.8571 40.9% 26.3 2s
H 283 288 40517.428571 23974.8571 40.8% 28.3 2s
H 289 288 40360.571429 23974.8571 40.6% 27.9 2s
H 366 442 40240.571429 23974.8571 40.4% 34.2 2s
H 494 521 40235.714286 23974.8571 40.4% 34.3 2s
H 2481 2424 40179.142857 23974.8571 40.3% 23.7 5s
H 2481 2423 40091.857143 23974.8571 40.2% 23.7 5s
H 2490 2423 40021.571429 23974.8571 40.1% 23.7 5s
H 2493 2303 40009.142857 23974.8571 40.1% 23.7 5s
H 2495 2190 39996.571429 23974.8571 40.1% 23.7 6s
H 2495 2080 39801.571429 23974.8571 39.8% 23.7 6s
H 2496 1976 39769.142857 23974.8571 39.7% 23.7 6s
H 2499 1879 39760.714286 24086.7143 39.4% 23.6 7s
H 2499 1785 39746.285714 24086.7143 39.4% 23.6 7s
H 2518 1708 39681.285714 25645.7432 35.4% 23.5 8s
H 2529 1628 39283.571429 25911.3138 34.0% 23.4 8s
H 2535 1550 39201.857143 25927.7095 33.9% 23.3 9s
H 2537 1473 39184.714286 25962.4714 33.7% 23.3 9s
H 2549 1406 39169.714286 25970.7721 33.7% 23.2 9s
2556 1410 25978.0548 36 133 39169.7143 25978.0548 33.7% 23.1 10s
H 2569 1347 38555.142857 25992.3124 32.6% 23.0 10s
H 2595 1297 38549.428571 25997.5487 32.6% 33.3 13s
2609 1306 27810.8004 223 131 38549.4286 27810.8004 27.9% 33.1 15s
H 2610 1242 38548.571429 27887.9543 27.7% 33.1 15s
H 2611 1179 38542.571429 27887.9543 27.6% 33.1 15s
H 2642 1139 38541.428571 28303.7403 26.6% 32.7 17s
Root relaxation: objective 2.397486e+04, 780 iterations, 0.03 seconds
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 23974.8571 0 130 68698.5714 23974.8571 65.1% - 0s
H 0 0 66691.000000 23974.8571 64.1% - 0s
H 0 0 66651.000000 23974.8571 64.0% - 0s
H 0 0 66451.000000 23974.8571 63.9% - 0s
H 0 0 66371.000000 23974.8571 63.9% - 0s
H 0 0 65691.000000 23974.8571 63.5% - 0s
0 0 23974.8571 0 116 65691.0000 23974.8571 63.5% - 0s
H 0 0 59665.428571 23974.8571 59.8% - 0s
0 0 23974.8571 0 116 59665.4286 23974.8571 59.8% - 0s
0 0 23974.8571 0 109 59665.4286 23974.8571 59.8% - 0s
H 0 0 58221.000000 23974.8571 58.8% - 0s
H 0 0 55868.857143 23974.8571 57.1% - 0s
0 0 23974.8571 0 107 55868.8571 23974.8571 57.1% - 0s
H 0 0 54881.428571 23974.8571 56.3% - 0s
0 0 23974.8571 0 112 54881.4286 23974.8571 56.3% - 0s
H 0 0 49235.428571 23974.8571 51.3% - 0s
0 0 23974.8571 0 107 49235.4286 23974.8571 51.3% - 0s
0 0 23974.8571 0 110 49235.4286 23974.8571 51.3% - 0s
H 0 0 48931.714286 23974.8571 51.0% - 0s
H 0 0 48856.857143 23974.8571 50.9% - 0s
H 0 0 48522.571429 23974.8571 50.6% - 1s
H 0 0 47162.571429 23974.8571 49.2% - 1s
0 0 23974.8571 0 109 47162.5714 23974.8571 49.2% - 1s
0 0 23974.8571 0 109 47162.5714 23974.8571 49.2% - 1s
H 0 0 46912.285714 23974.8571 48.9% - 1s
0 2 23974.8571 0 109 46912.2857 23974.8571 48.9% - 1s
H 35 39 46852.285714 23974.8571 48.8% 32.2 1s
H 63 79 46758.857143 23974.8571 48.7% 20.8 1s
H 78 79 46570.285714 23974.8571 48.5% 17.8 1s
H 111 114 46169.857143 23974.8571 48.1% 14.6 1s
H 113 114 44275.285714 23974.8571 45.9% 14.7 1s
H 144 144 44246.428571 23974.8571 45.8% 14.6 2s
H 750 715 44151.428571 23974.8571 45.7% 12.8 2s
H 965 921 43984.285714 23974.8571 45.5% 13.2 2s
H 971 921 43841.428571 23974.8571 45.3% 13.2 2s
H 1025 966 43503.857143 23974.8571 44.9% 13.2 3s
H 1029 919 43473.857143 23974.8571 44.9% 13.2 3s
H 1031 875 43472.142857 23974.8571 44.9% 13.1 4s
H 1032 831 43443.857143 23974.8571 44.8% 13.1 4s
H 1033 790 43423.857143 23974.8571 44.8% 13.1 4s
H 1034 752 43418.000000 23974.8571 44.8% 13.1 4s
H 1034 714 43417.995621 23974.8571 44.8% 13.1 4s
H 1035 678 43371.428571 23974.8571 44.7% 13.1 4s
H 1035 644 43332.285714 23974.8571 44.7% 13.1 4s
1036 645 27376.5616 35 117 43332.2857 23974.8571 44.7% 13.1 5s
H 1038 613 43331.428571 23974.8571 44.7% 13.1 5s
H 1041 584 43298.428571 23974.8571 44.6% 13.0 5s
H 1042 556 43009.571429 23974.8571 44.3% 13.0 5s
H 1046 533 42400.714286 23974.8571 43.5% 23.9 6s
H 1076 523 42364.428571 23974.8571 43.4% 24.3 6s
H 1078 496 42080.285714 23974.8571 43.0% 24.3 6s
H 1108 500 41820.285714 23974.8571 42.7% 23.8 7s
H 1123 478 41780.285714 23974.8571 42.6% 23.6 7s
H 1124 456 41772.571429 23974.8571 42.6% 23.6 7s
H 1126 434 41746.571429 23974.8571 42.6% 23.6 7s
H 1127 415 41064.571429 23974.8571 41.6% 23.6 7s
H 1148 426 40855.000000 23974.8571 41.3% 23.3 8s
H 2981 1411 40746.285714 23974.8571 41.2% 16.6 10s
H 2982 1400 40515.000000 23974.8571 40.8% 16.6 10s
H 3761 1907 40500.000000 23974.8571 40.8% 15.8 11s
H 3804 1901 40416.714286 23974.8571 40.7% 15.7 11s
H 5069 2765 40384.285714 23974.8571 40.6% 14.7 11s
H 6173 3568 40354.285714 23974.8571 40.6% 14.1 12s
H 7792 4496 40334.285714 23974.8571 40.6% 13.1 12s
H 8234 4771 40154.000000 23974.8571 40.3% 13.0 13s
H 8236 4768 40087.142857 23974.8571 40.2% 13.0 13s
11976 7382 26876.7143 40 106 40087.1429 24002.7143 40.1% 12.1 15s
H13413 7831 39790.714286 24003.2289 39.7% 11.8 16s
H13417 7825 39635.571429 24003.2289 39.4% 11.8 16s
H14438 8414 39366.142857 24025.7143 39.0% 11.7 19s
H14439 8409 39302.570751 24025.7143 38.9% 11.7 19s
H14440 8408 39287.000000 24025.7143 38.8% 11.7 19s
H14443 8400 39144.428571 24025.7143 38.6% 11.7 19s
14446 9921 25526.1325 32 105 39144.4286 24025.7143 38.6% 11.7 23s
H15437 9919 39124.428571 24025.7143 38.6% 11.6 23s
18663 12006 28360.0035 62 103 39124.4286 24067.8571 38.5% 11.4 25s
H23064 13164 39069.714286 24124.8686 38.3% 11.2 27s
As one can see, after 27s, the obtained gap is 38% for the explicit linearization model, whereas this was 27% after only 17s for the model without explicit linearization.
Question: What could be the reason for this? Is it because Gurobi uses some more efficient tricks to linearize products than the ones that I applied?
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi Rutger,
What could be the reason for this? Is it because Gurobi uses some more efficient tricks to linearize products than the ones that I applied?
Yes, the reason is that Gurobi is able to use different reformulation techniques without the linearization. The parameter PreQLinearize controls the reformulation technique. When you linearize the bilinear terms by hand, you take away the possibility of applying a possibly more efficient reformulation technique.
Best regards,
Jaromił0 -
Hello Jaromił, thank you for confirming this. In that case I will just stick with using the \(*\) operator for multiplications.
0
Post is closed for comments.
Comments
3 comments