MILP takes way too much time
AnsweredHi, I currently want to solve a MILP to model a heating system that is heating up a domestic hot water storage, every time when it falls to the lower bound. Unfortunatley it takes way too much time. Any suggestions what could be the reason for that ? / How to improve the modell
Here is my code:
import gurobipy as gp
from gurobipy import *
start = 0
ende = 1000
Periode = list(range(start, ende))
Anzahl_WP = list(range(0, 88))
M = 100000
Aufheizfaktor_DHW = 2
loss_DHW = 0.03
m = gp.Model("mip1")
m.modelSense = GRB.MINIMIZE
WP_Betrieb_DHW = m.addVars(Periode, vtype=GRB.BINARY, name="WP_Betrieb_DHW")
WP_Anfahrtvorgang_DHW = m.addVars(
Periode, vtype=GRB.BINARY, name="WP_Anfahrtvorgang_DHW "
)
DHW_Speichertemperatur = m.addVars(
Periode, lb=43.0, ub=53.0, vtype=GRB.CONTINUOUS, name="DHW_Speichertemperatur"
)
Wärmemenge_DHW = m.addVars(Periode, lb=0, vtype=GRB.CONTINUOUS, name="Wärmemenge_DHW")
Stromverbrauch = m.addVars(Periode, lb=0, vtype=GRB.CONTINUOUS, name="Stromverbrauch")
m.setObjective(sum(WP_Anfahrtvorgang_DHW[i] for i in Periode))
m.addConstrs((WP_Betrieb_DHW[i] * 0.4 <= Stromverbrauch[i] for i in Periode))
m.addConstrs((WP_Betrieb_DHW[i] * 4.0 >= Stromverbrauch[i] for i in Periode))
m.addConstrs((Wärmemenge_DHW[i] == (Stromverbrauch[i] * 3) for i in Periode))
m.addConstrs(
(
WP_Anfahrtvorgang_DHW[i] >= (WP_Betrieb_DHW[i] - WP_Betrieb_DHW[(i - 1)])
for i in range(start + 1, ende)
)
)
m.addConstrs(
(
DHW_Speichertemperatur[i]
== (
(DHW_Speichertemperatur[i - 1] * (1 - loss_DHW))
+ (Aufheizfaktor_DHW * Wärmemenge_DHW[i])
)
for i in range(start + 1, ende)
)
)
# m.params.Presolve = 2
# m.params.Prepasses = 5
# m.params.MIPFocus=1
# m.params.MIPGap = 0.05
# m.setParam("TimeLimit", timeLimit)
m.optimize()
Set parameter Username
Academic license - for non-commercial use only - expires 2023-06-03
Set parameter PrePasses to value 5
Gurobi Optimizer version 9.5.1 build v9.5.1rc2 (win64)
Thread count: 2 physical cores, 4 logical processors, using up to 4 threads
Optimize a model with 4998 rows, 5000 columns and 11994 nonzeros
Model fingerprint: 0x1ac88ac6
Variable types: 3000 continuous, 2000 integer (2000 binary)
Coefficient statistics:
Matrix range [4e-01, 4e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 5e+01]
RHS range [0e+00, 0e+00]
Presolve removed 2002 rows and 2003 columns
Presolve time: 0.02s
Presolved: 2996 rows, 2997 columns, 8988 nonzeros
Variable types: 1000 continuous, 1997 integer (1997 binary)
Found heuristic solution: objective 67.0000000
Found heuristic solution: objective 66.0000000
Root relaxation: objective 0.000000e+00, 1049 iterations, 0.00 seconds (0.00 work units)
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 0.00000 0 989 66.00000 0.00000 100% - 0s
0 0 0.00000 0 989 66.00000 0.00000 100% - 0s
0 0 0.09829 0 992 66.00000 0.09829 100% - 0s
0 0 0.11395 0 996 66.00000 0.11395 100% - 1s
0 0 0.11395 0 996 66.00000 0.11395 100% - 1s
0 0 0.52221 0 990 66.00000 0.52221 99.2% - 1s
0 0 0.57649 0 1005 66.00000 0.57649 99.1% - 1s
0 0 0.57649 0 1006 66.00000 0.57649 99.1% - 1s
0 0 1.12627 0 999 66.00000 1.12627 98.3% - 1s
0 0 1.13816 0 1002 66.00000 1.13816 98.3% - 1s
0 0 1.13930 0 1004 66.00000 1.13930 98.3% - 1s
0 0 1.13952 0 1004 66.00000 1.13952 98.3% - 1s
0 0 1.20210 0 1008 66.00000 1.20210 98.2% - 1s
0 0 1.20212 0 1008 66.00000 1.20212 98.2% - 1s
0 0 1.20318 0 1009 66.00000 1.20318 98.2% - 2s
0 0 1.20332 0 1009 66.00000 1.20332 98.2% - 2s
0 0 1.20405 0 1007 66.00000 1.20405 98.2% - 2s
0 0 1.20405 0 1007 66.00000 1.20405 98.2% - 2s
0 0 1.45746 0 1001 66.00000 1.45746 97.8% - 2s
0 0 1.45746 0 1001 66.00000 1.45746 97.8% - 2s
0 0 1.45746 0 992 66.00000 1.45746 97.8% - 2s
0 2 1.63952 0 991 66.00000 1.63952 97.5% - 4s
104 110 7.00000 37 957 66.00000 1.63952 97.5% 68.3 5s
763 733 26.00000 158 978 66.00000 5.83764 91.2% 25.9 10s
820 771 17.06228 86 987 66.00000 13.77194 79.1% 24.1 15s
-
I need this too, i want to solve 25 nodes with 4 vehicle VRP TW problem. I have been running for like 2 hours and still no solution. I need helppp...
1 -
The main issue in the first model is that the LP relaxation is pretty bad. The solution with objective value 66 cannot be improved upon also after running the solver for half an hour. It may just be the optimal solution that still needs to be proven by pushing up the dual bound.
You may find these recent TechTalks interesting:
Unfortunately, there is likely no simple answer to "how to speed up my MIP".
Best regards,
Matthias0
Please sign in to leave a comment.
Comments
2 comments