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

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005