-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (61 loc) · 3.27 KB
/
main.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
import os
# get the current working directory
# ensure that the active directory is the current working directory
dir_file = os.getcwd()
os.chdir(dir_file)
import numpy as np
from time import time
import pdb
import pandas as pd
'''
The model can be run independently from the terminal. Use this main file if you want to loop through multiple test
cases.
'''
test_case_loop = False
def planning_simulation():
# for now please modify this to manage the arguments to be sent to the solver or the pyomo model
os.system("runef -m grid_investment.py --traceback --output-solver-log --solver=gurobi --solve "
"--solution-writer=utils\csvsolutionwriter")
pass
if __name__ == "__main__":
risk_preference = [0, 0.5, 0.95]
operator_budget_count = [0.5, 1, 2, 3]
DG_counts = [0, 1, 5, 10]
line_hardening_counts = [0, 1, 5, 10]
line_capacity_upgrade_counts = [0, 1, 5, 10]
iter_counter = 0
execution_time_record = {}
for risk in risk_preference:
np.savetxt("results/iterator/risk_num.txt", [risk], delimiter=',', fmt='%.2f')
for budget in operator_budget_count:
np.savetxt("results/iterator/budget_num.txt", [budget], delimiter=',', fmt='%.2f')
for DG_num in DG_counts:
np.savetxt("results/iterator/DG_num.txt", [DG_num], delimiter=',', fmt='%i')
for harden_num in line_hardening_counts:
np.savetxt("results/iterator/harden_num.txt", [harden_num], delimiter=',', fmt='%i')
for linecap_num in line_capacity_upgrade_counts:
np.savetxt("results/iterator/linecap_num.txt", [linecap_num], delimiter=',', fmt='%i')
# this condition avoids 0 resource case except for one fully risk-neutral (expected) case
# and one fully risk-averse case
if (DG_num == 0 and harden_num == 0 and linecap_num == 0) and (budget > 0.5 or
(0 < risk < 0.95)):
continue
# print the current iteration to observe the status
print ('############################ CURRENT SIMULATION ###################################')
print(f'risk:{risk} \t '
f'budget:{budget} \t '
f'DG:{DG_num} \t '
f'harden:{harden_num} \t '
f'cap:{linecap_num}')
print('############################ CURRENT SIMULATION ###################################')
# start timer
start_time = time()
# RUN THE PLANNING SIMULATION FOR ALL OF THE CASES
planning_simulation()
# end timer
end_time = time()
elapsed_time = end_time - start_time
execution_time_record[iter_counter] = round(elapsed_time, 2)
iter_counter += 1
execution_time_df = pd.DataFrame(execution_time_record.items(), columns=['iteration', 'execution_time(s)'])
execution_time_df.to_csv('results/total_execution_time.csv')