% Recursive algorithm to find MCM vectors
% Thanks to Melih Bilmez
% 1.6.2020 
%Mustak Yalcin
clear all;

mNum = 4;
G = [-1 0 -1 -1; 4 -1 0 -1; 5 -1 -1 0; 5 -1 -1 -1]; % Same as L1 in LPM
Gd = -1.*G;

f = zeros(mNum,mNum+1);

f(:,1) = [0 inf inf inf]'; % reference vector

for m = 1:1:mNum
   
    for j = 1:1:mNum
       
        %find I set
        I = Gd(:,j) ~= 1;
        f(j,m+1) = min(f(I,m) + Gd(I,j));
        
    end
    
end

% find iteration bound
tableRow = zeros(1,mNum);
maxElement = tableRow;

% Table for (f(d)(i) - f(m)(i))/(d-m)
for i = 1:1:mNum
    
    for m = 1:1:mNum
    
        tableRow(m) = (f(i,mNum+1) - f(i,m))/(mNum-(m-1));
        
    end
    
    maxElement(i) = max(tableRow);
    
end

% Compute itearation bound
T_inf = -1*min(maxElement);