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

mat2vec

PURPOSE ^

MAT2VEC Converts a SDP matrix into a a list form used in the matrix

SYNOPSIS ^

function [sdpvec]=mat2vec(sdpmat, Wref_dd, Wref_qq, Wref_dq, matidx_dd, matidx_qq, matidx_dq)

DESCRIPTION ^

MAT2VEC Converts a SDP matrix into a a list form used in the matrix
completion decomposition.
   [SDPVEC] = MAT2VEC(SDPMAT, WREF_DD, WREF_QQ, WREF_DQ, MATIDX_DD,MATIDX_QQ, MATIDX_DQ)

   Used in the formation of the matrix completion decomposition for the
   semidefinite programming relaxation of the optimal power flow. Converts
   a 2*nbus by 2*nbus symmetric matrix sdpmat into a list form. For each
   nonzero element of sdpmat, the list form in sdpvec gives the
   appropriate matrix, the location in the matrix, and the value for that
   element.

   Inputs:
       SDPMAT : Symmetric 2*nbus by 2*nbus matrix (intended to be Yk, Yk_,
           Mk, Ylineft, Ylinetf, Y_lineft, Y_linetf from the semidefinite
           programming relaxation).
       WREF_DD : Matrix with three columns. The first column is a 
           numbering 1:size(Wref_dd,1). The second and third columns 
           indicate the row and column indices of the elements of the 
           matrix sdpmat, with the row of Wref_dd corresponding to the 
           index of matidx_dd. That is, the element of sdpmat located in 
           row Wref_dd(i,1), column Wref_dd(i,2) corresponds to 
           matidx_dd(i).
       WREF_QQ : Similar to Wref_dd, except for the qq entries of sdpmat.
       WREF_DQ : Similar to Wref_dd, except for the dq entries of sdpmat.
       MATIDX_DD : Matrix with three columns. Row i of matidx_dd indicates
           the location of sdpmat(Wref_dd(i,1), Wref_dd(i,2)). The first
           column indicates the index of the corresponding matrix. The
           second and third columns indicate the row and column,
           respectively, of the corresponding matrix. 
       MATIDX_QQ : Similar to matidx_dd, except corresponding to the qq 
           entries of sdpmat.
       MATIDX_DQ : Similar to matidx_dd, except corresponding to the dq 
           entries of sdpmat.

   Outputs:
       SDPVEC : A matrix with four columns, with a row for each nonzero
           element of sdpmat. The first column gives the index of the
           decomposed matrix. The second and third columns give the row
           and column, respectively, of the appropriate entry of the
           decomposed matrix. The fourth column is the value of the entry.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [sdpvec]=mat2vec(sdpmat, Wref_dd, Wref_qq, Wref_dq, matidx_dd, matidx_qq, matidx_dq)
0002 %MAT2VEC Converts a SDP matrix into a a list form used in the matrix
0003 %completion decomposition.
0004 %   [SDPVEC] = MAT2VEC(SDPMAT, WREF_DD, WREF_QQ, WREF_DQ, MATIDX_DD,MATIDX_QQ, MATIDX_DQ)
0005 %
0006 %   Used in the formation of the matrix completion decomposition for the
0007 %   semidefinite programming relaxation of the optimal power flow. Converts
0008 %   a 2*nbus by 2*nbus symmetric matrix sdpmat into a list form. For each
0009 %   nonzero element of sdpmat, the list form in sdpvec gives the
0010 %   appropriate matrix, the location in the matrix, and the value for that
0011 %   element.
0012 %
0013 %   Inputs:
0014 %       SDPMAT : Symmetric 2*nbus by 2*nbus matrix (intended to be Yk, Yk_,
0015 %           Mk, Ylineft, Ylinetf, Y_lineft, Y_linetf from the semidefinite
0016 %           programming relaxation).
0017 %       WREF_DD : Matrix with three columns. The first column is a
0018 %           numbering 1:size(Wref_dd,1). The second and third columns
0019 %           indicate the row and column indices of the elements of the
0020 %           matrix sdpmat, with the row of Wref_dd corresponding to the
0021 %           index of matidx_dd. That is, the element of sdpmat located in
0022 %           row Wref_dd(i,1), column Wref_dd(i,2) corresponds to
0023 %           matidx_dd(i).
0024 %       WREF_QQ : Similar to Wref_dd, except for the qq entries of sdpmat.
0025 %       WREF_DQ : Similar to Wref_dd, except for the dq entries of sdpmat.
0026 %       MATIDX_DD : Matrix with three columns. Row i of matidx_dd indicates
0027 %           the location of sdpmat(Wref_dd(i,1), Wref_dd(i,2)). The first
0028 %           column indicates the index of the corresponding matrix. The
0029 %           second and third columns indicate the row and column,
0030 %           respectively, of the corresponding matrix.
0031 %       MATIDX_QQ : Similar to matidx_dd, except corresponding to the qq
0032 %           entries of sdpmat.
0033 %       MATIDX_DQ : Similar to matidx_dd, except corresponding to the dq
0034 %           entries of sdpmat.
0035 %
0036 %   Outputs:
0037 %       SDPVEC : A matrix with four columns, with a row for each nonzero
0038 %           element of sdpmat. The first column gives the index of the
0039 %           decomposed matrix. The second and third columns give the row
0040 %           and column, respectively, of the appropriate entry of the
0041 %           decomposed matrix. The fourth column is the value of the entry.
0042 
0043 %   MATPOWER
0044 %   $Id: mat2vec.m 2272 2014-01-17 14:15:47Z ray $
0045 %   by Daniel Molzahn, PSERC U of Wisc, Madison
0046 %   Copyright (c) 2013-2014 by Power System Engineering Research Center (PSERC)
0047 %
0048 %   This file is part of MATPOWER.
0049 %   See http://www.pserc.cornell.edu/matpower/ for more info.
0050 %
0051 %   MATPOWER is free software: you can redistribute it and/or modify
0052 %   it under the terms of the GNU General Public License as published
0053 %   by the Free Software Foundation, either version 3 of the License,
0054 %   or (at your option) any later version.
0055 %
0056 %   MATPOWER is distributed in the hope that it will be useful,
0057 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0058 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0059 %   GNU General Public License for more details.
0060 %
0061 %   You should have received a copy of the GNU General Public License
0062 %   along with MATPOWER. If not, see <http://www.gnu.org/licenses/>.
0063 %
0064 %   Additional permission under GNU GPL version 3 section 7
0065 %
0066 %   If you modify MATPOWER, or any covered work, to interface with
0067 %   other modules (such as MATLAB code and MEX-files) available in a
0068 %   MATLAB(R) or comparable environment containing parts covered
0069 %   under other licensing terms, the licensors of MATPOWER grant
0070 %   you additional permission to convey the resulting work.
0071 
0072 %% Setup
0073 
0074 nbus = size(sdpmat,1) / 2;
0075 [matrow, matcol, matval] = find(triu(sdpmat));
0076 
0077 % To speed up this function, rather than search throuh the entire Wref_dd,
0078 % Wref_qq, Wref_dq vectors every time we look up a nonzero entry of sdpmat,
0079 % filter out the entries that will actually be used in the rest of the
0080 % function.
0081 
0082 dd_buses = unique([matrow(matrow <= nbus); matcol(matcol <= nbus)]);
0083 dd_rows = [];
0084 for i=1:length(dd_buses)
0085     dd_rows = [dd_rows; find(Wref_dd(:,2) == dd_buses(i) | Wref_dd(:,3) == dd_buses(i))];
0086 end
0087 Wref_dd = Wref_dd(dd_rows,:);
0088 
0089 qq_buses = unique([matrow(matrow > nbus); matcol(matcol > nbus)]) - nbus;
0090 qq_rows = [];
0091 for i=1:length(qq_buses)
0092     qq_rows = [qq_rows; find(Wref_qq(:,2) == qq_buses(i) | Wref_qq(:,3) == qq_buses(i))];
0093 end
0094 Wref_qq = Wref_qq(qq_rows,:);
0095 
0096 dq_buses = unique([matrow(matrow > nbus)-nbus; matcol(matcol > nbus)-nbus; matrow(matrow <= nbus); matcol(matcol <= nbus)]);
0097 dq_rows = [];
0098 for i=1:length(dq_buses)
0099     dq_rows = [dq_rows; find(Wref_dq(:,2) == dq_buses(i) | Wref_dq(:,3) == dq_buses(i))];
0100 end
0101 Wref_dq = Wref_dq(dq_rows,:);
0102 
0103 
0104 %% Form sdpvec
0105 
0106 sdpvec = zeros(2*length(matrow),4);
0107 idx = 0;
0108 for m = 1:length(matrow);
0109     idx = idx + 1;
0110     if matrow(m) <= nbus && matcol(m) <= nbus % In the dd section of the W matrix
0111         Wref_dd_row = find( (Wref_dd(:,2) == matrow(m) & Wref_dd(:,3) == matcol(m)) | ... 
0112                             (Wref_dd(:,3) == matrow(m) & Wref_dd(:,2) == matcol(m)), 1);
0113         sdpvec(idx,:) = [matidx_dd(Wref_dd(Wref_dd_row,1),1) matidx_dd(Wref_dd(Wref_dd_row,1),2) matidx_dd(Wref_dd(Wref_dd_row,1),3) matval(m)];
0114         idx = idx + 1;
0115         sdpvec(idx,:) = [matidx_dd(Wref_dd(Wref_dd_row,1),1) matidx_dd(Wref_dd(Wref_dd_row,1),3) matidx_dd(Wref_dd(Wref_dd_row,1),2) matval(m)];
0116     elseif matrow(m) > nbus && matcol(m) > nbus % In the qq section of the W matrix
0117         Wref_qq_row = find( (Wref_qq(:,2) == (matrow(m)-nbus) & Wref_qq(:,3) == (matcol(m))-nbus) | ...
0118                             (Wref_qq(:,3) == (matrow(m)-nbus) & Wref_qq(:,2) == (matcol(m)-nbus)), 1);
0119         sdpvec(idx,:) = [matidx_qq(Wref_qq(Wref_qq_row,1),1) matidx_qq(Wref_qq(Wref_qq_row,1),2) matidx_qq(Wref_qq(Wref_qq_row,1),3) matval(m)];
0120         idx = idx + 1;
0121         sdpvec(idx,:) = [matidx_qq(Wref_qq(Wref_qq_row,1),1) matidx_qq(Wref_qq(Wref_qq_row,1),3) matidx_qq(Wref_qq(Wref_qq_row,1),2) matval(m)];
0122     elseif (matrow(m) > nbus && matcol(m) <= nbus) % In the dq section of the W matrix
0123         Wref_dq_row = find(Wref_dq(:,3) == (matrow(m)-nbus) & Wref_dq(:,2) == matcol(m), 1);
0124         
0125         sdpvec(idx,:) = [matidx_dq(Wref_dq(Wref_dq_row,1),1) matidx_dq(Wref_dq(Wref_dq_row,1),2) matidx_dq(Wref_dq(Wref_dq_row,1),3) matval(m)];
0126         idx = idx + 1;
0127         sdpvec(idx,:) = [matidx_dq(Wref_dq(Wref_dq_row,1),1) matidx_dq(Wref_dq(Wref_dq_row,1),3) matidx_dq(Wref_dq(Wref_dq_row,1),2) matval(m)];
0128     elseif (matrow(m) <= nbus && matcol(m) > nbus) % In the dq section of the W matrix
0129         Wref_dq_row = find(Wref_dq(:,2) == matrow(m) & Wref_dq(:,3) == (matcol(m)-nbus), 1);
0130         
0131         sdpvec(idx,:) = [matidx_dq(Wref_dq(Wref_dq_row,1),1) matidx_dq(Wref_dq(Wref_dq_row,1),2) matidx_dq(Wref_dq(Wref_dq_row,1),3) matval(m)];
0132         idx = idx + 1;
0133         sdpvec(idx,:) = [matidx_dq(Wref_dq(Wref_dq_row,1),1) matidx_dq(Wref_dq(Wref_dq_row,1),3) matidx_dq(Wref_dq(Wref_dq_row,1),2) matval(m)];
0134     else
0135         error('mat2vec: Invalid matrow or matcol for bus %i',k);
0136     end
0137 end
0138 
0139 sdpvec = unique(sdpvec,'rows'); % Don't double count diagonals

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