function [ D ] = mssp(src_idx, dst_idx, adjmat, sssp)
%%MSSP(src_idx, dst_idx, adjmat, sssp) Solves a multi-source shortest path
% problem. Computes a matrix of distances from sources with indices
% src_idx to destinations with indices dst_idx over an adjacency matrix
% adjmat using the single-source shortest path solver sssp. If |src_idx| > |dst_idx|,
% then adjmat has been transposed prior to passing to this function. For example,
% if sssp expected a transposed adjmat (like most of them do, to efficiently walk
% along the columns), then adjmat may be the original adjacency matrix in such
% a case (transposed transpose).

reverse = length(src_idx) > length(dst_idx);
if(reverse)
    temp = src_idx;
    src_idx = dst_idx;
    dst_idx = temp;
    clear temp;
end

D = zeros(length(src_idx), length(dst_idx));
for isrc = 1 : length(src_idx)
    src = src_idx(isrc);
    dists = sssp(adjmat, src);
    D(isrc, :) = dists(dst_idx);
end

if(reverse)
    D = D';
end

end
