CASE2OFF Creates quantity & price offers from gen & gencost. [Q, P] = CASE2OFF(GEN, GENCOST) creates quantity and price offers from case variables GEN & GENCOST. See also OFF2CASE.
0001 function [q, p] = case2off(gen, gencost) 0002 %CASE2OFF Creates quantity & price offers from gen & gencost. 0003 % [Q, P] = CASE2OFF(GEN, GENCOST) creates quantity and price offers 0004 % from case variables GEN & GENCOST. 0005 % 0006 % See also OFF2CASE. 0007 0008 % MATPOWER 0009 % $Id: case2off.m 1635 2010-04-26 19:45:26Z ray $ 0010 % by Ray Zimmerman, PSERC Cornell 0011 % Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC) 0012 % 0013 % This file is part of MATPOWER. 0014 % See http://www.pserc.cornell.edu/matpower/ for more info. 0015 % 0016 % MATPOWER is free software: you can redistribute it and/or modify 0017 % it under the terms of the GNU General Public License as published 0018 % by the Free Software Foundation, either version 3 of the License, 0019 % or (at your option) any later version. 0020 % 0021 % MATPOWER is distributed in the hope that it will be useful, 0022 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0023 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0024 % GNU General Public License for more details. 0025 % 0026 % You should have received a copy of the GNU General Public License 0027 % along with MATPOWER. If not, see <http://www.gnu.org/licenses/>. 0028 % 0029 % Additional permission under GNU GPL version 3 section 7 0030 % 0031 % If you modify MATPOWER, or any covered work, to interface with 0032 % other modules (such as MATLAB code and MEX-files) available in a 0033 % MATLAB(R) or comparable environment containing parts covered 0034 % under other licensing terms, the licensors of MATPOWER grant 0035 % you additional permission to convey the resulting work. 0036 0037 %% define named indices into data matrices 0038 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 0039 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 0040 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 0041 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 0042 0043 %% do conversion 0044 oldgencost = gencost; 0045 i_poly = find(gencost(:, MODEL) == POLYNOMIAL); 0046 npts = 6; %% 6 points => 5 blocks 0047 %% convert polynomials to piece-wise linear by evaluating at zero and then 0048 %% at evenly spaced points between Pmin and Pmax 0049 if any(i_poly) 0050 [m, n] = size(gencost(i_poly, :)); %% size of piece being changed 0051 gencost(i_poly, MODEL) = PW_LINEAR * ones(m, 1); %% change cost model 0052 gencost(i_poly, COST:n) = zeros(size(gencost(i_poly, COST:n))); %% zero out old data 0053 gencost(i_poly, NCOST) = npts * ones(m, 1); %% change number of data points 0054 0055 for i = 1:m 0056 ig = i_poly(i); %% index to gen 0057 Pmin = gen(ig, PMIN); 0058 Pmax = gen(ig, PMAX); 0059 if Pmin == 0 0060 step = (Pmax - Pmin) / (npts - 1); 0061 xx = (Pmin:step:Pmax); 0062 else 0063 step = (Pmax - Pmin) / (npts - 2); 0064 xx = [0 Pmin:step:Pmax]; 0065 end 0066 yy = totcost(oldgencost(ig, :), xx); 0067 gencost(ig, COST:2:(COST + 2*(npts-1) )) = xx; 0068 gencost(ig, (COST+1):2:(COST + 2*(npts-1) + 1)) = yy; 0069 end 0070 end 0071 n = max(gencost(:, NCOST)); 0072 xx = gencost(:, COST:2:( COST + 2*n - 1 )); 0073 yy = gencost(:, (COST+1):2:( COST + 2*n )); 0074 i1 = 1:(n-1); 0075 i2 = 2:n; 0076 q = xx(:, i2) - xx(:, i1); 0077 p = ( yy(:, i2) - yy(:, i1) ) ./ q;