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)
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-2016, 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 c = gencost(ipol, COST:m); 0052 0053 switch modtype 0054 case 'SCALE_F', 0055 gencost(ipol, COST:m) = diag(alpha(ipol)) * c; 0056 gencost(ipwl, COST+1:2:m) = diag(alpha(ipwl)) * gencost(ipwl, COST+1:2:m); 0057 case 'SCALE_X', 0058 for k = 1:length(ipol) 0059 n = gencost(ipol(k), NCOST); 0060 for i = 1:n 0061 gencost(ipol(k), COST+i-1) = c(k, i) / alpha(ipol(k))^(n-i); 0062 end 0063 end 0064 gencost(ipwl, COST:2:m-1) = diag(alpha(ipwl)) * gencost(ipwl, COST:2:m-1); 0065 case 'SHIFT_F', 0066 for k = 1:length(ipol) 0067 n = gencost(ipol(k), NCOST); 0068 gencost(ipol(k), COST+n-1) = alpha(ipol(k)) + c(k, n); 0069 end 0070 gencost(ipwl, COST+1:2:m) = ... 0071 diag(alpha(ipwl)) * ones(length(ipwl), (m+1-COST)/2) + ... 0072 gencost(ipwl, COST+1:2:m); 0073 case 'SHIFT_X', 0074 for k = 1:length(ipol) 0075 n = gencost(ipol(k), NCOST); 0076 gencost(ipol(k), COST:COST+n-1) = polyshift(c(k, 1:n)', alpha(ipol(k)))'; 0077 end 0078 gencost(ipwl, COST:2:m-1) = ... 0079 diag(alpha(ipwl)) * ones(length(ipwl), (m+1-COST)/2) + ... 0080 gencost(ipwl, COST:2:m-1); 0081 otherwise 0082 error('modcost: ''%s'' is not a valid modtype\n', modtype); 0083 end 0084 end 0085 0086 0087 %%----- POLYSHIFT ----- 0088 function d = polyshift(c, a) 0089 %POLYSHIFT Returns the coefficients of a horizontally shifted polynomial. 0090 % 0091 % D = POLYSHIFT(C, A) shifts to the right by A, the polynomial whose 0092 % coefficients are given in the column vector C. 0093 % 0094 % Example: For any polynomial with n coefficients in c, and any values 0095 % for x and shift a, the f - f0 should be zero. 0096 % x = rand; 0097 % a = rand; 0098 % c = rand(n, 1); 0099 % f0 = polyval(c, x) 0100 % f = polyval(polyshift(c, a), x+a) 0101 0102 n = length(c); 0103 d = zeros(size(c)); 0104 A = (-a * ones(n, 1)) .^ ((0:n-1)'); 0105 b = ones(n, 1); 0106 for k = 1:n 0107 d(n-k+1) = b' * ( c(n-k+1:-1:1) .* A(1:n-k+1) ); 0108 b = cumsum(b(1:n-k)); 0109 end