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

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