1
1
# import libraries
2
- import networkx
3
2
from pyomo .environ import *
4
3
import numpy as np
5
4
import scipy .io as readmat
16
15
# degree to radian conversion factor
17
16
deg_to_rad = math .pi / 180
18
17
19
- # extract the scenarios and their probabilities from external file
20
- scenario_file = dir_file + r"/scenario_files/failure_scenarios.mat"
21
- probability_file = dir_file + r"/scenario_files/scenario_probabilities_49.csv"
22
-
23
18
# create a concrete pyomo model
24
19
model = ConcreteModel ()
25
20
26
21
# load matpower test case in mat format
27
- matpower_mat_file = readmat .loadmat (dir_file + '/test_cases /case' + test_case + '.mat' ,
22
+ matpower_mat_file = readmat .loadmat (dir_file + '/power_system_test_cases /case' + test_case + '.mat' ,
28
23
struct_as_record = False ,
29
24
squeeze_me = True )
30
25
# ensure that all the saved mat file are saved under workspace var name 'matpower_testcase'
48
43
Inf_transfer_Pmax = 10e6
49
44
Pmax_line = 10e6 / model .Pbase
50
45
51
- # # Pmax, Gmax, and max load for bounds set
52
- # if max(model.line[:, 7]) == 0:
53
- # Pmax_line = Inf_transfer_Pmax / model.Pbase
54
- # else:
55
- # Pmax_line = max(model.line[:, 7]) / model.Pbase
56
-
57
46
Gmax = max (model .gen [:, 8 ]) / model .Pbase
58
47
max_load = max (model .bus [:, 2 ]) / model .Pbase
59
48
77
66
initialize = 0 ) # active power flowing through each lines
78
67
model .theta_ss = Var (model .b_i , bounds = (- 2 * math .pi , 2 * math .pi ), within = Reals , initialize = 0 ) # angle of each bus
79
68
80
- # model.xij = Var(model.x_ij, bounds=(0,1), within=Binary, initialize=0) # connectivity of each line
81
- # model.load_shed = Var(model.b_i, bounds=(0, max_load), within=Reals) # real active power shed at each bus
82
-
83
-
84
69
###############################################################################################################
85
70
####################################### Constraints ###########################################################
86
71
###############################################################################################################
180
165
model .angle_limit .add (model .theta_ss [slack_bus ] == 0 )
181
166
182
167
183
- # ###################### max load shedding ############################################
184
- # for load_bus_num in range(model.nNodes):
185
- # model.c.add(model.load_shed[load_bus_num] >= 0)
186
- # model.c.add(model.load_shed[load_bus_num] <= model.bus[load_bus_num, 2])
187
-
188
-
189
168
############################# Overall Objective ###########################
190
169
191
170
def overall_objective (model ):
192
- expr = 0
193
171
expr = sum (model .gen_cost [gen_num , 4 ] * (model .bus_gen_ss [np .where (model .bus [:, 0 ] == model .gen [gen_num , 0 ])[0 ][0 ]]
194
172
* model .Pbase ) ** 2 +
195
173
model .gen_cost [gen_num , 5 ] * (model .bus_gen_ss [np .where (model .bus [:, 0 ] == model .gen [gen_num , 0 ])[0 ][0 ]]
196
174
* model .Pbase ) +
197
175
model .gen_cost [gen_num , 6 ] for gen_num in range (model .nGen ))
198
- # expr = sum(model.load_shed[bus_num] for bus_num in range(model.nNodes))
199
176
return expr
200
177
201
178
@@ -209,7 +186,6 @@ def overall_objective(model):
209
186
results = solver .solve (model , tee = True )
210
187
211
188
# Observing the results
212
-
213
189
for k in range (0 , model .nGen ):
214
190
print ("G[%d] = %f" % (model .gen [k , 0 ], value (model .bus_gen_ss [np .where (model .bus [:, 0 ] ==
215
191
model .gen [k , 0 ])[0 ][0 ]])))
0 commit comments