1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Computes total cost for generators at given output level.
18 """
19
20 from numpy import zeros, arange
21 from numpy import flatnonzero as find
22
23 from polycost import polycost
24 from idx_cost import PW_LINEAR, POLYNOMIAL, COST, NCOST, MODEL
25
26
28 """Computes total cost for generators at given output level.
29
30 Computes total cost for generators given a matrix in gencost format and
31 a column vector or matrix of generation levels. The return value has the
32 same dimensions as PG. Each row of C{gencost} is used to evaluate the
33 cost at the points specified in the corresponding row of C{Pg}.
34
35 @author: Ray Zimmerman (PSERC Cornell)
36 @author: Carlos E. Murillo-Sanchez (PSERC Cornell & Universidad
37 Autonoma de Manizales)
38 @author: Richard Lincoln
39 """
40 ng, m = gencost.shape
41 totalcost = zeros(ng)
42
43 if len(gencost) > 0:
44 ipwl = find(gencost[:, MODEL] == PW_LINEAR)
45 ipol = find(gencost[:, MODEL] == POLYNOMIAL)
46 if len(ipwl) > 0:
47 p = gencost[:, COST:(m-1):2]
48 c = gencost[:, (COST+1):m:2]
49
50 for i in ipwl:
51 ncost = gencost[i, NCOST]
52 for k in arange(ncost - 1):
53 p1, p2 = p[i, k], p[i, k+1]
54 c1, c2 = c[i, k], c[i, k+1]
55 m = (c2 - c1) / (p2 - p1)
56 b = c1 - m * p1
57 Pgen = Pg[i]
58 if Pgen < p2:
59 totalcost[i] = m * Pgen + b
60 break
61 totalcost[i] = m * Pgen + b
62
63 if len(ipol) > 0:
64 totalcost[ipol] = polycost(gencost[ipol, :], Pg[ipol])
65
66 return totalcost
67