Home > matpower6.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 %   Copyright (c) 2013-2016, Power Systems Engineering Research Center (PSERC)
0047 %   by Daniel Molzahn, PSERC U of Wisc, Madison
0048 %
0049 %   This file is part of MATPOWER.
0050 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0051 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0052 
0053 %% Setup
0054 
0055 [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
0056     TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
0057     ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
0058 
0059 mpc = loadcase(mpc);
0060 nbus = size(mpc.bus,1);
0061 Y = makeYbus(mpc);
0062 
0063 emat = speye(nbus);
0064 e = @(k) emat(:,k); % kth standard basis vector
0065 Yk_small = @(k) e(k)*e(k).'*Y;
0066 
0067 % Set tau == 0 to 1 (tau == 0 indicates nominal voltage ratio)
0068 mpc.branch(mpc.branch(:,TAP) == 0,TAP) = 1;
0069 
0070 %% Matrices used in SDP relaxation of OPF problem
0071 
0072 Yk = @(k) (1/2)*[real(Yk_small(k) + Yk_small(k).') imag(Yk_small(k).' - Yk_small(k));
0073     imag(Yk_small(k) - Yk_small(k).') real(Yk_small(k) + Yk_small(k).')];
0074 
0075 Yk_ = @(k) -(1/2)*[imag(Yk_small(k) + Yk_small(k).') real(Yk_small(k) - Yk_small(k).');
0076     real(Yk_small(k).' - Yk_small(k)) imag(Yk_small(k) + Yk_small(k).')];
0077 
0078 Mk = @(k) blkdiag(e(k)*e(k).', e(k)*e(k).');
0079 
0080 
0081 % For the line limit matrices, specify a line index corresponding to the
0082 % entries in mpc.branch
0083 gl = @(lineidx) real( 1 / (mpc.branch(lineidx,BR_R)+1i*mpc.branch(lineidx,BR_X))); % Real part of line admittance
0084 bl = @(lineidx) imag( 1 / (mpc.branch(lineidx,BR_R)+1i*mpc.branch(lineidx,BR_X))); % Imaginary part of line admittance
0085 bsl= @(lineidx) mpc.branch(lineidx,BR_B); % Line shunt susceptance
0086 Rl = @(lineidx) mpc.branch(lineidx,BR_R);
0087 Xl = @(lineidx) mpc.branch(lineidx,BR_X);
0088 
0089 % tau (col TAP)
0090 % theta (col SHIFT)
0091 % gbcosft = g*cos(theta)+b*cos(theta+pi/2)
0092 % gbsinft = g*sin(theta)+b*sin(theta+pi/2)
0093 % gbcostf = g*cos(-theta)+b*cos(-theta+pi/2)
0094 % gbsintf = g*sin(-theta)+b*sin(-theta+pi/2)
0095 
0096 tau = @(lineidx) mpc.branch(lineidx,TAP); 
0097 theta = @(lineidx) mpc.branch(lineidx,SHIFT)*pi/180;
0098 gbcosft = @(lineidx) gl(lineidx)*cos(theta(lineidx)) + bl(lineidx)*cos(theta(lineidx)+pi/2);
0099 gbsinft = @(lineidx) gl(lineidx)*sin(theta(lineidx)) + bl(lineidx)*sin(theta(lineidx)+pi/2);
0100 gbcostf = @(lineidx) gl(lineidx)*cos(-theta(lineidx)) + bl(lineidx)*cos(-theta(lineidx)+pi/2);
0101 gbsintf = @(lineidx) gl(lineidx)*sin(-theta(lineidx)) + bl(lineidx)*sin(-theta(lineidx)+pi/2);
0102 
0103 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 ], ...
0104                                   [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 ], ...
0105                                   [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)    ] ...
0106                                   ,2*nbus,2*nbus) + ...
0107                        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 ], ...
0108                                   [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 ], ...
0109                                   [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)    ] ...
0110                                   ,2*nbus,2*nbus).');
0111                                                            
0112 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 ], ...
0113                                     [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 ], ...
0114                                     [-(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)     ] ...
0115                                   ,2*nbus,2*nbus) + ...
0116                         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 ], ...
0117                                     [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 ], ...
0118                                     [-(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)     ] ...
0119                                   ,2*nbus,2*nbus).');
0120 
0121 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 ], ...
0122                                   [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 ], ...
0123                                   [-gbcostf(lidx)/tau(lidx)   -gbsintf(lidx)/tau(lidx)    gbsintf(lidx)/tau(lidx)     -gbcostf(lidx)/tau(lidx)    gl(lidx)               gl(lidx)                    ] ...
0124                                   ,2*nbus,2*nbus) + ...
0125                        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 ], ...
0126                                   [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 ], ...
0127                                   [-gbcostf(lidx)/tau(lidx)   -gbsintf(lidx)/tau(lidx)    gbsintf(lidx)/tau(lidx)     -gbcostf(lidx)/tau(lidx)    gl(lidx)               gl(lidx)                ] ...
0128                                   ,2*nbus,2*nbus).');
0129                               
0130 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 ], ...
0131                                   [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 ], ...
0132                                   [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)     ] ...
0133                                   ,2*nbus,2*nbus) + ...
0134                        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 ], ...
0135                                   [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 ], ...
0136                                   [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)     ] ...
0137                                   ,2*nbus,2*nbus).');
0138                          
0139                               
0140 % Matrices to calculate active and reactive power line losses
0141 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 ], ...
0142                                   [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 ], ...
0143                                   [1                        -1                          1                                -1                            -1                      1                       -1                           1                           ] ...
0144                                   ,2*nbus,2*nbus) * Rl(lidx)*(gl(lidx)^2+bl(lidx)^2);
0145                               
0146 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 ], ...
0147                                   [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 ], ...
0148                                   [1                         -1                          1                                -1                            -1                      1                       -1                           1                           ] ...
0149                                   ,2*nbus,2*nbus) * Xl(lidx) * (gl(lidx)^2+bl(lidx)^2) + ...
0150                        -sparse(   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus   ], ...
0151                                   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus   ], ...
0152                                   [1                         1                             1                        1                             ] ...
0153                                   ,2*nbus,2*nbus) * bsl(lidx)/2;

Generated on Fri 16-Dec-2016 12:45:37 by m2html © 2005