Home > matpower4.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.

   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.
0011 %
0012 %   MODTYPE takes one of the 4 possible values (let F_alpha(X) denote the
0013 %   the modified function):
0014 %       SCALE_F (default) : F_alpha(X)         == F(X) * ALPHA
0015 %       SCALE_X           : F_alpha(X * ALPHA) == F(X)
0016 %       SHIFT_F           : F_alpha(X)         == F(X) + ALPHA
0017 %       SHIFT_X           : F_alpha(X + ALPHA) == F(X)
0018 
0019 %   MATPOWER
0020 %   $Id: modcost.m,v 1.1 2010/06/01 20:11:36 ray Exp $
0021 %   by Ray Zimmerman, PSERC Cornell
0022 %   Copyright (c) 2010 by Power System Engineering Research Center (PSERC)
0023 %
0024 %   This file is part of MATPOWER.
0025 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0026 %
0027 %   MATPOWER is free software: you can redistribute it and/or modify
0028 %   it under the terms of the GNU General Public License as published
0029 %   by the Free Software Foundation, either version 3 of the License,
0030 %   or (at your option) any later version.
0031 %
0032 %   MATPOWER is distributed in the hope that it will be useful,
0033 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0034 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0035 %   GNU General Public License for more details.
0036 %
0037 %   You should have received a copy of the GNU General Public License
0038 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0039 %
0040 %   Additional permission under GNU GPL version 3 section 7
0041 %
0042 %   If you modify MATPOWER, or any covered work, to interface with
0043 %   other modules (such as MATLAB code and MEX-files) available in a
0044 %   MATLAB(R) or comparable environment containing parts covered
0045 %   under other licensing terms, the licensors of MATPOWER grant
0046 %   you additional permission to convey the resulting work.
0047 
0048 %% define named indices into data matrices
0049 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0050 
0051 if nargin < 3
0052     modtype = 'SCALE_F';
0053 end
0054 
0055 [ng, m] = size(gencost);
0056 if ng ~= 0
0057     ipwl = find(gencost(:, MODEL) == PW_LINEAR);
0058     ipol = find(gencost(:, MODEL) == POLYNOMIAL);
0059     c = gencost(ipol, COST:m);
0060 
0061     switch modtype
0062         case 'SCALE_F',
0063             gencost(ipol, COST:m)       = alpha * c;
0064             gencost(ipwl, COST+1:2:m)   = alpha * gencost(ipwl, COST+1:2:m);
0065         case 'SCALE_X',
0066             for k = 1:length(ipol)
0067                 n = gencost(ipol(k), NCOST);
0068                 for i = 1:n
0069                     gencost(ipol(k), COST+i-1) = c(k, i) / alpha^(n-i);
0070                 end
0071             end
0072             gencost(ipwl, COST:2:m-1)   = alpha * gencost(ipwl, COST:2:m-1);
0073         case 'SHIFT_F',
0074             for k = 1:length(ipol)
0075                 n = gencost(ipol(k), NCOST);
0076                 gencost(ipol(k), COST+n-1) = alpha + c(k, n);
0077             end
0078             gencost(ipwl, COST+1:2:m)   = alpha + gencost(ipwl, COST+1:2:m);
0079         case 'SHIFT_X',
0080             for k = 1:length(ipol)
0081                 n = gencost(ipol(k), NCOST);
0082                 gencost(ipol(k), COST:COST+n-1) = polyshift(c(k, 1:n)', alpha)';
0083             end
0084             gencost(ipwl, COST:2:m-1)   = alpha + gencost(ipwl, COST:2:m-1);
0085         otherwise
0086             error('modcost: ''%s'' is not a valid modtype\n', modtype);
0087     end
0088 end
0089 
0090 
0091 %%-----  POLYSHIFT  -----
0092 function d = polyshift(c, a)
0093 %POLYSHIFT  Returns the coefficients of a horizontally shifted polynomial.
0094 %
0095 %   D = POLYSHIFT(C, A) shifts to the right by A, the polynomial whose
0096 %   coefficients are given in the column vector C.
0097 %
0098 %   Example: For any polynomial with n coefficients in c, and any values
0099 %   for x and shift a, the f - f0 should be zero.
0100 %       x = rand;
0101 %       a = rand;
0102 %       c = rand(n, 1);
0103 %       f0 = polyval(c, x)
0104 %       f  = polyval(polyshift(c, a), x+a)
0105 
0106 n = length(c);
0107 d = zeros(size(c));
0108 A = (-a * ones(n, 1)) .^ ((0:n-1)');
0109 b = ones(n, 1);
0110 for k = 1:n
0111     d(n-k+1) = b' * ( c(n-k+1:-1:1) .* A(1:n-k+1) );
0112     b = cumsum(b(1:n-k));
0113 end

Generated on Mon 26-Jan-2015 15:00:13 by m2html © 2005