Commit a4537ba8 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

misc.permute2blockTriangle: new method for frobenius form of digraphs

parent 7765fb90
function [triangularMatrix, permutationMatrix] = permute2blockTriangle(A)
% MISC.PERMUTE2BLOCKTRIANGLE permutes the matrix A, if possible, to a lower block triangular matrix.
% The implementation is based on using methods for digraphs, see matlab documentation for digraph.
%
% triangularMatrix = misc.permute2blockTriangle(A) calculates a permutation of A
%
% [triangularMatrix, permutationMatrix] = misc.permute2blockTriangle(A) also returns the
% permutation matrix such that
% triangularMatrix = permutationMatrix * A * permutationMatrix.'
%
% Note that inv(permutationMatrix) = permutationMatrix.' (which holds for all so-called
% permutation matrices).
% conncomp computes strongly connected components of a graph, i.e. irreducible components. Those
% will result in the block-diagonal elements of the triangularMatrix. Hence, conncomp is used to
% find which elements shall be grouped together..
myDiagraph = digraph(A);
[agentsBlockNumber, blockSize] = myDiagraph.conncomp();
% As agentsBlockNumber defines which agent belongs to which group, the following for loop defines
% how they will be sorted.
sortIdx = zeros(size(A, 1), 1);
for blockIdx = numel(blockSize) : -1 : 1
sortIdx(sum(blockSize(numel(blockSize):-1:(blockIdx+1))) + (1:blockSize(blockIdx)), 1) ...
= find(agentsBlockNumber - blockIdx == 0);
end
permutationMatrix = full(sparse(1:1:size(A, 1), sortIdx, 1));
triangularMatrix = permutationMatrix * A * permutationMatrix.';
end % permute2blockTriangle()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment