https://github.com/HTDerekLiu/SpecCoarsen_MATLAB
Raw File
Tip revision: 749b4bf2aa89143c0b50c9a2a50a6fbd6b115919 authored by HTDerekLiu on 12 September 2019, 16:56:12 UTC
update number of eVec in use
Tip revision: 749b4bf
matrixBellmanFord.m
function [dist, nearestCenter] = matrixBellmanFord(SoC, centersIdx)
% MATRIXBELLMANFORD performs matrix bellman ford algorithm to compute the
% shortest graph distance for every node to a given set of center points
%
% Reference: 
% Bell, Algebraic Multigrid for Discrete Differential Forms, 2008
%
% [dist, nearestCenter] = matrixBellmanFord(A, centerIdx)
%
% Inputs:
%   SoC |V| x |V| matrix of strength of connections 
%   centersIdx #centers vector of indices of the centers
% Outputs:
%   dist a |V| vector of the graph distance to the closest center point
%   nearestCenter a |V| vector of indices of the nearest center point


% initialize dist and nearestCenter
nV = size(SoC,1);
dist = Inf(nV,1);
nearestCenter = zeros(nV,1);

% set center indices
dist(centersIdx) = 0;
nearestCenter(centersIdx) = centersIdx;

% iterate through all the non-zeros in the system matrix A
[i,j,dij] = find(SoC);

while true
    idx = find( (dist(i)+dij) < dist(j));
    if size(idx,1) ~= 0
        dist(j(idx)) = dist(i(idx)) + dij(idx);
        nearestCenter(j(idx)) = nearestCenter(i(idx));
    else
        break;
    end 
end
end
back to top