Skip to content

Commit 4dafc43

Browse files
committed
minor updates on the code
1 parent 275fb0e commit 4dafc43

File tree

7 files changed

+14299
-25
lines changed

7 files changed

+14299
-25
lines changed

DCOPF.py

+1-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# import libraries
2-
import networkx
32
from pyomo.environ import *
43
import numpy as np
54
import scipy.io as readmat
@@ -16,15 +15,11 @@
1615
# degree to radian conversion factor
1716
deg_to_rad = math.pi / 180
1817

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-
2318
# create a concrete pyomo model
2419
model = ConcreteModel()
2520

2621
# 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',
2823
struct_as_record=False,
2924
squeeze_me=True)
3025
# ensure that all the saved mat file are saved under workspace var name 'matpower_testcase'
@@ -48,12 +43,6 @@
4843
Inf_transfer_Pmax = 10e6
4944
Pmax_line = 10e6/model.Pbase
5045

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-
5746
Gmax = max(model.gen[:, 8]) / model.Pbase
5847
max_load = max(model.bus[:, 2]) / model.Pbase
5948

@@ -77,10 +66,6 @@
7766
initialize=0) # active power flowing through each lines
7867
model.theta_ss = Var(model.b_i, bounds=(-2 * math.pi, 2 * math.pi), within=Reals, initialize=0) # angle of each bus
7968

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-
8469
###############################################################################################################
8570
####################################### Constraints ###########################################################
8671
###############################################################################################################
@@ -180,22 +165,14 @@
180165
model.angle_limit.add(model.theta_ss[slack_bus] == 0)
181166

182167

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-
189168
############################# Overall Objective ###########################
190169

191170
def overall_objective(model):
192-
expr = 0
193171
expr = sum(model.gen_cost[gen_num, 4] * (model.bus_gen_ss[np.where(model.bus[:, 0] == model.gen[gen_num, 0])[0][0]]
194172
* model.Pbase) ** 2 +
195173
model.gen_cost[gen_num, 5] * (model.bus_gen_ss[np.where(model.bus[:, 0] == model.gen[gen_num, 0])[0][0]]
196174
* model.Pbase) +
197175
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))
199176
return expr
200177

201178

@@ -209,7 +186,6 @@ def overall_objective(model):
209186
results = solver.solve(model, tee=True)
210187

211188
# Observing the results
212-
213189
for k in range(0, model.nGen):
214190
print("G[%d] = %f" % (model.gen[k, 0], value(model.bus_gen_ss[np.where(model.bus[:, 0] ==
215191
model.gen[k, 0])[0][0]])))

0 commit comments

Comments
 (0)