0001 function [q, p] = case2off(gen, gencost)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
0020 MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
0021 QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
0022 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0023
0024
0025 oldgencost = gencost;
0026 i_poly = find(gencost(:, MODEL) == POLYNOMIAL);
0027 npts = 6;
0028
0029
0030 if any(i_poly)
0031 [m, n] = size(gencost(i_poly, :));
0032 gencost(i_poly, MODEL) = PW_LINEAR * ones(m, 1);
0033 gencost(i_poly, COST:n) = zeros(size(gencost(i_poly, COST:n)));
0034 gencost(i_poly, NCOST) = npts * ones(m, 1);
0035
0036 for i = 1:m
0037 ig = i_poly(i);
0038 Pmin = gen(ig, PMIN);
0039 Pmax = gen(ig, PMAX);
0040 if Pmin == 0
0041 step = (Pmax - Pmin) / (npts - 1);
0042 xx = (Pmin:step:Pmax);
0043 else
0044 step = (Pmax - Pmin) / (npts - 2);
0045 xx = [0 Pmin:step:Pmax];
0046 end
0047 yy = totcost(oldgencost(ig, :), xx);
0048 gencost(ig, COST:2:(COST + 2*(npts-1) )) = xx;
0049 gencost(ig, (COST+1):2:(COST + 2*(npts-1) + 1)) = yy;
0050 end
0051 end
0052 n = max(gencost(:, NCOST));
0053 xx = gencost(:, COST:2:( COST + 2*n - 1 ));
0054 yy = gencost(:, (COST+1):2:( COST + 2*n ));
0055 i1 = 1:(n-1);
0056 i2 = 2:n;
0057 q = xx(:, i2) - xx(:, i1);
0058 p = ( yy(:, i2) - yy(:, i1) ) ./ q;