Home > matpower5.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-2015 by Power System Engineering Research Center (PSERC)
0010 %   by Ray Zimmerman, PSERC Cornell
0011 %
0012 %   $Id: case2off.m 2644 2015-03-11 19:34:22Z ray $
0013 %
0014 %   This file is part of MATPOWER.
0015 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0016 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0017 
0018 %% define named indices into data matrices
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 %% do conversion
0025 oldgencost = gencost;
0026 i_poly = find(gencost(:, MODEL) == POLYNOMIAL);
0027 npts = 6;                   %% 6 points => 5 blocks
0028 %% convert polynomials to piece-wise linear by evaluating at zero and then
0029 %% at evenly spaced points between Pmin and Pmax
0030 if any(i_poly)
0031     [m, n] = size(gencost(i_poly, :));                              %% size of piece being changed
0032     gencost(i_poly, MODEL) = PW_LINEAR * ones(m, 1);                %% change cost model
0033     gencost(i_poly, COST:n) = zeros(size(gencost(i_poly, COST:n))); %% zero out old data
0034     gencost(i_poly, NCOST) = npts * ones(m, 1);                     %% change number of data points
0035     
0036     for i = 1:m
0037         ig = i_poly(i);     %% index to gen
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;

Generated on Fri 20-Mar-2015 18:23:34 by m2html © 2005