1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Make the A matrix and RHS for the CCV formulation.
18 """
19
20 from numpy import array, diff, any, zeros, r_, flatnonzero as find
21
22 from scipy.sparse import lil_matrix as sparse
23
24 from idx_cost import MODEL, PW_LINEAR, NCOST, COST
25
26
27 -def makeAy(baseMVA, ng, gencost, pgbas, qgbas, ybas):
28 """Make the A matrix and RHS for the CCV formulation.
29
30 Constructs the parameters for linear "basin constraints" on C{Pg}, C{Qg}
31 and C{Y} used by the CCV cost formulation, expressed as::
32
33 Ay * x <= by
34
35 where C{x} is the vector of optimization variables. The starting index
36 within the C{x} vector for the active, reactive sources and the C{y}
37 variables should be provided in arguments C{pgbas}, C{qgbas}, C{ybas}.
38 The number of generators is C{ng}.
39
40 Assumptions: All generators are in-service. Filter any generators
41 that are offline from the C{gencost} matrix before calling L{makeAy}.
42 Efficiency depends on C{Qg} variables being after C{Pg} variables, and
43 the C{y} variables must be the last variables within the vector C{x} for
44 the dimensions of the resulting C{Ay} to be conformable with C{x}.
45
46 @author: Carlos E. Murillo-Sanchez (PSERC Cornell & Universidad
47 Autonoma de Manizales)
48 @author: Richard Lincoln
49 """
50
51 iycost = find(gencost[:, MODEL] == PW_LINEAR)
52
53
54 ny = iycost.shape[0]
55
56 if ny == 0:
57 Ay = zeros((0, ybas + ny - 1))
58 by = array([])
59 return Ay, by
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 m = sum( gencost[iycost, NCOST].astype(int) )
75 Ay = sparse((m - ny, ybas + ny - 1))
76 by = array([])
77
78
79 k = 0
80 for i in iycost:
81 ns = gencost[i, NCOST].astype(int)
82 p = gencost[i, COST:COST + 2 * ns - 1:2] / baseMVA
83 c = gencost[i, COST + 1:COST + 2 * ns:2]
84 m = diff(c) / diff(p)
85 if any(diff(p) == 0):
86 print 'makeAy: bad x axis data in row ##i of gencost matrix' % i
87 b = m * p[:ns - 1] - c[:ns - 1]
88 by = r_[by, b]
89 if i > ng:
90 sidx = qgbas + (i - ng) - 1
91 else:
92 sidx = pgbas + i - 1
93
94
95
96 for ii, kk in enumerate(range(k, k + ns - 1)):
97 Ay[kk, sidx] = m[ii]
98
99 k = k + ns - 1
100
101 k = 0
102 j = 0
103 for i in iycost:
104 ns = gencost[i, NCOST].astype(int)
105
106
107 for kk in range(k, k + ns - 1):
108 Ay[kk, ybas + j - 1] = -1
109 k = k + ns - 1
110 j = j + 1
111
112 return Ay.tocsr(), by
113