Home > matpower4.0 > 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 %   $Id: makeAy.m,v 1.11 2010/04/26 19:45:25 ray Exp $
0026 %   by Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales
0027 %   Copyright (c) 1996-2010 by Power System Engineering Research Center (PSERC)
0028 %
0029 %   This file is part of MATPOWER.
0030 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0031 %
0032 %   MATPOWER is free software: you can redistribute it and/or modify
0033 %   it under the terms of the GNU General Public License as published
0034 %   by the Free Software Foundation, either version 3 of the License,
0035 %   or (at your option) any later version.
0036 %
0037 %   MATPOWER is distributed in the hope that it will be useful,
0038 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0039 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0040 %   GNU General Public License for more details.
0041 %
0042 %   You should have received a copy of the GNU General Public License
0043 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0044 %
0045 %   Additional permission under GNU GPL version 3 section 7
0046 %
0047 %   If you modify MATPOWER, or any covered work, to interface with
0048 %   other modules (such as MATLAB code and MEX-files) available in a
0049 %   MATLAB(R) or comparable environment containing parts covered
0050 %   under other licensing terms, the licensors of MATPOWER grant
0051 %   you additional permission to convey the resulting work.
0052 
0053 [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost;
0054 
0055 % find all pwl cost rows in gencost, either real or reactive
0056 iycost = find(gencost(:, MODEL) == PW_LINEAR);
0057 
0058 % this is the number of extra "y" variables needed to model those costs
0059 ny = size(iycost, 1);
0060 
0061 if ny == 0
0062    Ay = sparse([], [], [], 0, ybas+ny-1, 0);
0063    by = [];
0064    return
0065 end
0066 
0067 % if p(i),p(i+1),c(i),c(i+1) define one of the cost segments, then
0068 % the corresponding constraint on Pg (or Qg) and Y is
0069 %                                             c(i+1) - c(i)
0070 %  Y   >=   c(i) + m * (Pg - p(i)),      m = ---------------
0071 %                                             p(i+1) - p(i)
0072 %
0073 % this becomes   m * Pg - Y   <=   m*p(i) - c(i)
0074 
0075 % Form A matrix.  Use two different loops, one for the PG/Qg coefs,
0076 % then another for the y coefs so that everything is filled in the
0077 % same order as the compressed column sparse format used by matlab;
0078 % this should be the quickest.
0079 
0080 m = sum(gencost(iycost, NCOST));  % total number of cost points
0081 Ay = sparse([], [], [], m-ny, ybas+ny-1, 2*(m-ny)); 
0082 by = [];
0083 % First fill the Pg or Qg coefficients (since their columns come first)
0084 % and the rhs
0085 k = 1;
0086 for i=iycost'
0087    ns = gencost(i, NCOST);                % # of cost points; segments = ns-1
0088    p = gencost(i, COST:2:COST+2*ns-1) / baseMVA;
0089    c = gencost(i, COST+1:2:COST+2*ns);
0090    m = diff(c) ./ diff(p);                % slopes for Pg (or Qg)
0091    if any(diff(p) == 0)
0092      fprintf('\nmakeAy: bad x axis data in row %i of gencost matrix\n',i);
0093    end
0094    b = m .* p(1:ns-1) - c(1:ns-1);        % and rhs
0095    by = [by;  b'];
0096    if i > ng
0097      sidx = qgbas + (i-ng) - 1;           % this was for a q cost
0098    else
0099      sidx = pgbas + i - 1;                % this was for a p cost
0100    end
0101    Ay(k:k+ns-2, sidx) = m';
0102    k = k + ns - 1;
0103 end
0104 % Now fill the y columns with -1's
0105 k = 1;
0106 j = 1;
0107 for i=iycost'
0108    ns = gencost(i, NCOST);
0109    Ay(k:k+ns-2, ybas+j-1) = -ones(ns-1,1);
0110    k = k + ns - 1;
0111    j = j + 1;
0112 end

Generated on Mon 26-Jan-2015 14:56:45 by m2html © 2005