Home > matpower7.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-2019, Power Systems Engineering Research Center (PSERC)
0047 %   by Daniel Molzahn, PSERC U of Wisc, Madison
0048 %
0049 %   This file is part of MATPOWER/mx-sdp_pf.
0050 %   Covered by the 3-clause BSD License (see LICENSE file for details).
0051 %   See https://github.com/MATPOWER/mx-sdp_pf/ 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 if have_fcn('octave')
0064     emat = full(speye(nbus));
0065 else
0066     emat = speye(nbus);
0067 end
0068 e = @(k) emat(:,k); % kth standard basis vector
0069 Yk_small = @(k) e(k)*e(k).'*Y;
0070 
0071 % Set tau == 0 to 1 (tau == 0 indicates nominal voltage ratio)
0072 mpc.branch(mpc.branch(:,TAP) == 0,TAP) = 1;
0073 
0074 %% Matrices used in SDP relaxation of OPF problem
0075 
0076 Yk = @(k) (1/2)*[real(Yk_small(k) + Yk_small(k).') imag(Yk_small(k).' - Yk_small(k));
0077     imag(Yk_small(k) - Yk_small(k).') real(Yk_small(k) + Yk_small(k).')];
0078 
0079 Yk_ = @(k) -(1/2)*[imag(Yk_small(k) + Yk_small(k).') real(Yk_small(k) - Yk_small(k).');
0080     real(Yk_small(k).' - Yk_small(k)) imag(Yk_small(k) + Yk_small(k).')];
0081 
0082 Mk = @(k) blkdiag(e(k)*e(k).', e(k)*e(k).');
0083 
0084 
0085 % For the line limit matrices, specify a line index corresponding to the
0086 % entries in mpc.branch
0087 gl = @(lineidx) real( 1 / (mpc.branch(lineidx,BR_R)+1i*mpc.branch(lineidx,BR_X))); % Real part of line admittance
0088 bl = @(lineidx) imag( 1 / (mpc.branch(lineidx,BR_R)+1i*mpc.branch(lineidx,BR_X))); % Imaginary part of line admittance
0089 bsl= @(lineidx) mpc.branch(lineidx,BR_B); % Line shunt susceptance
0090 Rl = @(lineidx) mpc.branch(lineidx,BR_R);
0091 Xl = @(lineidx) mpc.branch(lineidx,BR_X);
0092 
0093 % tau (col TAP)
0094 % theta (col SHIFT)
0095 % gbcosft = g*cos(theta)+b*cos(theta+pi/2)
0096 % gbsinft = g*sin(theta)+b*sin(theta+pi/2)
0097 % gbcostf = g*cos(-theta)+b*cos(-theta+pi/2)
0098 % gbsintf = g*sin(-theta)+b*sin(-theta+pi/2)
0099 
0100 tau = @(lineidx) mpc.branch(lineidx,TAP); 
0101 theta = @(lineidx) mpc.branch(lineidx,SHIFT)*pi/180;
0102 gbcosft = @(lineidx) gl(lineidx)*cos(theta(lineidx)) + bl(lineidx)*cos(theta(lineidx)+pi/2);
0103 gbsinft = @(lineidx) gl(lineidx)*sin(theta(lineidx)) + bl(lineidx)*sin(theta(lineidx)+pi/2);
0104 gbcostf = @(lineidx) gl(lineidx)*cos(-theta(lineidx)) + bl(lineidx)*cos(-theta(lineidx)+pi/2);
0105 gbsintf = @(lineidx) gl(lineidx)*sin(-theta(lineidx)) + bl(lineidx)*sin(-theta(lineidx)+pi/2);
0106 
0107 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 ], ...
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                        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 ], ...
0112                                   [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 ], ...
0113                                   [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)    ] ...
0114                                   ,2*nbus,2*nbus).');
0115                                                            
0116 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 ], ...
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                         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 ], ...
0121                                     [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 ], ...
0122                                     [-(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)     ] ...
0123                                   ,2*nbus,2*nbus).');
0124 
0125 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 ], ...
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                        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 ], ...
0130                                   [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 ], ...
0131                                   [-gbcostf(lidx)/tau(lidx)   -gbsintf(lidx)/tau(lidx)    gbsintf(lidx)/tau(lidx)     -gbcostf(lidx)/tau(lidx)    gl(lidx)               gl(lidx)                ] ...
0132                                   ,2*nbus,2*nbus).');
0133                               
0134 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 ], ...
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                        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 ], ...
0139                                   [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 ], ...
0140                                   [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)     ] ...
0141                                   ,2*nbus,2*nbus).');
0142                          
0143                               
0144 % Matrices to calculate active and reactive power line losses
0145 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 ], ...
0146                                   [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 ], ...
0147                                   [1                        -1                          1                                -1                            -1                      1                       -1                           1                           ] ...
0148                                   ,2*nbus,2*nbus) * Rl(lidx)*(gl(lidx)^2+bl(lidx)^2);
0149                               
0150 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 ], ...
0151                                   [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 ], ...
0152                                   [1                         -1                          1                                -1                            -1                      1                       -1                           1                           ] ...
0153                                   ,2*nbus,2*nbus) * Xl(lidx) * (gl(lidx)^2+bl(lidx)^2) + ...
0154                        -sparse(   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus   ], ...
0155                                   [mpc.branch(lidx,F_BUS)    mpc.branch(lidx,F_BUS)+nbus   mpc.branch(lidx,T_BUS)   mpc.branch(lidx,T_BUS)+nbus   ], ...
0156                                   [1                         1                             1                        1                             ] ...
0157                                   ,2*nbus,2*nbus) * bsl(lidx)/2;

Generated on Mon 24-Jun-2019 15:58:45 by m2html © 2005