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