Home > matpower5.1 > 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 %   Copyright (c) 2010-2015 by Power System Engineering Research Center (PSERC)
0023 %   by Ray Zimmerman, PSERC Cornell
0024 %
0025 %   $Id: modcost.m 2644 2015-03-11 19:34:22Z ray $
0026 %
0027 %   This file is part of MATPOWER.
0028 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0029 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0030 
0031 %% define named indices into data matrices
0032 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0033 
0034 if nargin < 3
0035     modtype = 'SCALE_F';
0036 end
0037 
0038 [ng, m] = size(gencost);
0039 
0040 if ng ~= 0
0041     if length(alpha) ~= ng
0042         if length(alpha) == 1 && ng > 1     %% scalar, make it a col vector
0043             alpha = alpha * ones(ng, 1);
0044         else
0045             error('modcost: ALPHA must be a scalar or col vector with NG rows');
0046         end
0047     elseif size(alpha, 2) ~= 1
0048         alpha = alpha';                     %% convert row vector to col vector
0049     end
0050 
0051     ipwl = find(gencost(:, MODEL) == PW_LINEAR);
0052     ipol = find(gencost(:, MODEL) == POLYNOMIAL);
0053     c = gencost(ipol, COST:m);
0054 
0055     switch modtype
0056         case 'SCALE_F',
0057             gencost(ipol, COST:m)       = diag(alpha(ipol)) * c;
0058             gencost(ipwl, COST+1:2:m)   = diag(alpha(ipwl)) * gencost(ipwl, COST+1:2:m);
0059         case 'SCALE_X',
0060             for k = 1:length(ipol)
0061                 n = gencost(ipol(k), NCOST);
0062                 for i = 1:n
0063                     gencost(ipol(k), COST+i-1) = c(k, i) / alpha(ipol(k))^(n-i);
0064                 end
0065             end
0066             gencost(ipwl, COST:2:m-1)   = diag(alpha(ipwl)) * gencost(ipwl, COST:2:m-1);
0067         case 'SHIFT_F',
0068             for k = 1:length(ipol)
0069                 n = gencost(ipol(k), NCOST);
0070                 gencost(ipol(k), COST+n-1) = alpha(ipol(k)) + c(k, n);
0071             end
0072             gencost(ipwl, COST+1:2:m)   = ...
0073                 diag(alpha(ipwl)) * ones(length(ipwl), (m+1-COST)/2) + ...
0074                     gencost(ipwl, COST+1:2:m);
0075         case 'SHIFT_X',
0076             for k = 1:length(ipol)
0077                 n = gencost(ipol(k), NCOST);
0078                 gencost(ipol(k), COST:COST+n-1) = polyshift(c(k, 1:n)', alpha(ipol(k)))';
0079             end
0080             gencost(ipwl, COST:2:m-1)   = ...
0081                 diag(alpha(ipwl)) * ones(length(ipwl), (m+1-COST)/2) + ...
0082                     gencost(ipwl, COST:2:m-1);
0083         otherwise
0084             error('modcost: ''%s'' is not a valid modtype\n', modtype);
0085     end
0086 end
0087 
0088 
0089 %%-----  POLYSHIFT  -----
0090 function d = polyshift(c, a)
0091 %POLYSHIFT  Returns the coefficients of a horizontally shifted polynomial.
0092 %
0093 %   D = POLYSHIFT(C, A) shifts to the right by A, the polynomial whose
0094 %   coefficients are given in the column vector C.
0095 %
0096 %   Example: For any polynomial with n coefficients in c, and any values
0097 %   for x and shift a, the f - f0 should be zero.
0098 %       x = rand;
0099 %       a = rand;
0100 %       c = rand(n, 1);
0101 %       f0 = polyval(c, x)
0102 %       f  = polyval(polyshift(c, a), x+a)
0103 
0104 n = length(c);
0105 d = zeros(size(c));
0106 A = (-a * ones(n, 1)) .^ ((0:n-1)');
0107 b = ones(n, 1);
0108 for k = 1:n
0109     d(n-k+1) = b' * ( c(n-k+1:-1:1) .* A(1:n-k+1) );
0110     b = cumsum(b(1:n-k));
0111 end

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005