Home > matpower7.1 > extras > smartmarket > case2off.m

case2off

PURPOSE ^

CASE2OFF Creates quantity & price offers from gen & gencost.

SYNOPSIS ^

function [q, p] = case2off(gen, gencost)

DESCRIPTION ^

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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

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 %   Copyright (c) 1996-2016, Power Systems Engineering Research Center (PSERC)
0010 %   by Ray Zimmerman, PSERC Cornell
0011 %
0012 %   This file is part of MATPOWER Extras.
0013 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0014 %   See https://github.com/MATPOWER/matpower-extras for more info.
0015 
0016 %% define named indices into data matrices
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 %% do conversion
0023 oldgencost = gencost;
0024 i_poly = find(gencost(:, MODEL) == POLYNOMIAL);
0025 npts = 6;                   %% 6 points => 5 blocks
0026 %% convert polynomials to piece-wise linear by evaluating at zero and then
0027 %% at evenly spaced points between Pmin and Pmax
0028 if any(i_poly)
0029     [m, n] = size(gencost(i_poly, :));                              %% size of piece being changed
0030     gencost(i_poly, MODEL) = PW_LINEAR * ones(m, 1);                %% change cost model
0031     gencost(i_poly, COST:n) = zeros(size(gencost(i_poly, COST:n))); %% zero out old data
0032     gencost(i_poly, NCOST) = npts * ones(m, 1);                     %% change number of data points
0033     
0034     for i = 1:m
0035         ig = i_poly(i);     %% index to gen
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;

Generated on Fri 09-Oct-2020 11:21:31 by m2html © 2005