Package pypower :: Module totcost
[hide private]
[frames] | no frames]

Source Code for Module pypower.totcost

 1  # Copyright (C) 1996-2011 Power System Engineering Research Center (PSERC) 
 2  # Copyright (C) 2011 Richard Lincoln 
 3  # 
 4  # PYPOWER is free software: you can redistribute it and/or modify 
 5  # it under the terms of the GNU General Public License as published 
 6  # by the Free Software Foundation, either version 3 of the License, 
 7  # or (at your option) any later version. 
 8  # 
 9  # PYPOWER is distributed in the hope that it will be useful, 
10  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
11  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
12  # GNU General Public License for more details. 
13  # 
14  # You should have received a copy of the GNU General Public License 
15  # along with PYPOWER. If not, see <http://www.gnu.org/licenses/>. 
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   
27 -def totcost(gencost, Pg):
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