
%% COMPUTE THE LWA..

L=zeros(5,9);
Ls=zeros(5,9);
figure
for k=1:5
    tempf_nega=Xs(k,1:2); %% MFs for the linguistic ratings
    tempf=Xs(k,3);
    temps=Xs(k,4);
    MFs1_nega=MFsf_nega(tempf_nega,:);
    MFs1=MFsf(tempf,:);
    MFs2=MFss(temps,:);
    MFs=[MFs1_nega; MFs1; MFs2];
    
    tempw1=Ws(1:2); %% MFs for the linguistic weights
    tempw2=Ws(3);
    tempw3=Ws(4);
    MFsw1=MFs_w(tempw1,:);
    MFsw2=MFs_ww(tempw2,:);
    MFsw3=MFs_w(tempw3,:);
    MFsw=[MFsw1; MFsw2; MFsw3]; 
        
    LWA=LWA9(MFs,MFsw); %% LWA
    %subplot(5,min(3,counter),k)
    subplot(5,1,k)
    set(gcf,'DefaulttextFontName','times new roman');
    set(gcf,'DefaultaxesFontName','times new roman');
    set(gcf,'DefaulttextFontAngle','italic');
    set(gcf,'DefaulttextFontSize',12);
    set(gcf,'DefaultlineLineWidth',1);
    set(gcf,'DefaultaxesLineWidth',1);
    fill(LWA([1:4 8:-1:5]),[0 1 1 0 0 LWA([9 9]) 0],[0.9,0.9,0.9]);
    hold on
    title(['alternative' num2str(k)]);
    switch k
        case 1
            title('The Commodity Market');
        case 2
            title('The Stock Market');
        case 3
            title('Gold and/or Diamonds');
        case 4
            title('Real Estate');
        case 5
            title('Long-term Bonds');
    end
    plot(LWA([1:4 8:-1:5]),[0 1 1 0 0 LWA([9 9]) 0],'linewidth',1.5);
    axis tight
    axis([0,10,0,1]);
    set(gca,'xtick',[0:10]);
    L(k,:)=LWA;
    [Cs(k), Cl(k), Cr(k)]=centroidIT2(LWA); %% centriod
    hold on;
end

disp('         ');    
disp('(1) Ranking and the Centroid - Center, [Left bound, Right bound]');
disp('      ');

figure
[Cs,index]=sort(Cs);  %% Sort the center of the centroid
Cl=Cl(index);
Cr=Cr(index);

a=zeros(5,1);
a=index;
L=L(index,:);
x1=[];x2=[];x3=[];x4=[];x5=[];
%% Ranking for the five alternatives
for k=1:5
    subplot(5,1,k)
    
    %subplot(5,min(3,counter),k)
    set(gcf,'DefaulttextFontName','times new roman');
    set(gcf,'DefaultaxesFontName','times new roman');
    set(gcf,'DefaulttextFontAngle','italic');
    set(gcf,'DefaulttextFontSize',12);
    fill(L(6-k,[1:4 8:-1:5]),[0 1 1 0 0 LWA([9 9]) 0],[0.9,0.9,0.9]);
    hold on
    % fill(MFs(index,[1:4 8:-1:5]),[0 1 1 0 0 MFs(index,[9 9]) 0],[0.9,0.9,0.9]);
    plot(L(6-k,[1:4 8:-1:5]),[0 1 1 0 0 LWA([9 9]) 0],'linewidth',1.5);
    % plot(MFs(index,[1:4 8:-1:5]),[0 1 1 0 0 MFs(index,[9 9]) 0],'--','linewidth',1.5);
    axis tight
    axis([0,10,0,1]);
    switch k
        case 1
            ylabel('FIRST');
        case 2
            ylabel('SECOND');
        case 3
            ylabel('THIRD');
        case 4
            ylabel('FORTH');
        case 5
            ylabel('FIFTH');
    end
    switch a(6-k)
        case 1
            title('The Commodity Market');
            disp([num2str(k) ': The Commodity Market - ' num2str(Cs(6-k),'%2.2f') ', [' num2str(Cl(6-k),'%2.2f') ',' num2str(Cr(6-k),'%2.2f') ']']); 
            x1=[Cs(6-k) Cl(6-k)  Cr(6-k)];
        case 2
            title('The Stock Market');
            disp([num2str(k) ': The Stock Market - ' num2str(Cs(6-k),'%2.2f') ',[' num2str(Cl(6-k),'%2.2f') ',' num2str(Cr(6-k),'%2.2f') ']']);
            x2=[Cs(6-k) Cl(6-k)  Cr(6-k)];
        case 3
            title('Gold and/or Diamonds');
            disp([num2str(k) ': Gold and/or Diamonds - ' num2str(Cs(6-k),'%2.2f') ',[' num2str(Cl(6-k),'%2.2f') ',' num2str(Cr(6-k),'%2.2f') ']']);
            x3=[Cs(6-k) Cl(6-k)  Cr(6-k)];
        case 4
            title('Real Estate');
            disp([num2str(k) ': Real Estate - ' num2str(Cs(6-k),'%2.2f') ',[' num2str(Cl(6-k),'%2.2f') ',' num2str(Cr(6-k),'%2.2f') ']']);
            x4=[Cs(6-k) Cl(6-k)  Cr(6-k)];
        case 5
            title('Long-term Bonds');
            disp([num2str(k) ': Long-term Bonds - ' num2str(Cs(6-k),'%2.2f') ',[' num2str(Cl(6-k),'%2.2f') ',' num2str(Cr(6-k),'%2.2f') ']']);
            x5=[Cs(6-k) Cl(6-k)  Cr(6-k)];
    end
   %title(['alternative' num2str(a(6-k))]);
    Ls(k,:)=L(6-k,:);
     % axis([0, 11, 0, 1.4]);
    % text('Interpreter','latex','String','$$\widetilde{Y}_{LWA}$$','Position',[LWA(2)+.2,1.15]);
    % axis([0,11,0,1.4]);
    set(gca,'xtick',[0:10]);  
    hold on
end

global xxs xxl xxr


xxs=[x1(1); x2(1); x3(1); x4(1); x5(1)]; %%Ranking Band
xxl=[x1(2); x2(2); x3(2); x4(2); x5(2)];
xxr=[x1(3); x2(3); x3(3); x4(3); x5(3)];
xxsm=[10-x1(1); 10-x2(1); 10-x3(1); 10-x4(1); 10-x5(1)]; %% RIsk Band
xxsl=[10-x1(2); 10-x2(2); 10-x3(2); 10-x4(2); 10-x5(2)];
xxsr=[10-x1(3); 10-x2(3); 10-x3(3); 10-x4(3); 10-x5(3)];

[xxs,index]=sort(xxs);
xxl=xxl(index);
xxr=xxr(index);
xxsm=xxsm(index);
xxsl=xxsl(index);
xxsr=xxsr(index);

figure
title('Ranking Band')
for i=1:5
    subplot(5,1,i)
    %subplot(5,min(3,counter),i)
    set(gcf,'DefaulttextFontName','times new roman');
    set(gcf,'DefaultaxesFontName','times new roman');
    set(gcf,'DefaulttextFontAngle','italic');
    set(gcf,'DefaulttextFontSize',12);
    plot(xxs(6-i),1,'b*', 'linewidth', 3); hold on; grid on;
    plot([xxl(6-i) xxr(6-i)],[1 1], 'b-','linewidth',1.5); hold on;
    axis tight
    axis([0,10,0.5,1.5]);
    switch a(6-i)
        case 1
            title('The Commodity Market');
        case 2
            title('The Stock Market');
        case 3
            title('Gold and/or Diamonds');
        case 4
            title('Real Estate');
        case 5
            title('Long-term Bonds');
    end
    switch i
        case 1
            ylabel('FIRST');
        case 2
            ylabel('SECOND');
        case 3
            ylabel('THIRD');
        case 4
            ylabel('FORTH');
        case 5
            ylabel('FIFTH');
    end
end

%% Risk Band
figure
title('Risk Band')
for i=1:5
    subplot(5,1,i)
   % subplot(5,min(3,counter),i)
    set(gcf,'DefaulttextFontName','times new roman');
    set(gcf,'DefaultaxesFontName','times new roman');
    set(gcf,'DefaulttextFontAngle','italic');
    set(gcf,'DefaulttextFontSize',12);
    plot(xxsm(6-i),1,'b*', 'linewidth', 3); hold on; grid on;
    plot([xxsl(6-i) xxsr(6-i)],[1 1], 'b-','linewidth',1.5); hold on;
    axis tight
    axis([0,10,0.5,1.5]);
    switch a(6-i)
        case 1
            title('The Commodity Market');
        case 2
            title('The Stock Market');
        case 3
            title('Gold and/or Diamonds');
        case 4
            title('Real Estate');
        case 5
            title('Long-term Bonds');
    end
    switch i
        case 1
            ylabel('FIRST');
        case 2
            ylabel('SECOND');
        case 3
            ylabel('THIRD');
        case 4
            ylabel('FORTH');
        case 5
            ylabel('FIFTH');
    end
end


%% Jacard Similarity
S=zeros(5,5);
for i=1:5
    for k=1:5
        S(i,k)=Jaccard(Ls(i,:), Ls(k,:));
    end
end

disp('  ');
disp('  ');
disp('(2) Similarity matrix for alternatives S');
S

