Gurobi dynamic probem
ユーザーの入力を待っています。Hello, I am trying to make this kind of problem without add the equality constraint into the problem. This is useful to don't have equality constraints in my problem, get the standard form in matrix shape and apply other algorithm. This would be a simplification.
def main_building():
"""Main function build
Function in which the problem is defined.
Initial conditions are stablished, boundings and return the problem defined"""
# Create a new model
m = gp.Model("building")
m.reset() # Reset the problem, keep options.
PelHP = [m.addVar(name = 'PelHP_%d'%t) for t in range(T)] #Eletric Power
PthFC = [m.addVar(name = 'PthFC_%d'%t) for t in range(T)] #Thermal power given by the fan coil
T_ST_BMS= [m.addVar(name = 'T_ST_BMS_%d'%t) for t in range(T)] #Storage temperature
T_build_BMS= [m.addVar(name = 'T_build_BMS_%d'%t) for t in range(T)] #Building temperature
T_ST_BMS_list = T_ST_BMS
T_build_BMS_list = T_build_BMS
for t in range (T-1):
print(T_ST_BMS_list[t])
T_ST_BMS_list[0]=T_ST0+273.15
T_build_BMS_list[0]=T_BMS0+273.15
for t in range (T-1):
T_ST_BMS_list[t+1]=((COP_HP*PelHP[t]-PthFC[t]/eta_FC)/C_ST)*dt+T_ST_BMS_list[t]
T_build_BMS_list[t+1]=((((T_build_ext[t]-T_build_BMS_list[t])/R_build)+15*PthFC[t])*dt/C_build)+T_build_BMS_list[t]
m.addConstr(T_build_BMS_list[t+1]<=T_build_BMS_max)
m.addConstr(-T_build_BMS_min >= -T_build_BMS_list[t+1])
m.addConstr(T_ST_BMS_list[t+1]<=273.15+60)
m.addConstr(-273.15+30 >= -T_ST_BMS_list[t+1] )
Objective_b=0
for t in range(T):
m.addConstr(PelHP[t]<=PelHP_max)
m.addConstr(PthFC[t]<=eta_FC*m_air*cp_air*(T_ST_BMS_list[t]-T_build_BMS_list[t]))
m.addConstr(0>=-PelHP[t])
m.addConstr(0>=-PthFC[t])
Objective_b=Objective_b+dt*(C_buy*(-(-PelHP[t]))+(T_build_BMS_list [t]-T_obj)**2+(T_ST_BMS_list[t]-T_obj_2)**2)
# Set objective:
m.setObjective(Objective_b, gp.GRB.MINIMIZE)
m.optimize()
print(PelHP)
print(PthFC)
print(T_ST_BMS_list)
print(T_build_BMS_list)
return m
Gurobi is able to solve it with 10 times in T. But when I increase it, gurobi blocks. Anyone that could help me? The point is that the expression of T_ST_BMS becomes higher with t.
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Hi Daniel,
The code snippet you provided is not reproducible. There are definitions missing of multiple objects, e.g., \(\texttt{C_buy, dt, ...}\).
If you cannot or don't want to share your model/code, could you please at least share the log files of a run with 10 times in T and a run with more times where Gurobi does not converge?
Best regards,
Jaromił0 -
They are not important, it can be run with several values. However, the issue is that for T<=15 it is able to solve it. However if I increase this, the problem is that it is not able to assimilate the number of variables, it crashes. There is no important message to display because it just crashes. The key is that the variable T_ST_BMS_list becomes a longer and longer expression that it is not able to handle, at least that's the feeling I get.
Thank you for your answer
0 -
It is hard to help without anything to reproduce the issue.
It might be that your machine runs out of memory because your model gets too big. Is this possible?
Could you show the statistics for a model that can be solved, i.e., show the first ~20 lines of the log file / console output?
0 -
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (win64)
Thread count: 2 physical cores, 4 logical processors, using up to 4 threads
Optimize a model with 76 rows, 40 columns and 400 nonzeros
Model fingerprint: 0xa0bc8b29
Model has 171 quadratic objective terms
Coefficient statistics:
Matrix range [1e-02, 3e+00]
Objective range [5e-02, 4e+01]
QObjective range [1e-01, 2e+01]
Bounds range [0e+00, 0e+00]
RHS range [5e-01, 8e+01]
Presolve removed 52 rows and 22 columns
Presolve time: 0.02s
Presolved: 24 rows, 25 columns, 234 nonzeros
Presolved model has 171 quadratic objective terms
Ordering time: 0.00s
Barrier statistics:
Free vars : 17
AA' NZ : 8.200e+02
Factor NZ : 8.610e+02
Factor Ops : 2.382e+04 (less than 1 second per iteration)
Threads : 1
Objective Residual
Iter Primal Dual Primal Dual Compl Time
0 4.52999965e+05 -3.56159762e+05 1.96e+03 5.85e+02 1.00e+06 0s
1 9.56162030e+04 -1.59207143e+05 3.57e+02 1.07e+02 1.91e+05 0s
2 1.77304735e+04 -1.17545166e+05 1.16e+01 2.55e+00 6.92e+03 0s
3 1.28050736e+02 -7.26144742e+04 8.55e-06 2.55e-06 1.23e+03 0s
4 1.18687411e+02 -7.13284325e+03 8.34e-07 2.49e-07 1.23e+02 0s
5 3.64250867e+01 -1.16016288e+03 8.34e-13 2.89e-13 2.03e+01 0s
6 1.25892198e+01 -4.86305732e+01 5.73e-14 1.72e-13 1.04e+00 0s
7 8.54939679e+00 3.36948617e+00 1.91e-14 1.41e-13 8.78e-02 0s
8 7.01563133e+00 5.98596671e+00 9.99e-16 2.35e-14 1.75e-02 0s
9 6.77770116e+00 6.70701827e+00 7.03e-16 2.02e-14 1.20e-03 0s
10 6.72505043e+00 6.71408466e+00 4.44e-16 2.42e-14 1.86e-04 0s
11 6.72173994e+00 6.72082450e+00 2.22e-16 4.63e-14 1.55e-05 0s
12 6.72147390e+00 6.72140848e+00 2.08e-16 3.95e-13 1.11e-06 0s
13 6.72145295e+00 6.72144928e+00 2.22e-16 3.41e-14 6.22e-08 0s
14 6.72145033e+00 6.72145011e+00 1.11e-16 3.58e-13 3.81e-09 0s
Barrier solved model in 14 iterations and 0.04 seconds (0.00 work units)
Optimal objective 6.72145033e+00These are the statics I get. Thats the problem the big number of quadratic terms. But, for example, I tried this in matlab and it is able to solve it, there is no other way to express a recurrent equation?
This is just with 10 times by the way
0 -
The model is definitely manageable and memory should not be an issue at all.
Could you show some output or share a screenshot of what exactly goes wrong when you now increase the number of times to let's say 16?
You said "It just crashes". However, it is almost impossible to help here without seeing any output or without have a code snippet which reproduces the issue. Could you try to isolate the issue and write a minimal working example which results in the crash you see?
0
投稿コメントは受け付けていません。
コメント
6件のコメント