Home > matpower5.0 > modcost.m

modcost

PURPOSE ^

MODCOST Modifies generator costs by shifting or scaling (F or X).

SYNOPSIS ^

function gencost = modcost(gencost, alpha, modtype)

DESCRIPTION ^

MODCOST  Modifies generator costs by shifting or scaling (F or X).
   NEWGENCOST = MODCOST(GENCOST, ALPHA)
   NEWGENCOST = MODCOST(GENCOST, ALPHA, MODTYPE)

   For each generator cost F(X) (for real or reactive power) in
   GENCOST, this function modifies the cost by scaling or shifting
   the function by ALPHA, depending on the value of MODTYPE, and
   and returns the modified GENCOST. Rows of GENCOST can be a mix
   of polynomial or piecewise linear costs. ALPHA can be a scalar,
   applied to each row of GENCOST, or an NG x 1 vector, where each
   element is applied to the corresponding row of GENCOST.

   MODTYPE takes one of the 4 possible values (let F_alpha(X) denote the
   the modified function):
       'SCALE_F' (default) : F_alpha(X)         == F(X) * ALPHA
       'SCALE_X'           : F_alpha(X * ALPHA) == F(X)
       'SHIFT_F'           : F_alpha(X)         == F(X) + ALPHA
       'SHIFT_X'           : F_alpha(X + ALPHA) == F(X)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function gencost = modcost(gencost, alpha, modtype)
0002 %MODCOST  Modifies generator costs by shifting or scaling (F or X).
0003 %   NEWGENCOST = MODCOST(GENCOST, ALPHA)
0004 %   NEWGENCOST = MODCOST(GENCOST, ALPHA, MODTYPE)
0005 %
0006 %   For each generator cost F(X) (for real or reactive power) in
0007 %   GENCOST, this function modifies the cost by scaling or shifting
0008 %   the function by ALPHA, depending on the value of MODTYPE, and
0009 %   and returns the modified GENCOST. Rows of GENCOST can be a mix
0010 %   of polynomial or piecewise linear costs. ALPHA can be a scalar,
0011 %   applied to each row of GENCOST, or an NG x 1 vector, where each
0012 %   element is applied to the corresponding row of GENCOST.
0013 %
0014 %   MODTYPE takes one of the 4 possible values (let F_alpha(X) denote the
0015 %   the modified function):
0016 %       'SCALE_F' (default) : F_alpha(X)         == F(X) * ALPHA
0017 %       'SCALE_X'           : F_alpha(X * ALPHA) == F(X)
0018 %       'SHIFT_F'           : F_alpha(X)         == F(X) + ALPHA
0019 %       'SHIFT_X'           : F_alpha(X + ALPHA) == F(X)
0020 
0021 %   MATPOWER
0022 %   $Id: modcost.m 2189 2013-07-30 16:23:31Z ray $
0023 %   by Ray Zimmerman, PSERC Cornell
0024 %   Copyright (c) 2010 by Power System Engineering Research Center (PSERC)
0025 %
0026 %   This file is part of MATPOWER.
0027 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0028 %
0029 %   MATPOWER is free software: you can redistribute it and/or modify
0030 %   it under the terms of the GNU General Public License as published
0031 %   by the Free Software Foundation, either version 3 of the License,
0032 %   or (at your option) any later version.
0033 %
0034 %   MATPOWER is distributed in the hope that it will be useful,
0035 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0036 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0037 %   GNU General Public License for more details.
0038 %
0039 %   You should have received a copy of the GNU General Public License
0040 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0041 %
0042 %   Additional permission under GNU GPL version 3 section 7
0043 %
0044 %   If you modify MATPOWER, or any covered work, to interface with
0045 %   other modules (such as MATLAB code and MEX-files) available in a
0046 %   MATLAB(R) or comparable environment containing parts covered
0047 %   under other licensing terms, the licensors of MATPOWER grant
0048 %   you additional permission to convey the resulting work.
0049 
0050 %% define named indices into data matrices
0051 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0052 
0053 if nargin < 3
0054     modtype = 'SCALE_F';
0055 end
0056 
0057 [ng, m] = size(gencost);
0058 
0059 if ng ~= 0
0060     if length(alpha) ~= ng
0061         if length(alpha) == 1 && ng > 1     %% scalar, make it a col vector
0062             alpha = alpha * ones(ng, 1);
0063         else
0064             error('modcost: ALPHA must be a scalar or col vector with NG rows');
0065         end
0066     elseif size(alpha, 2) ~= 1
0067         alpha = alpha';                     %% convert row vector to col vector
0068     end
0069 
0070     ipwl = find(gencost(:, MODEL) == PW_LINEAR);
0071     ipol = find(gencost(:, MODEL) == POLYNOMIAL);
0072     c = gencost(ipol, COST:m);
0073 
0074     switch modtype
0075         case 'SCALE_F',
0076             gencost(ipol, COST:m)       = diag(alpha(ipol)) * c;
0077             gencost(ipwl, COST+1:2:m)   = diag(alpha(ipwl)) * gencost(ipwl, COST+1:2:m);
0078         case 'SCALE_X',
0079             for k = 1:length(ipol)
0080                 n = gencost(ipol(k), NCOST);
0081                 for i = 1:n
0082                     gencost(ipol(k), COST+i-1) = c(k, i) / alpha(ipol(k))^(n-i);
0083                 end
0084             end
0085             gencost(ipwl, COST:2:m-1)   = diag(alpha(ipwl)) * gencost(ipwl, COST:2:m-1);
0086         case 'SHIFT_F',
0087             for k = 1:length(ipol)
0088                 n = gencost(ipol(k), NCOST);
0089                 gencost(ipol(k), COST+n-1) = alpha(ipol(k)) + c(k, n);
0090             end
0091             gencost(ipwl, COST+1:2:m)   = ...
0092                 diag(alpha(ipwl)) * ones(length(ipwl), (m+1-COST)/2) + ...
0093                     gencost(ipwl, COST+1:2:m);
0094         case 'SHIFT_X',
0095             for k = 1:length(ipol)
0096                 n = gencost(ipol(k), NCOST);
0097                 gencost(ipol(k), COST:COST+n-1) = polyshift(c(k, 1:n)', alpha(ipol(k)))';
0098             end
0099             gencost(ipwl, COST:2:m-1)   = ...
0100                 diag(alpha(ipwl)) * ones(length(ipwl), (m+1-COST)/2) + ...
0101                     gencost(ipwl, COST:2:m-1);
0102         otherwise
0103             error('modcost: ''%s'' is not a valid modtype\n', modtype);
0104     end
0105 end
0106 
0107 
0108 %%-----  POLYSHIFT  -----
0109 function d = polyshift(c, a)
0110 %POLYSHIFT  Returns the coefficients of a horizontally shifted polynomial.
0111 %
0112 %   D = POLYSHIFT(C, A) shifts to the right by A, the polynomial whose
0113 %   coefficients are given in the column vector C.
0114 %
0115 %   Example: For any polynomial with n coefficients in c, and any values
0116 %   for x and shift a, the f - f0 should be zero.
0117 %       x = rand;
0118 %       a = rand;
0119 %       c = rand(n, 1);
0120 %       f0 = polyval(c, x)
0121 %       f  = polyval(polyshift(c, a), x+a)
0122 
0123 n = length(c);
0124 d = zeros(size(c));
0125 A = (-a * ones(n, 1)) .^ ((0:n-1)');
0126 b = ones(n, 1);
0127 for k = 1:n
0128     d(n-k+1) = b' * ( c(n-k+1:-1:1) .* A(1:n-k+1) );
0129     b = cumsum(b(1:n-k));
0130 end

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005