-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuBOS_EnergyInfo_application.py
422 lines (343 loc) · 14.6 KB
/
RuBOS_EnergyInfo_application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/usr/bin/env python
# -*-coding:utf-8 -*-
'''
__author__ : Lukas Theisinger
__version__ : 1.0
__maintainer__ : Michael Frank
__contact__ : [email protected]
'''
import os
from pyomo.environ import *
from RuBOS.optimization.ControlLogic_validation import *
from RuBOS.utilities.utilities import *
current_dir=os.getcwd()
scen = "summer"
type = "sequencing"
indexing_dict = {
'T': None,
'c_el': 'T',
'P_th_heat': 'T',
'P_th_cool': 'T',
'T_amb': 'T',
'T_amb_avg': 'T',
'T_flow_heat': 'T',
'T_flow_cool': 'T'
}
model_data = prepare_timeseries(os.path.join(current_dir, "MDPI_data_Industry_" + scen + ".xlsx"), indexing_dict=indexing_dict)
thres = {
1: 290,
2: 275
}
# 'b': [44, 22, 33, 11]
# 'g': [33, 44, 22, 11]
# 'r': [33, 22, 11, 44]
# 'c': [44, 33, 22, 11]
# rules = {
# 1: [44, 22, 33, 11], # b
# 2: [33, 44, 22, 11], # g
# 3: [44, 33, 22, 11], # None
# 4: [33, 22, 11, 44], # r
# 5: [44, 33, 22, 11], # None
# 6: [44, 33, 22, 11], # None
# 7: [44, 33, 22, 11], # None
# 8: [33, 22, 11, 44], # r
# 9: [44, 22, 33, 11], # b
# 10: [44, 33, 22, 11], # c
# 11: [44, 33, 22, 11], # None
# 12: [44, 33, 22, 11], # c
# 13: [44, 33, 22, 11], # None
# 14: [44, 33, 22, 11], # None
# 15: [44, 33, 22, 11], # None
# 16: [33, 22, 11, 44] # r
# }
rules = {
1: [44, 22, 33, 11], # r
2: [44, 33, 22, 11], # g
3: [44, 33, 22, 11], # None
4: [33, 22, 11, 44], # None
}
cl_data = controlLogic_validation(thres, rules, 2, 4, model_data[None]['T'][None])
#cl_data = controlLogic_data_c1_optimization(4, model_data[None]['T'][None])
"""
data: P_th_heat, P_th_cool, T_amb, T_amb_avg, T_flow_heat, T_flow_cool, c_el
"""
model = AbstractModel()
### indices ###
model.T = Set(domain = NonNegativeIntegers, doc = "time step index T")
model.C = Set(doc = "converter index C")
### variables ###
model.P_el_hp1 = Var(model.T, bounds = (0, 375))
model.P_el_hp2 = Var(model.T, bounds = (0, 250))
model.P_el_hp3 = Var(model.T, bounds = (0, 125))
model.P_th_heat_hp1 = Var(model.T, within = NonNegativeReals)
model.P_th_heat_hp2 = Var(model.T, within = NonNegativeReals)
model.P_th_heat_hp3 = Var(model.T, within = NonNegativeReals)
model.P_th_cool_hp1 = Var(model.T, within = NonNegativeReals)
model.P_th_cool_hp2 = Var(model.T, within = NonNegativeReals)
model.P_th_cool_hp3 = Var(model.T, within = NonNegativeReals)
model.bOn_hp1 = Var(model.T, within = Binary)
model.bOn_hp2 = Var(model.T, within = Binary)
model.bOn_hp3 = Var(model.T, within = Binary)
model.bSwitchOn_hp1 = Var(model.T, within = Binary)
model.bSwitchOn_hp2 = Var(model.T, within = Binary)
model.bSwitchOn_hp3 = Var(model.T, within = Binary)
model.P_gas_chp1 = Var(model.T, bounds = (0, 6000))
model.P_el_chp1 = Var(model.T, within = NonNegativeReals)
model.P_th_heat_chp1 = Var(model.T, within = NonNegativeReals)
model.bOn_chp1 = Var(model.T, within = Binary)
model.bSwitchOn_chp1 = Var(model.T, within = Binary)
# model.P_gas_chp2 = Var(model.T, bounds = (0, 3000))
# model.P_el_chp2 = Var(model.T, within = NonNegativeReals)
# model.P_th_heat_chp2 = Var(model.T, within = NonNegativeReals)
# model.bOn_chp2 = Var(model.T, within = Binary)
# model.bSwitchOn_chp2 = Var(model.T, within = Binary)
model.P_el_ct = Var(model.T, bounds = (0, 10000))
model.P_th_cool_ct = Var(model.T, within = NonNegativeReals)
model.E_th_heat = Var(model.T, bounds = (0, 800))
model.E_th_cool = Var(model.T, bounds = (0, 800))
### parameters ###
model.corr_fac_hp = 0.5
model.rel_min_hp = 0.5
model.switch_loss_hp = 0.2
model.eta_th_chp = 0.5
model.eta_el_chp = 0.4
model.rel_min_chp = 0.5
model.switch_loss_chp = 0.2
model.T_amb = Param(model.T)
model.T_amb_avg = Param(model.T)
model.T_flow_heat = Param(model.T) # Kelvin
model.T_flow_cool = Param(model.T) # Kelvin
model.c_el = Param(model.T)
model.c_gas = 0.08 # €/kWh
model.P_th_heat = Param(model.T)
model.P_th_cool = Param(model.T)
model.E_th_heat_target = 800
model.E_th_cool_target = 800
model.dT = 1
model.controlLogic = ControlLogic.create_instance(cl_data)
def heat_balance1(m, T):
if T == m.T.first():
return m.E_th_heat[T] == m.E_th_heat_target + m.P_th_heat_hp1[T] + m.P_th_heat_hp2[T] + m.P_th_heat_hp3[T] + m.P_th_heat_chp1[T] - m.P_th_heat[T]
else:
return Constraint.Skip
model.heat_bal1_cons = Constraint(model.T, rule = heat_balance1)
def heat_balance2(m, T):
if not T == m.T.first():
return m.E_th_heat[T] - m.E_th_heat[T - 1] == m.P_th_heat_hp1[T] + m.P_th_heat_hp2[T] + m.P_th_heat_hp3[T] + m.P_th_heat_chp1[T] - m.P_th_heat[T]
else:
return Constraint.Skip
model.heat_bal2_cons = Constraint(model.T, rule = heat_balance2)
def cool_balance1(m, T):
if T == m.T.first():
return m.E_th_cool[T] == m.E_th_cool_target + m.P_th_cool_hp1[T] + m.P_th_cool_hp2[T] + m.P_th_cool_hp3[T] + m.P_th_cool_ct[T] - m.P_th_cool[T]
else:
return Constraint.Skip
model.cool_bal1_cons = Constraint(model.T, rule = cool_balance1)
def cool_balance2(m, T):
if not T == m.T.first():
return m.E_th_cool[T] - m.E_th_cool[T] == m.P_th_cool_hp1[T] + m.P_th_cool_hp2[T] + m.P_th_cool_hp3[T] + m.P_th_cool_ct[T] - m.P_th_cool[T]
else:
return Constraint.Skip
model.cool_bal2_cons = Constraint(model.T, rule = cool_balance2)
def hp1_balance1(m, T):
return m.P_th_cool_hp1[T] + m.P_el_hp1[T] == m.P_th_heat_hp1[T]
model.hp1_bal_cons1 = Constraint(model.T, rule = hp1_balance1)
def hp1_balance2(m, T):
return ((m.T_flow_heat[T] * m.corr_fac_hp)/(m.T_flow_heat[T] - m.T_flow_cool[T])) * m.P_el_hp1[T] - m.bSwitchOn_hp1[T] * m.switch_loss_hp * 375 == m.P_th_heat_hp1[T]
model.hp1_balance2 = Constraint(model.T, rule = hp1_balance2)
def hp1_balance3(m, T):
return m.bOn_hp1[T] * 375 >= m.P_el_hp1[T]
model.hp1_bal_cons3 = Constraint(model.T, rule = hp1_balance3)
def hp1_balance4(m, T):
return m.P_el_hp1[T] >= m.bOn_hp1[T] * m.rel_min_hp * 375
model.hp1_bal_cons4 = Constraint(model.T, rule = hp1_balance4)
def hp1_balance5(m, T):
if not T == m.T.first():
return m.bSwitchOn_hp1[T] >= m.bOn_hp1[T] - m.bOn_hp1[T-1]
else:
return Constraint.Skip
model.hp1_bal_cons5 = Constraint(model.T, rule = hp1_balance5)
def hp1_balance6(m, T):
if not T == m.T.first():
return m.bSwitchOn_hp1[T] + m.bSwitchOn_hp1[T - 1] <= 1
else:
return Constraint.Skip
model.hp1_bal_cons6 = Constraint(model.T, rule = hp1_balance6)
def hp2_balance1(m, T):
return m.P_th_cool_hp2[T] + m.P_el_hp2[T] == m.P_th_heat_hp2[T]
model.hp2_bal_cons1 = Constraint(model.T, rule = hp2_balance1)
def hp2_balance2(m, T):
return ((m.T_flow_heat[T] * m.corr_fac_hp)/(m.T_flow_heat[T] - m.T_flow_cool[T])) * m.P_el_hp2[T] - m.bSwitchOn_hp2[T] * m.switch_loss_hp * 250 == m.P_th_heat_hp2[T]
model.hp2_balance2 = Constraint(model.T, rule = hp2_balance2)
def hp2_balance3(m, T):
return m.bOn_hp2[T] * 250 >= m.P_el_hp2[T]
model.hp2_bal_cons3 = Constraint(model.T, rule = hp2_balance3)
def hp2_balance4(m, T):
return m.P_el_hp2[T] >= m.bOn_hp2[T] * m.rel_min_hp * 250
model.hp2_bal_cons4 = Constraint(model.T, rule = hp2_balance4)
def hp2_balance5(m, T):
if not T == m.T.first():
return m.bSwitchOn_hp2[T] >= m.bOn_hp2[T] - m.bOn_hp2[T-1]
else:
return Constraint.Skip
model.hp2_bal_cons5 = Constraint(model.T, rule = hp2_balance5)
def hp2_balance6(m, T):
if not T == m.T.first():
return m.bSwitchOn_hp2[T] + m.bSwitchOn_hp2[T - 1] <= 1
else:
return Constraint.Skip
model.hp2_bal_cons6 = Constraint(model.T, rule = hp2_balance6)
def hp3_balance1(m, T):
return m.P_th_cool_hp3[T] + m.P_el_hp3[T] == m.P_th_heat_hp3[T]
model.hp3_bal_cons1 = Constraint(model.T, rule = hp3_balance1)
def hp3_balance2(m, T):
return ((m.T_flow_heat[T] * m.corr_fac_hp)/(m.T_flow_heat[T] - m.T_flow_cool[T])) * m.P_el_hp3[T] - m.bSwitchOn_hp3[T] * m.switch_loss_hp * 125 == m.P_th_heat_hp3[T]
model.hp3_balance2 = Constraint(model.T, rule = hp3_balance2)
def hp3_balance3(m, T):
return m.bOn_hp3[T] * 125 >= m.P_el_hp3[T]
model.hp3_bal_cons3 = Constraint(model.T, rule = hp3_balance3)
def hp3_balance4(m, T):
return m.P_el_hp3[T] >= m.bOn_hp3[T] * m.rel_min_hp * 125
model.hp3_bal_cons4 = Constraint(model.T, rule = hp3_balance4)
def hp3_balance5(m, T):
if not T == m.T.first():
return m.bSwitchOn_hp3[T] >= m.bOn_hp3[T] - m.bOn_hp3[T-1]
else:
return Constraint.Skip
model.hp3_bal_cons5 = Constraint(model.T, rule = hp3_balance5)
def hp3_balance6(m, T):
if not T == m.T.first():
return m.bSwitchOn_hp3[T] + m.bSwitchOn_hp3[T - 1] <= 1
else:
return Constraint.Skip
model.hp3_bal_cons6 = Constraint(model.T, rule = hp3_balance6)
def chp1_balance1(m, T):
return m.P_gas_chp1[T] * m.eta_th_chp - m.bSwitchOn_chp1[T] * m.switch_loss_chp * 6000 == m.P_th_heat_chp1[T]
model.chp1_balance1 = Constraint(model.T, rule = chp1_balance1)
def chp1_balance2(m, T):
return m.P_gas_chp1[T] * m.eta_el_chp - m.bSwitchOn_chp1[T] * m.switch_loss_chp * 6000 == m.P_el_chp1[T]
model.chp1_balance2 = Constraint(model.T, rule = chp1_balance2)
def chp1_balance3(m, T):
return m.bOn_chp1[T] * 6000 >= m.P_gas_chp1[T]
model.chp1_balance3 = Constraint(model.T, rule = chp1_balance3)
def chp1_balance4(m, T):
return m.P_gas_chp1[T] >= m.bOn_chp1[T] * m.rel_min_chp * 6000
model.chp1_balance4 = Constraint(model.T, rule = chp1_balance4)
def chp1_balance5(m, T):
if not T == m.T.first():
return m.bSwitchOn_chp1[T] >= m.bOn_chp1[T] - m.bOn_chp1[T-1]
else:
return Constraint.Skip
model.chp1_balance5 = Constraint(model.T, rule = chp1_balance5)
def chp1_balance6(m, T):
if not T == m.T.first():
return m.bSwitchOn_chp1[T] + m.bSwitchOn_chp1[T - 1] <= 1
else:
return Constraint.Skip
model.chp1_balance6 = Constraint(model.T, rule = chp1_balance6)
# def chp2_balance1(m, T):
# return m.P_gas_chp2[T] * m.eta_th_chp - m.bSwitchOn_chp2[T] * m.switch_loss_chp * 3000 == m.P_th_heat_chp2[T]
# model.chp2_balance1 = Constraint(model.T, rule = chp2_balance1)
# def chp2_balance2(m, T):
# return m.P_gas_chp2[T] * m.eta_el_chp - m.bSwitchOn_chp2[T] * m.switch_loss_chp * 3000 == m.P_el_chp2[T]
# model.chp2_balance2 = Constraint(model.T, rule = chp2_balance2)
# def chp2_balance3(m, T):
# return m.bOn_chp2[T] * 3000 >= m.P_gas_chp2[T]
# model.chp2_balance3 = Constraint(model.T, rule = chp2_balance3)
# def chp2_balance4(m, T):
# return m.P_gas_chp2[T] >= m.bOn_chp2[T] * m.rel_min_chp * 3000
# model.chp2_balance4 = Constraint(model.T, rule = chp2_balance4)
# def chp2_balance5(m, T):
# if not T == m.T.first():
# return m.bSwitchOn_chp2[T] >= m.bOn_chp2[T] - m.bOn_chp2[T-1]
# else:
# return Constraint.Skip
# model.chp2_balance5 = Constraint(model.T, rule = chp2_balance5)
# def chp2_balance6(m, T):
# if not T == m.T.first():
# return m.bSwitchOn_chp2[T] + m.bSwitchOn_chp2[T - 1] <= 1
# else:
# return Constraint.Skip
# model.chp2_balance6 = Constraint(model.T, rule = chp2_balance6)
def ct_balance1(m, T):
return (50 - (45/40)*(m.T_amb[T] - 273.15)) * m.P_el_ct[T] == m.P_th_cool_ct[T]
model.ct_balance1 = Constraint(model.T, rule = ct_balance1)
def influence_factor_def1(m, T):
return m.controlLogic.fac[1, T] == m.T_amb[T]
model.infl_fac_def1 = Constraint(model.T, rule = influence_factor_def1)
def influence_factor_def2(m, T):
return m.controlLogic.fac[2, T] == m.T_amb[T]
model.infl_fac_def2 = Constraint(model.T, rule = influence_factor_def2)
# def influence_factor_def3(m, T):
# return m.controlLogic.fac[3, T] == m.T_amb[T]
# model.infl_fac_def3 = Constraint(model.T, rule = influence_factor_def3)
# def influence_factor_def4(m, T):
# return m.controlLogic.fac[4, T] == m.T_amb[T]
# model.infl_fac_def4 = Constraint(model.T, rule = influence_factor_def4)
def rel_load_def1(m, T):
return m.controlLogic.rel[11, T] == m.P_el_hp1[T] / 375
model.rel_load_def1 = Constraint(model.T, rule = rel_load_def1)
def rel_load_def2(m, T):
return m.controlLogic.rel[22, T] == m.P_el_hp2[T] / 250
model.rel_load_def2 = Constraint(model.T, rule = rel_load_def2)
def rel_load_def3(m, T):
return m.controlLogic.rel[33, T] == m.P_el_hp3[T] / 125
model.rel_load_def3 = Constraint(model.T, rule = rel_load_def3)
def rel_load_def4(m, T):
return m.controlLogic.rel[44, T] == m.P_gas_chp1[T] / 6000
model.rel_load_def4 = Constraint(model.T, rule = rel_load_def4)
# def rel_load_def5(m, T):
# return m.controlLogic.rel[55, T] == m.P_gas_chp2[T] / 3000
# model.rel_load_def5 = Constraint(model.T, rule = rel_load_def5
def obj(m):
return sum((m.P_el_hp1[t] + m.P_el_hp2[t] + m.P_el_hp3[t] + m.P_el_ct[t] - m.P_el_chp1[t])*m.c_el[t] + (m.P_gas_chp1[t])*m.c_gas for t in m.T)
model.obj_rule = Objective(rule = obj)
print('data loaded')
opt = SolverFactory('cplex')
instance = model.create_instance(model_data)
print('model set up')
opt.solve(instance, tee = True, options_string="mipgap=0.01")
var_list = [
'P_th_heat_hp1',
'P_th_heat_hp2',
'P_th_heat_hp3',
'P_th_cool_hp1',
'P_th_cool_hp2',
'P_th_cool_hp3',
'P_el_hp1',
'P_el_hp2',
'P_el_hp3',
'P_th_heat_chp1',
'P_el_chp1',
'P_gas_chp1',
'P_th_cool_ct',
'P_el_ct'
]
param_list = [
'T_amb',
'T_amb_avg',
'T_flow_heat',
'T_flow_cool',
'P_th_heat',
'P_th_cool',
'c_el'
]
res_df = pd.DataFrame()
for var in var_list:
temp_list = []
for key in getattr(instance, var)._data:
temp_list.append(getattr(instance, var)._data[key].value)
res_df[var] = temp_list
for param in param_list:
temp_list = []
for key in getattr(instance, param)._data:
temp_list.append(getattr(instance, param)._data[key])
res_df[param] = temp_list
for conv in [11, 22, 33, 44]:
temp_list = []
for timestep in getattr(instance, 'T')._ordered_values:
for key in getattr(instance.controlLogic, 'c1')._data:
if getattr(instance.controlLogic, 'c1')._data[key].value > 0.8 and key[0] == conv and key[2] == timestep:
temp_list.append(key[1])
res_df[str(conv)] = temp_list
res_df.to_excel(os.path.join(current_dir, "res_" + scen + "_" + type + ".xlsx"))