Home > matpower5.1 > makeAy.m

makeAy

PURPOSE ^

MAKEAY Make the A matrix and RHS for the CCV formulation.

SYNOPSIS ^

function [Ay, by] = makeAy(baseMVA, ng, gencost, pgbas, qgbas, ybas)

DESCRIPTION ^

MAKEAY  Make the A matrix and RHS for the CCV formulation.
   [AY, BY]  = MAKEAY(BASEMVA, NG, GENCOST, PGBAS, QGBAS, YBAS)

   Constructs the parameters for linear "basin constraints" on Pg, Qg
   and Y used by the CCV cost formulation, expressed as

       AY * X <= BY

   where X is the vector of optimization variables. The starting index
   within the X vector for the active, reactive sources and the Y
   variables should be provided in arguments PGBAS, QGBAS, YBAS. The
   number of generators is NG.

   Assumptions: All generators are in-service.  Filter any generators
   that are offline from the GENCOST matrix before calling MAKEAY.
   Efficiency depends on Qg variables being after Pg variables, and
   the Y variables must be the last variables within the vector X for
   the dimensions of the resulting AY to be conformable with X.

   Example:
       [Ay, by]  = makeAy(baseMVA, ng, gencost, pgbas, qgbas, ybas);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Ay, by]  = makeAy(baseMVA, ng, gencost, pgbas, qgbas, ybas)
0002 %MAKEAY  Make the A matrix and RHS for the CCV formulation.
0003 %   [AY, BY]  = MAKEAY(BASEMVA, NG, GENCOST, PGBAS, QGBAS, YBAS)
0004 %
0005 %   Constructs the parameters for linear "basin constraints" on Pg, Qg
0006 %   and Y used by the CCV cost formulation, expressed as
0007 %
0008 %       AY * X <= BY
0009 %
0010 %   where X is the vector of optimization variables. The starting index
0011 %   within the X vector for the active, reactive sources and the Y
0012 %   variables should be provided in arguments PGBAS, QGBAS, YBAS. The
0013 %   number of generators is NG.
0014 %
0015 %   Assumptions: All generators are in-service.  Filter any generators
0016 %   that are offline from the GENCOST matrix before calling MAKEAY.
0017 %   Efficiency depends on Qg variables being after Pg variables, and
0018 %   the Y variables must be the last variables within the vector X for
0019 %   the dimensions of the resulting AY to be conformable with X.
0020 %
0021 %   Example:
0022 %       [Ay, by]  = makeAy(baseMVA, ng, gencost, pgbas, qgbas, ybas);
0023 
0024 %   MATPOWER
0025 %   Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC)
0026 %   by Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
0027 %
0028 %   $Id: makeAy.m 2644 2015-03-11 19:34:22Z ray $
0029 %
0030 %   This file is part of MATPOWER.
0031 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0032 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0033 
0034 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0035 
0036 % find all pwl cost rows in gencost, either real or reactive
0037 iycost = find(gencost(:, MODEL) == PW_LINEAR);
0038 
0039 % this is the number of extra "y" variables needed to model those costs
0040 ny = size(iycost, 1);
0041 
0042 if ny == 0
0043    Ay = sparse([], [], [], 0, ybas+ny-1, 0);
0044    by = [];
0045    return
0046 end
0047 
0048 % if p(i),p(i+1),c(i),c(i+1) define one of the cost segments, then
0049 % the corresponding constraint on Pg (or Qg) and Y is
0050 %                                             c(i+1) - c(i)
0051 %  Y   >=   c(i) + m * (Pg - p(i)),      m = ---------------
0052 %                                             p(i+1) - p(i)
0053 %
0054 % this becomes   m * Pg - Y   <=   m*p(i) - c(i)
0055 
0056 % Form A matrix.  Use two different loops, one for the Pg/Qg coeffs,
0057 % then another for the y coeffs so that everything is filled in the
0058 % same order as the compressed column sparse format used by Matlab;
0059 % this should be the quickest.
0060 
0061 m = sum(gencost(iycost, NCOST));  % total number of cost points
0062 Ay = sparse([], [], [], m-ny, ybas+ny-1, 2*(m-ny)); 
0063 by = [];
0064 % First fill the Pg or Qg coefficients (since their columns come first)
0065 % and the rhs
0066 k = 1;
0067 for i=iycost'
0068    ns = gencost(i, NCOST);                % # of cost points; segments = ns-1
0069    p = gencost(i, COST:2:COST+2*ns-1) / baseMVA;
0070    c = gencost(i, COST+1:2:COST+2*ns);
0071    m = diff(c) ./ diff(p);                % slopes for Pg (or Qg)
0072    if any(diff(p) == 0)
0073      fprintf('\nmakeAy: bad x axis data in row %i of gencost matrix\n',i);
0074    end
0075    b = m .* p(1:ns-1) - c(1:ns-1);        % and rhs
0076    by = [by;  b'];
0077    if i > ng
0078      sidx = qgbas + (i-ng) - 1;           % this was for a q cost
0079    else
0080      sidx = pgbas + i - 1;                % this was for a p cost
0081    end
0082    Ay(k:k+ns-2, sidx) = m';
0083    k = k + ns - 1;
0084 end
0085 % Now fill the y columns with -1's
0086 k = 1;
0087 j = 1;
0088 for i=iycost'
0089    ns = gencost(i, NCOST);
0090    Ay(k:k+ns-2, ybas+j-1) = -ones(ns-1,1);
0091    k = k + ns - 1;
0092    j = j + 1;
0093 end

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