-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_da_bids.py
executable file
·656 lines (464 loc) · 23.8 KB
/
get_da_bids.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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
#!/usr/bin/env python
# coding: utf-8
import numpy as np
import pandas as pd
from utility import utility as util
from utility import utils as utils
import yaml
#from tqdm.notebook import tqdm_notebook
import copy
import math
import os
import numpy.random as rand
from tqdm import tqdm
import matplotlib.pyplot as plt
import pandas as pd
import deterministic_solver_ev_penetration_no_solar
import generate_expected_EV_values as E_ev_generator
import ev_data_sampler
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-P", "--perc", help = "percentage of vehicles that participate in v2g", type=int, required=True)
parser.add_argument("-N", "--num_samples", help = "Number of Montecarlo simulations", type= int, required=False)
args = parser.parse_args()
perc_allow_EV_discharge = [args.perc]
if args.num_samples == None:
num_samples = 10
else:
num_samples = args.num_samples
# In[10]:
def create_ev_dict_from_df(df_ev, day): # day int: {0 - 364}
FINAL_SOC = 0.97
ALPHA_C = 11
B_CAP = 80
ETA_C = 0.98
df_ev_day = df_ev[df_ev["day_no"] == day]
# Init dict
ev_dict = {}
ev_outer_keys = ['init_soc','ev_stay_t','ev_laxity']
for key in ev_outer_keys:
ev_dict[key] = {}
for h in range(24):
ev_dict[key]["hour_{}".format(str(h))] = []
for hour in range(24):
df_ev_hour = df_ev_day[df_ev_day["start_hour"] == hour]
for _, row in df_ev_hour.iterrows():
stay_t = row.new_connected_time
init_soc = row.initial_soc
depart_time = hour + stay_t
if(depart_time > 23):
depart_time = 23
stay_t = depart_time - hour
laxity = stay_t - (FINAL_SOC - init_soc)*B_CAP/(ALPHA_C * ETA_C)
if(laxity >= 0):
ev_dict['ev_stay_t']['hour_{}'.format(hour)].append(stay_t)
ev_dict['init_soc']['hour_{}'.format(hour)].append(init_soc)
ev_dict['ev_laxity']['hour_{}'.format(hour)].append(laxity)
return ev_dict
def create_ev_dict(seed):
raise Exception("Using deprecated create de dict")
rng = np.random.default_rng(seed)
DAY_HRS = 24
FINAL_SOC = 0.97
ALPHA_C = 11
B_CAP = 80
ETA_C = 0.98
ev_dict = {}
ev_outer_keys = ['init_soc','ev_stay_t','ev_laxity']
for key in ev_outer_keys:
ev_dict[key] = {}
for key in ev_outer_keys:
for h in range(DAY_HRS):
ev_dict[key]['hour_{}'.format(str(h))] = []
for hour in range(DAY_HRS):
num_arrived_ev = ev_data_sampler.sample_num_EV_arrivals(rng, hour)
# print('in origg ', num_arrived_ev)
for _ in range(num_arrived_ev):
stay_t = ev_data_sampler.sample_ev_stay_time(rng, hour)
init_soc = ev_data_sampler.sample_init_soc(seed)
seed += 1
depart_time = hour + stay_t
if(depart_time > 23):
depart_time = 23
stay_t = depart_time - hour
laxity = stay_t - (FINAL_SOC - init_soc)*B_CAP/(ALPHA_C * ETA_C)
if(laxity >= 0):
ev_dict['ev_stay_t']['hour_{}'.format(hour)].append(stay_t)
ev_dict['init_soc']['hour_{}'.format(hour)].append(init_soc)
ev_dict['ev_laxity']['hour_{}'.format(hour)].append(laxity)
return ev_dict
# In[11]:
def create_forecast_ev_dict(seed, sample_no):
rng = np.random.default_rng(seed)
ev_rng = np.random.default_rng(seed+sample_no)
DAY_HRS = 24
FINAL_SOC = 0.97
ALPHA_C = 11
B_CAP = 80
ETA_C = 0.98
NOISE_STD = 0.1
ev_dict = {}
ev_outer_keys = ['init_soc','ev_stay_t','ev_laxity']
for key in ev_outer_keys:
ev_dict[key] = {}
for key in ev_outer_keys:
for h in range(DAY_HRS):
ev_dict[key]['hour_{}'.format(str(h))] = []
for hour in range(DAY_HRS):
num_arrived_ev = ev_data_sampler.sample_num_EV_arrivals(rng, hour)
num_arrived_ev_noise = ev_rng.normal(0, (num_arrived_ev*NOISE_STD))
num_arrived_ev += num_arrived_ev_noise
# if(num_arrived_ev_noise > 0):
# num_arrived_ev = np.ceil(num_arrived_ev)
# if(num_arrived_ev > 0.5 and num_arrived_ev <= 1):
# num_arrived_ev = 1
num_arrived_ev = int(num_arrived_ev)
if(num_arrived_ev <= 0):
num_arrived_ev = 0
for _ in range(num_arrived_ev):
stay_t = ev_data_sampler.sample_ev_stay_time(rng, hour)
stay_t_noise = ev_rng.normal(0, (stay_t*NOISE_STD))
stay_t += stay_t_noise
if(stay_t_noise > 0):
stay_t = np.ceil(stay_t)
stay_t = int(stay_t)
if(stay_t >= (DAY_HRS-1)):
stay_t = DAY_HRS-1
elif(stay_t < 0):
stay_t = 0
init_soc = ev_data_sampler.sample_init_soc(seed)
init_soc_noise = ev_rng.normal(0, (init_soc*NOISE_STD))
init_soc += init_soc_noise
seed += 1
depart_time = hour + stay_t
if(depart_time > 23):
depart_time = 23
stay_t = depart_time - hour
if(init_soc >= FINAL_SOC):
init_soc = FINAL_SOC
elif(init_soc < 0):
init_soc = 0
laxity = stay_t - (((FINAL_SOC - init_soc)*B_CAP)/(ALPHA_C * ETA_C))
if(laxity >= 0):
ev_dict['ev_stay_t']['hour_{}'.format(hour)].append(stay_t)
ev_dict['init_soc']['hour_{}'.format(hour)].append(init_soc)
ev_dict['ev_laxity']['hour_{}'.format(hour)].append(laxity)
return ev_dict
# In[12]:
class EV:
def __init__(self, arrival_time, stay_time, soc_init, laxity):
self.arrival_time = arrival_time
self.stay_time = stay_time
self.departure_time = self.arrival_time + self.stay_time
self.soc_final = 0.97
self.soc_init = soc_init
self.soc_t = soc_init
self.laxity = laxity
self.battery_cap = 80 #kW
self.alpha_c = 11 #kW
self.eta_c = 0.98
self.alpha_d = -11 #kW
self.eta_d = 0.98
self.allow_discharge = False
self.priority_charge = False
self.bool_c_d = False
self.completed = False
self.time_to_full_soc = 0
self.incentive_valuation = 0
self.actual_payback = 0
self.discharge_threshold = 1.25
# In[13]:
def get_connected_ev(ev_dict, hour):
just_arrived_ev_lst = []
if(len(ev_dict['init_soc']['hour_{}'.format(str(hour))]) != 0):
for ev_num in range(len(ev_dict['init_soc']['hour_{}'.format(str(hour))])):
just_arrived_ev_lst.append(EV(hour,
ev_dict['ev_stay_t']['hour_{}'.format(str(hour))][ev_num],
ev_dict['init_soc']['hour_{}'.format(str(hour))][ev_num],
ev_dict['ev_laxity']['hour_{}'.format(str(hour))][ev_num]
))
return just_arrived_ev_lst
else:
return [-1]
# In[14]:
def surplus_pv_gen(current_time, pv_diff, available_ev_lst, im_price_lst):
imbalance_sell = 0
e_extra = pv_diff
charge_e_dict = {}
for ev in available_ev_lst:
if(ev.bool_c_d == False and ev.soc_t < ev.soc_final):
charge_e_dict[ev] = ev.laxity
# sort based on ascending order of Laxity. Smaller lax => more urgent to charge!
if(len(charge_e_dict) != 0):
charge_e_dict = sorted(charge_e_dict.items(), key=lambda x: x[1], reverse=False)
for ev in charge_e_dict:
if(e_extra > 0):
e_charging = charge_EV(ev[0], e_extra)
e_extra -= e_charging
# if(im_price_lst[current_time] > 0):
# imbalance_sell += e_charging * im_price_lst[current_time]
# Sell remaining surplus energy to imbalance market after EV charging complete!
if(e_extra > 0 and im_price_lst[current_time] > 0):
imbalance_sell += e_extra * im_price_lst[current_time]
return imbalance_sell
# In[15]:
def charge_EV(ev, e_charging):
ETA_C = 0.98
e_required = (ev.soc_final - ev.soc_t) * ev.battery_cap
if(e_charging >= e_required):
e_charging = e_required
e_required = 0
if(e_charging >= ev.alpha_c):
e_charging = ev.alpha_c
ev.soc_t = ev.soc_t + (e_charging*ETA_C)/ev.battery_cap
ev.stay_time -= 1
ev.laxity = ev.stay_time - ((ev.soc_final - ev.soc_t) * ev.battery_cap)/(ev.alpha_c * ETA_C)
if(ev.laxity == 0):
ev.laxity = 0
ev.bool_c_d = True
return e_charging
# In[16]:
def shortage_pv_gen(current_time, pv_diff, available_ev_lst, da_price_lst, im_price_lst):
imbalance_buy = 0
DISCHRG_THRESH = 0
e_short = np.abs(pv_diff)
discharge_e_dict = {}
sum_disch_E = 0
#print("BEFOREEE DISCHRGG E-short ", e_short)
# Obtain the EVs that have POSITIVE LAXITY and ALLOW DISCHARGE
for ev in available_ev_lst:
if(ev.laxity > DISCHRG_THRESH and ev.allow_discharge == True and ev.bool_c_d == False):
# storing the EV obj address in the dict as "key" and the available discharge energy as the "item"
discharge_e_dict[ev] = get_available_discharge_energy(ev)
#print('discharge_e_dict ', discharge_e_dict)
if(len(discharge_e_dict) != 0):
# Descending sort
discharge_e_dict = sorted(discharge_e_dict.items(), key=lambda x: x[1], reverse=True)
for ev in discharge_e_dict:
sum_disch_E += ev[1]
e_short_orig = e_short
for ev in discharge_e_dict:
if (e_short > 0 and ev[1] != 0):
if(sum_disch_E > e_short):
e_discharged = discharge_EV(ev[0], (ev[1]/sum_disch_E)*e_short_orig, e_short)
#ev[0].dsch_revenue_contrib += e_discharged * im_price_lst[current_time]
else:
e_discharged = discharge_EV(ev[0], ev[1], e_short)
e_short -= e_discharged
#print('EEE_DISCCC ', e_discharged)
#revenue_from_ev_dischrg += e_discharged * im_price_lst[current_time]
#print('SSORRRTT ',e_short)
return e_short
def get_available_discharge_energy(ev):
e_required = (ev.soc_final - ev.soc_t) * ev.battery_cap
look_ahead_e_required = ev.alpha_c * ev.eta_c * (ev.stay_time - 1)
e_discharge = look_ahead_e_required - e_required
if(e_discharge < 0):
e_discharge = 0
elif(e_discharge >= np.abs(ev.alpha_d)):
e_discharge = np.abs(ev.alpha_d)
return e_discharge
# In[17]:
def discharge_EV(ev, e_discharge_available, e_short):
ETA_D = 0.98
if(e_discharge_available > np.abs(ev.alpha_d)):
e_discharge_available = np.abs(ev.alpha_d)
elif(e_discharge_available <= 0):
e_discharge_available = 0
# if(e_discharge_available != 0):
# if(e_short <= e_discharge_available):
# e_discharge_available = e_short
# e_short = 0
# else:
# e_short -= e_discharge_available
ev.soc_t = ev.soc_t - (e_discharge_available/ETA_D)/ev.battery_cap
ev.stay_time -= 1
ev.laxity = ev.stay_time - ((ev.soc_final - ev.soc_t) * ev.battery_cap)/(ev.alpha_c * ETA_C)
if(ev.laxity == 0):
ev.laxity = 0
ev.bool_c_d = True
return e_discharge_available
# In[18]:
def update_ev_dict_allowed_discharge_evs(seed, ev_dict, ratio):
rng = np.random.default_rng(seed)
total_evs = 0
for h in range(24):
total_evs += len(ev_dict['init_soc']['hour_{}'.format(str(h))])
ev_allowed_discharge = rng.choice(total_evs, size=round(total_evs*(ratio/100)), replace=False)
ev_dict['ev_allowed_discharge'] = ev_allowed_discharge
return ev_dict
# In[20]:
def get_online_alg_result_mc_simul(seed, day_no, current_date, unique_dates, sampling_unique_dates, orig_ev_dict, ratio_EV_discharge, pv_gen_df, price_df, sampling_pv_gen_df, sampling_price_df, num_samples):
all_bids_sample_paths = []
bids_sample_paths = []
DAY_HRS = 24
NOISE_STD = 0.1
FINAL_SOC = 0.97
B_CAP = 80
ALPHA_C = 11
ETA_C = 0.98
my_rng = np.random.default_rng(seed)
# actual realizations of the date
pv_gen_lst = np.array(list(pv_gen_df.loc[(pv_gen_df.index == current_date)]['PV_Vol']))
da_price_lst = np.array(list(price_df.loc[(price_df.index == current_date)]['price_da']))
im_price_lst = np.array(list(price_df.loc[(price_df.index == current_date)]['price_imbalance']))
# sampling the white gaussian noise to add
pv_forecast_noise = my_rng.normal(0, (pv_gen_lst*NOISE_STD), (num_samples,DAY_HRS))
da_price_forecast_noise = my_rng.normal(0, np.abs(da_price_lst)*NOISE_STD, (num_samples,DAY_HRS))
im_price_forecast_noise = my_rng.normal(0, np.abs(im_price_lst)*NOISE_STD, (num_samples,DAY_HRS))
for sample in (range(num_samples)):
forecast_ev_dict = create_forecast_ev_dict(seed, sample)
pv_gen_forecast = pv_gen_lst + pv_forecast_noise[sample]
da_price_forecast = da_price_lst + da_price_forecast_noise[sample]
im_price_forecast = im_price_lst + im_price_forecast_noise[sample]
for idx, p in enumerate(im_price_forecast):
if p < 0:
im_price_forecast[idx] = 0
for idx, p in enumerate(da_price_forecast):
if p < 0:
da_price_forecast[idx] = 0
_, bids, _ = deterministic_solver_ev_penetration_no_solar.main(seed, pv_gen_forecast, da_price_forecast, im_price_forecast, forecast_ev_dict, ratio_EV_discharge)
bids_sample_paths.append(bids)
# Javier: Change dirs
#if(len(os.listdir('bids_snowball_no_solar/{}_perc'.format(ratio_EV_discharge))) >= 1):
# all_bids_sample_paths = util.load_result(('bids_snowball_no_solar/{}_perc'.format(ratio_EV_discharge)+'/bid_sample_path_'+str(ratio_EV_discharge)+'_perc'))
if(len(os.listdir('results/bids_no_solar_2019_trial/{}_perc'.format(ratio_EV_discharge))) >= 1):
all_bids_sample_paths = util.load_result(('bids_no_solar_2019/{}_perc'.format(ratio_EV_discharge)+'/bid_sample_path_'+str(ratio_EV_discharge)+'_perc'))
all_bids_sample_paths.append(bids_sample_paths)
util.save_result('results/bids_no_solar_2019_trial/{}_perc'.format(ratio_EV_discharge)+'/bid_sample_path_'+str(ratio_EV_discharge)+'_perc', all_bids_sample_paths)
# # # +++++++++++++++++++++++++++ For each of the sample paths' bid, solving STAGE - 2 +++++++++++++++++++++++++++++++++++
# revenue_sample_paths = []
# im_buy_sample_paths = []
# im_sell_sample_paths = []
# time_to_soc_sample_paths = []
# for b in (bids_sample_paths):
# bids = b
# da_revenue_lst = np.zeros(DAY_HRS)
# imbalance_buy_lst = np.zeros(DAY_HRS)
# imbalance_sell_lst = np.zeros(DAY_HRS)
# revenue_lst = np.zeros(DAY_HRS)
# #_, bids = perform_monte_carlo_simul(seed, date, unique_dates, ratio_EV_discharge, pv_gen_df, price_df)
# ev_dict = update_ev_dict_allowed_discharge_evs(seed, orig_ev_dict, ratio_EV_discharge)
# available_ev_lst = []
# ev_history_lst = []
# avg_time_to_full_soc = []
# pv_gen_lst = np.array(list(pv_gen_df.loc[(pv_gen_df.index == current_date)]['PV_Vol']))
# da_price_lst = np.array(list(price_df.loc[(price_df.index == current_date)]['price_da']))
# im_price_lst = np.array(list(price_df.loc[(price_df.index == current_date)]['price_imbalance']))
# for current_time in range(DAY_HRS):
# revenue = 0
# da_revenue = 0
# im_buy_revenue = 0
# im_sell_revenue = 0
# # Get the EVs
# found_evs_lst = get_connected_ev(ev_dict, current_time)
# # Form available_ev_lst
# if(found_evs_lst[0] != -1):
# for found_ev in found_evs_lst:
# ev_history_lst.append(found_ev)
# if(ev_history_lst.index(found_ev) in ev_dict['ev_allowed_discharge']):
# found_ev.allow_discharge = True
# else:
# found_ev.allow_discharge = False
# available_ev_lst.append(found_ev)
# # Find EVs with Low laxity
# ac_lst = []
# for ev in available_ev_lst:
# ev.bool_c_d = False #Reset for all EVs on every hour
# if(current_time >= ev.departure_time or ev.stay_time == 0):
# ev.bool_c_d = True
# if(ev.bool_c_d == False and ev.completed == False and (math.floor(ev.laxity)) <= 0 and (ev.soc_t != ev.soc_final)):
# ac_lst.append(charge_EV(ev, ev.alpha_c))
# # Total charging demand
# x_t = np.array(bids[current_time]) + np.sum(np.array(ac_lst))
# bid_amt = np.array(bids[current_time])
# total_chrg_demand = np.sum(np.array(ac_lst))
# da_revenue += bid_amt * da_price_lst[current_time]
# # Get the surplus/deficit
# if(pv_gen_lst[current_time] >= x_t):
# # Surplus
# pv_diff = pv_gen_lst[current_time] - x_t
# im_sell_revenue += surplus_pv_gen(current_time, pv_diff, available_ev_lst, im_price_lst)
# elif (x_t > pv_gen_lst[current_time]):
# # Deficit
# pv_diff = pv_gen_lst[current_time] - x_t
# e_short = shortage_pv_gen(current_time, pv_diff, available_ev_lst, da_price_lst, im_price_lst)
# if(e_short > 0):
# im_buy_revenue += -1 * e_short * im_price_lst[current_time]
# e_short = 0
# revenue = da_revenue + im_sell_revenue + im_buy_revenue
# revenue_lst[current_time] = revenue
# da_revenue_lst[current_time] = da_revenue
# imbalance_buy_lst[current_time] = im_buy_revenue
# imbalance_sell_lst[current_time] = im_sell_revenue
# for ev in available_ev_lst:
# if(ev.bool_c_d == False):
# # For EVs not charged or discharged, ONLY Laxity update
# e_required = (ev.soc_final - ev.soc_t) * ev.battery_cap
# ev.stay_time -= 1
# ev.laxity = ev.stay_time - (e_required/(ev.alpha_c * ev.eta_c))
# for ev in available_ev_lst:
# if(current_time == ev.departure_time or ev.stay_time == 0):
# if(ev.completed == False):
# avg_time_to_full_soc.append(1+(current_time - ev.arrival_time))
# ev.completed = True
# ev.bool_c_d = True
# revenue_sample_paths.append(np.sum(revenue_lst))
# im_buy_sample_paths.append(np.sum(imbalance_buy_lst))
# im_sell_sample_paths.append(np.sum(imbalance_sell_lst))
# time_to_soc_sample_paths.append(np.mean(avg_time_to_full_soc,axis=0))
return 1, 1, 1, 1
#return np.average(revenue_sample_paths), np.average(im_buy_sample_paths), np.average(im_sell_sample_paths), np.average(time_to_soc_sample_paths)
# In[ ]:
sampling_pv_gen_df = pd.read_csv('data/sampling_pv_data.csv', index_col='Date') # Not used
sampling_pv_gen_df.index = pd.to_datetime(sampling_pv_gen_df.index)
# Javier chages to 2019
pv_gen_test_df = pd.read_csv('data/real_data/2019_test_data_pv.csv', index_col='Date')
pv_gen_test_df.index = pd.to_datetime(pv_gen_test_df.index)
sampling_price_df = pd.read_csv('data/sampling_price_data.csv', index_col='Date') # Not used
sampling_price_df.index = pd.to_datetime(sampling_price_df.index)
# Javier changes to 2019
price_test_df = pd.read_csv('data/real_data/2019_test_data_price.csv', index_col='Date')
price_test_df.index = pd.to_datetime(price_test_df.index)
# Javier df_ev
df_ev = pd.read_csv("data/real_data/df_elaad_preproc.csv", parse_dates = ["starttime_parking", "endtime_parking"])
unique_dates = pv_gen_test_df.index.unique()
sampling_unique_dates = sampling_pv_gen_df.index.unique()
baseline_revenue_dict = {}
online_algo_revenue_dict = {}
seed_lst = [777]
#perc_allow_EV_discharge = [100] # Was 75 before. Does it affect?
for perc in (perc_allow_EV_discharge):
baseline_revenue_dict = {}
online_algo_revenue_dict = {}
for run, seed in enumerate(seed_lst):
baseline_revenue_lst = []
total_revenue_lst_E_stage_1 = []
im_buy_revenue_lst_E_stage_1 = []
im_sell_revenue_lst_E_stage_1 = []
time_to_full_soc_lst_E_stage_1 = []
total_revenue_lst_R_stage_1 = []
im_buy_revenue_lst_R_stage_1 = []
im_sell_revenue_lst_R_stage_1 = []
time_to_full_soc_lst_R_stage_1 = []
#_, bids = perform_monte_carlo_simul(seed, unique_dates, perc, pv_gen_test_df, price_test_df)
for day_no, date in enumerate(tqdm(unique_dates, total=len(unique_dates))):
current_pv_gen_lst = np.array(list(pv_gen_test_df.loc[(pv_gen_test_df.index == date)]['PV_Vol']))
current_da_price_lst = np.array(list(price_test_df.loc[(price_test_df.index == date)]['price_da']))
current_im_price_lst = (np.array(list(price_test_df.loc[(price_test_df.index == date)]['price_imbalance'])))
#ev_dict = create_ev_dict(seed+run)
ev_dict = create_ev_dict_from_df(df_ev, day_no)
# Using Monte Carlo simulation results
total, im_buy, im_sell, time_to_full_soc = get_online_alg_result_mc_simul(seed+run, day_no, date, unique_dates, sampling_unique_dates, ev_dict, perc, pv_gen_test_df, price_test_df, sampling_pv_gen_df, sampling_price_df, num_samples)
total_revenue_lst_E_stage_1.append(total)
im_buy_revenue_lst_E_stage_1.append(im_buy)
im_sell_revenue_lst_E_stage_1.append(im_sell)
time_to_full_soc_lst_E_stage_1.append(time_to_full_soc)
seed += 10000
baseline_revenue_dict[str(perc)+'_run'+str(run)] = baseline_revenue_lst
online_algo_revenue_dict['total_revenue_'+str(perc)+'_run'+str(run)+'_E'] = total_revenue_lst_E_stage_1
online_algo_revenue_dict['im_buy_'+str(perc)+'_run'+str(run)+'_E'] = im_buy_revenue_lst_E_stage_1
online_algo_revenue_dict['im_sell_'+str(perc)+'_run'+str(run)+'_E'] = im_sell_revenue_lst_E_stage_1
online_algo_revenue_dict['time_to_full_soc_'+str(perc)+'_run'+str(run)+'_E'] = time_to_full_soc_lst_E_stage_1
#util.save_result('w_mc_results/baseline_revenue_'+str(perc),baseline_revenue_dict)
#util.save_result('w_mc_results/1K/expected_online_algo_revenue_original_'+str(perc),online_algo_revenue_dict)