Home > matpower5.0 > extras > sdp_pf > makesdpmat.m

makesdpmat

PURPOSE ^

MAKESDPMAT Creates the matrix functions used in the semidefinite

SYNOPSIS ^

function [Yk,Yk_,Mk,Ylineft,Ylinetf,Y_lineft,Y_linetf,YL,YL_] = makesdpmat(mpc)

DESCRIPTION ^

MAKESDPMAT Creates the matrix functions used in the semidefinite 
programming relaxation of the optimal power flow problem.
   [YK,YK_,MK,YLINEFT,YLINETF,Y_LINEFT,Y_LINETF] = MAKESDPMAT(MPC)

   Creates functions that return the matrices used in the semidefinite
   programming relaxation of the optimal power flow problem.

   Inputs:
       MPC : MATPOWER case variable with internal indexing.

   Outputs:
       YK : Function to create the matrix for active power injection.
           Yk(i) is the matrix corresponding to the active power injection
           at bus i.
       YK_ : Function to create the matrix for reactive power injection.
           Yk_(i) is the matrix corresponding to the reactive power
           injection at bus i.
       MK : Function to create the matrix for the square of voltage
           magnitude. Mk(i) is the matrix corresponding to the square of
           the voltage magnitude at bus i.
       YLINEFT : Function to create the matrix for the active power flow
           on the specified line, measured from the "from" bus to the "to" 
           bus. Ylineft(i) is the matrix corresponding to the active power
           flow on the line mpc.branch(i,:).
       YLINETF : Function to create the matrix for the active power flow
           on the specified line, measured from the "to" bus to the "from" 
           bus. Ylinetf(i) is the matrix corresponding to the active power
           flow on the line mpc.branch(i,:).
       Y_LINEFT : Function to create the matrix for the reactive power
           flow on the specified line, measured from the "from" bus to the 
           "to" bus. Ylineft(i) is the matrix corresponding to the
           reactive power flow on the line mpc.branch(i,:).
       Y_LINETF : Function to create the matrix for the reactive power
           flow on the specified line, measured from the "to" bus to the
           "from" bus. Ylineft(i) is the matrix corresponding to the
           reactive power flow on the line mpc.branch(i,:).
       YL : Function to create the matrix for the active power loss
           on the specified line (included for completeness, 
           not used in the OPF formulation)
       YL_ : Function to create the matrix for the reactive power loss
           on the specified line (included for completeness, 
           not used in the OPF formulation)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [Yk,Yk_,Mk,Ylineft,Ylinetf,Y_lineft,Y_linetf,YL,YL_] = makesdpmat(mpc)
0002 %MAKESDPMAT Creates the matrix functions used in the semidefinite
0003 %programming relaxation of the optimal power flow problem.
0004 %   [YK,YK_,MK,YLINEFT,YLINETF,Y_LINEFT,Y_LINETF] = MAKESDPMAT(MPC)
0005 %
0006 %   Creates functions that return the matrices used in the semidefinite
0007 %   programming relaxation of the optimal power flow problem.
0008 %
0009 %   Inputs:
0010 %       MPC : MATPOWER case variable with internal indexing.
0011 %
0012 %   Outputs:
0013 %       YK : Function to create the matrix for active power injection.
0014 %           Yk(i) is the matrix corresponding to the active power injection
0015 %           at bus i.
0016 %       YK_ : Function to create the matrix for reactive power injection.
0017 %           Yk_(i) is the matrix corresponding to the reactive power
0018 %           injection at bus i.
0019 %       MK : Function to create the matrix for the square of voltage
0020 %           magnitude. Mk(i) is the matrix corresponding to the square of
0021 %           the voltage magnitude at bus i.
0022 %       YLINEFT : Function to create the matrix for the active power flow
0023 %           on the specified line, measured from the "from" bus to the "to"
0024 %           bus. Ylineft(i) is the matrix corresponding to the active power
0025 %           flow on the line mpc.branch(i,:).
0026 %       YLINETF : Function to create the matrix for the active power flow
0027 %           on the specified line, measured from the "to" bus to the "from"
0028 %           bus. Ylinetf(i) is the matrix corresponding to the active power
0029 %           flow on the line mpc.branch(i,:).
0030 %       Y_LINEFT : Function to create the matrix for the reactive power
0031 %           flow on the specified line, measured from the "from" bus to the
0032 %           "to" bus. Ylineft(i) is the matrix corresponding to the
0033 %           reactive power flow on the line mpc.branch(i,:).
0034 %       Y_LINETF : Function to create the matrix for the reactive power
0035 %           flow on the specified line, measured from the "to" bus to the
0036 %           "from" bus. Ylineft(i) is the matrix corresponding to the
0037 %           reactive power flow on the line mpc.branch(i,:).
0038 %       YL : Function to create the matrix for the active power loss
0039 %           on the specified line (included for completeness,
0040 %           not used in the OPF formulation)
0041 %       YL_ : Function to create the matrix for the reactive power loss
0042 %           on the specified line (included for completeness,
0043 %           not used in the OPF formulation)
0044 
0045 %   MATPOWER
0046 %   $Id: makesdpmat.m 2272 2014-01-17 14:15:47Z ray $
0047 %   by Daniel Molzahn, PSERC U of Wisc, Madison
0048 %   Copyright (c) 2013-2014 by Power System Engineering Research Center (PSERC)
0049 %
0050 %   This file is part of MATPOWER.
0051 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0052 %
0053 %   MATPOWER is free software: you can redistribute it and/or modify
0054 %   it under the terms of the GNU General Public License as published
0055 %   by the Free Software Foundation, either version 3 of the License,
0056 %   or (at your option) any later version.
0057 %
0058 %   MATPOWER is distributed in the hope that it will be useful,
0059 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0060 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0061 %   GNU General Public License for more details.
0062 %
0063 %   You should have received a copy of the GNU General Public License
0064 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0065 %
0066 %   Additional permission under GNU GPL version 3 section 7
0067 %
0068 %   If you modify MATPOWER, or any covered work, to interface with
0069 %   other modules (such as MATLAB code and MEX-files) available in a
0070 %   MATLAB(R) or comparable environment containing parts covered
0071 %   under other licensing terms, the licensors of MATPOWER grant
0072 %   you additional permission to convey the resulting work.
0073 
0074 %% Setup
0075 
0076 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0077     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0078     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0079 
0080 mpc = loadcase(mpc);
0081 nbus = size(mpc.bus,1);
0082 Y = makeYbus(mpc);
0083 
0084 emat = speye(nbus);
0085 e = @(k) emat(:,k); % kth standard basis vector
0086 Yk_small = @(k) e(k)*e(k).'*Y;
0087 
0088 % Set tau == 0 to 1 (tau == 0 indicates nominal voltage ratio)
0089 mpc.branch(mpc.branch(:,TAP) == 0,TAP) = 1;
0090 
0091 %% Matrices used in SDP relaxation of OPF problem
0092 
0093 Yk = @(k) (1/2)*[real(Yk_small(k) + Yk_small(k).') imag(Yk_small(k).' - Yk_small(k));
0094     imag(Yk_small(k) - Yk_small(k).') real(Yk_small(k) + Yk_small(k).')];
0095 
0096 Yk_ = @(k) -(1/2)*[imag(Yk_small(k) + Yk_small(k).') real(Yk_small(k) - Yk_small(k).');
0097     real(Yk_small(k).' - Yk_small(k)) imag(Yk_small(k) + Yk_small(k).')];
0098 
0099 Mk = @(k) blkdiag(e(k)*e(k).', e(k)*e(k).');
0100 
0101 
0102 % For the line limit matrices, specify a line index corresponding to the
0103 % entries in mpc.branch
0104 gl = @(lineidx) real( 1 / (mpc.branch(lineidx,BR_R)+1i*mpc.branch(lineidx,BR_X))); % Real part of line admittance
0105 bl = @(lineidx) imag( 1 / (mpc.branch(lineidx,BR_R)+1i*mpc.branch(lineidx,BR_X))); % Imaginary part of line admittance
0106 bsl= @(lineidx) mpc.branch(lineidx,BR_B); % Line shunt susceptance
0107 Rl = @(lineidx) mpc.branch(lineidx,BR_R);
0108 Xl = @(lineidx) mpc.branch(lineidx,BR_X);
0109 
0110 % tau (col TAP)
0111 % theta (col SHIFT)
0112 % gbcosft = g*cos(theta)+b*cos(theta+pi/2)
0113 % gbsinft = g*sin(theta)+b*sin(theta+pi/2)
0114 % gbcostf = g*cos(-theta)+b*cos(-theta+pi/2)
0115 % gbsintf = g*sin(-theta)+b*sin(-theta+pi/2)
0116 
0117 tau = @(lineidx) mpc.branch(lineidx,TAP); 
0118 theta = @(lineidx) mpc.branch(lineidx,SHIFT)*pi/180;
0119 gbcosft = @(lineidx) gl(lineidx)*cos(theta(lineidx)) + bl(lineidx)*cos(theta(lineidx)+pi/2);
0120 gbsinft = @(lineidx) gl(lineidx)*sin(theta(lineidx)) + bl(lineidx)*sin(theta(lineidx)+pi/2);
0121 gbcostf = @(lineidx) gl(lineidx)*cos(-theta(lineidx)) + bl(lineidx)*cos(-theta(lineidx)+pi/2);
0122 gbsintf = @(lineidx) gl(lineidx)*sin(-theta(lineidx)) + bl(lineidx)*sin(-theta(lineidx)+pi/2);
0123 
0124 Ylineft = @(lidx) 0.5*(sparse(    [mpc.branch(lidx,F_BUS)     mpc.branch(lidx,F_BUS)     mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus  mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus ], ...
0125                                   [mpc.branch(lidx,F_BUS)     mpc.branch(lidx,T_BUS)     mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus  mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus ], ...
0126                                   [gl(lidx)/(tau(lidx)^2)     -gbcosft(lidx)/tau(lidx)   gbsinft(lidx)/tau(lidx)     gl(lidx)/(tau(lidx)^2)       -gbsinft(lidx)/tau(lidx)    -gbcosft(lidx)/tau(lidx)    ] ...
0127                                   ,2*nbus,2*nbus) + ...
0128                        sparse(    [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)     mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus  mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus ], ...
0129                                   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,T_BUS)     mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus  mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus ], ...
0130                                   [gl(lidx)/(tau(lidx)^2)    -gbcosft(lidx)/tau(lidx)   gbsinft(lidx)/tau(lidx)     gl(lidx)/(tau(lidx)^2)       -gbsinft(lidx)/tau(lidx)    -gbcosft(lidx)/tau(lidx)    ] ...
0131                                   ,2*nbus,2*nbus).');
0132                                                            
0133 Y_lineft = @(lidx) 0.5*(sparse(     [mpc.branch(lidx,F_BUS)                mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus            mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus ], ...
0134                                     [mpc.branch(lidx,F_BUS)                mpc.branch(lidx,T_BUS)    mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus            mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus ], ...
0135                                     [-(bl(lidx)+bsl(lidx)/2)/(tau(lidx)^2) gbsinft(lidx)/tau(lidx)   gbcosft(lidx)/tau(lidx)     -(bl(lidx)+bsl(lidx)/2)/(tau(lidx)^2)  -gbcosft(lidx)/tau(lidx)    gbsinft(lidx)/tau(lidx)     ] ...
0136                                   ,2*nbus,2*nbus) + ...
0137                         sparse(     [mpc.branch(lidx,F_BUS)                mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus           mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus ], ...
0138                                     [mpc.branch(lidx,F_BUS)                mpc.branch(lidx,T_BUS)    mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus           mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus ], ...
0139                                     [-(bl(lidx)+bsl(lidx)/2)/(tau(lidx)^2) gbsinft(lidx)/tau(lidx)   gbcosft(lidx)/tau(lidx)     -(bl(lidx)+bsl(lidx)/2)/(tau(lidx)^2) -gbcosft(lidx)/tau(lidx)    gbsinft(lidx)/tau(lidx)     ] ...
0140                                   ,2*nbus,2*nbus).');
0141 
0142 Ylinetf = @(lidx) 0.5*(sparse(    [mpc.branch(lidx,F_BUS)     mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,T_BUS) mpc.branch(lidx,T_BUS)+nbus ], ...
0143                                   [mpc.branch(lidx,T_BUS)     mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS) mpc.branch(lidx,T_BUS)+nbus ], ...
0144                                   [-gbcostf(lidx)/tau(lidx)   -gbsintf(lidx)/tau(lidx)    gbsintf(lidx)/tau(lidx)     -gbcostf(lidx)/tau(lidx)    gl(lidx)               gl(lidx)                    ] ...
0145                                   ,2*nbus,2*nbus) + ...
0146                        sparse(    [mpc.branch(lidx,F_BUS)     mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,T_BUS) mpc.branch(lidx,T_BUS)+nbus ], ...
0147                                   [mpc.branch(lidx,T_BUS)     mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS) mpc.branch(lidx,T_BUS)+nbus ], ...
0148                                   [-gbcostf(lidx)/tau(lidx)   -gbsintf(lidx)/tau(lidx)    gbsintf(lidx)/tau(lidx)     -gbcostf(lidx)/tau(lidx)    gl(lidx)               gl(lidx)                ] ...
0149                                   ,2*nbus,2*nbus).');
0150                               
0151 Y_linetf = @(lidx) 0.5*(sparse(   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,T_BUS)  mpc.branch(lidx,T_BUS)+nbus ], ...
0152                                   [mpc.branch(lidx,T_BUS)    mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS)  mpc.branch(lidx,T_BUS)+nbus ], ...
0153                                   [gbsintf(lidx)/tau(lidx)   -gbcostf(lidx)/tau(lidx)    gbcostf(lidx)/tau(lidx)     gbsintf(lidx)/tau(lidx)     -(bl(lidx)+bsl(lidx)/2) -(bl(lidx)+bsl(lidx)/2)     ] ...
0154                                   ,2*nbus,2*nbus) + ...
0155                        sparse(    [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,F_BUS)+nbus mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus ], ...
0156                                   [mpc.branch(lidx,T_BUS)    mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS)      mpc.branch(lidx,T_BUS)+nbus mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus ], ...
0157                                   [gbsintf(lidx)/tau(lidx)   -gbcostf(lidx)/tau(lidx)    gbcostf(lidx)/tau(lidx)     gbsintf(lidx)/tau(lidx)     -(bl(lidx)+bsl(lidx)/2)  -(bl(lidx)+bsl(lidx)/2)     ] ...
0158                                   ,2*nbus,2*nbus).');
0159                          
0160                               
0161 % Matrices to calculate active and reactive power line losses
0162 YL = @(lidx)          sparse(    [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus      mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)  mpc.branch(lidx,T_BUS)  mpc.branch(lidx,T_BUS)+nbus  mpc.branch(lidx,T_BUS)+nbus ], ...
0163                                   [mpc.branch(lidx,F_BUS)   mpc.branch(lidx,T_BUS)      mpc.branch(lidx,F_BUS)+nbus      mpc.branch(lidx,T_BUS)+nbus   mpc.branch(lidx,F_BUS)  mpc.branch(lidx,T_BUS)  mpc.branch(lidx,F_BUS)+nbus  mpc.branch(lidx,T_BUS)+nbus ], ...
0164                                   [1                        -1                          1                                -1                            -1                      1                       -1                           1                           ] ...
0165                                   ,2*nbus,2*nbus) * Rl(lidx)*(gl(lidx)^2+bl(lidx)^2);
0166                               
0167 YL_ = @(lidx)          sparse(    [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)      mpc.branch(lidx,F_BUS)+nbus      mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)  mpc.branch(lidx,T_BUS)  mpc.branch(lidx,T_BUS)+nbus  mpc.branch(lidx,T_BUS)+nbus ], ...
0168                                   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,T_BUS)      mpc.branch(lidx,F_BUS)+nbus      mpc.branch(lidx,T_BUS)+nbus   mpc.branch(lidx,F_BUS)  mpc.branch(lidx,T_BUS)  mpc.branch(lidx,F_BUS)+nbus  mpc.branch(lidx,T_BUS)+nbus ], ...
0169                                   [1                         -1                          1                                -1                            -1                      1                       -1                           1                           ] ...
0170                                   ,2*nbus,2*nbus) * Xl(lidx) * (gl(lidx)^2+bl(lidx)^2) + ...
0171                        -sparse(   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus   ], ...
0172                                   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus   ], ...
0173                                   [1                         1                             1                        1                             ] ...
0174                                   ,2*nbus,2*nbus) * bsl(lidx)/2;

Generated on Mon 26-Jan-2015 15:21:31 by m2html © 2005