-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmod_matrices.py
96 lines (76 loc) · 2.57 KB
/
mod_matrices.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
import numpy as np
# from snl_progress.mod_sysdata import RASystemData
class RAMatrices:
'''Creates generation, incidence, and curtailment matrices for the RA model'''
def __init__(self, nb):
"""
Initializes the RAMatrices class.
Parameters:
nb (int): Number of buses in the system.
"""
self.nb = nb
def genmat(self, ng, genbus, ness, essbus):
"""
Creates a generation matrix for the optimization problem.
Parameters:
ng (int): Number of generators.
genbus (list): List of generator buses.
ness (int): Number of energy storage systems (ESS).
essbus (list): List of ESS buses.
Returns:
numpy.ndarray: Generation matrix.
"""
self.ng = ng + ness
self.genbus = np.concatenate((genbus, essbus))
self.gen_mat = np.zeros((self.nb, self.ng))
j_temp = 0
for i in range(self.ng):
self.gen_mat[self.genbus[i]-1, j_temp] = 1
j_temp+=1
return(self.gen_mat)
def Ainc(self, nl, fb, tb):
"""
Creates an incidence matrix for modeling the flow constraints.
Parameters:
nl (int): Number of lines.
fb (list): From buses.
tb (list): To buses.
Returns:
numpy.ndarray: Incidence matrix.
"""
self.nl = nl
self.fb = fb
self.tb = tb
self.A_inc = np.zeros((self.nl, self.nb))
for i in range(self.nl):
for j in range(self.nb + 1):
if self.fb[i] == j:
self.A_inc[i,j - 1] = 1
elif self.tb[i] == j:
self.A_inc[i, j - 1] = -1
return(self.A_inc)
def curtmat(self, nb):
"""
Creates a curtailment matrix for the load curtailment variables in the optimizer.
Parameters:
nb (int): Number of buses.
Returns:
numpy.ndarray: Curtailment matrix.
"""
return(np.eye(nb))
def chmat(self, ness, essbus, nb):
"""
Creates a matrix for ESS charging variables.
Parameters:
ness (int): Number of energy storage systems (ESS).
essbus (list): List of ESS buses.
nb (int): Number of buses.
Returns:
numpy.ndarray: ESS charging matrix.
"""
self.ch_mat = np.zeros((nb, ness))
j_temp = 0
for i in range(ness):
self.ch_mat[essbus[i]-1, j_temp] = 1
j_temp+=1
return(self.ch_mat)