function [objval DOF d01 d02 nfull nred Nsim]= dif_delta_mb_WCE(N,dibtype)
%% Solutions for a set of different reduced oreder models
% clc
% clear all
% close all

for Nsim =  10
nfull = 16;
nred  = 16;
% N = 8;  %prediction horizon
% dibtype = {[4 3 3]};
% dibtype = {[8] [7 2] [6 2 2] [5 2 2] [4 2 2 2 2] [3 2 2 2 2 2]};   %input blocking type for different calc.DOF 1-7 free last
% dibtype = {[8] [2 7] [2 2 6] [2 2 2 5] [2 2 2 2 4] [2 2 2 2 2 3]}; %input blocking type for different calc.DOF 1-7 free first
% dibtype = {[2 2 6] [2 3 5] [2 4 4]};   % compar input blocking types with same DOF = 4 a
% dibtype = {[6 2 2] [5 3 2] [4 4 2]};   % compar input blocking types with same DOF = 4 b
d01 = [];
d02 = [];
d0n = [];

%% calculation WCE of full model and reduced model using delat input blocking

        for i = 1:length(dibtype)
            [objval(i) d0 UR{i} UF{i} XR{i} XF{i} Nsim M{i} DOF(i)] = ...
                deltamoveblocking_onestep(Nsim,nfull,nred,N,double(dibtype{i}))
               
                d01 = [d01; d0(1,1)];
                d02 = [d02; d0(2,1)];
                d0n = [d0n; d0];
        end
    

d01 = double(d01);
d02 = double(d02);

%% ploting
% figure
% plot(DOF,objval,'LineWidth',2);
% xlabel('degrees of freedom (DOF)')
% ylabel('worst-case error (outputs)')
% title('Delta input blocking');
% hold on ;
% plot(DOF,objval,'r*');
% grid on;
% xlim([1.999999999 7])
% legend('DIB','dibtype = ([8], [7 2], [6 2 2], [5 2 2], [4 2 2 2 2], [3 2 2 2 2 2])')  % last free 
% % legend('DIB','dibtype = ([8], [2 7], [2 2 6], [2 2 2 5], [2 2 2 2 4], [2 2 2 2 2 3])')    % first free


%% plot u differences
% for IB = 1:length(dibtype)
% ur = UR{IB};
% ur = double(ur{1});
% % obtaining ur1, ur2 when we have nu = 2
% for i = 1 : (size(ur,1)/2)
% 
% j = i - 1;   
% ur1(i) = ur(2*j+1);    
% ur2(i) = ur(2*i);
% 
% end
% 
% figure;
% plot((1:1:N),ur1,'LineWidth',2);
% hold on
% plot((1:1:N),ur1,'*r');
% xlabel('u(i1)')
% ylabel('values')
% title('')
% grid on
% 
% figure;
% plot((1:1:N),ur2,'LineWidth',2);
% hold on
% plot((1:1:N),ur2,'*r');
% xlabel('u(i2)')
% ylabel('values')
% title('')
% grid on
% end

%% calculation to comapre different DIB types with same DOF

% %DOF = 4
% % colors for plot
% G = cell(5,1);
% G{1,1} = 'b*';
% G{2,1} = 'g*';
% G{3,1} = 'r*';
% G{4,1} = 'c*';
% G{5,1} = 'k*';
% G{6,1} = 'y*';
% 
% 
% % calculation for different IB types
% 
%     for i = 1:length(dibtype)
%         [objval(i) d0 UR{i} UF{i} XR{i} XF{i} Nsim M{i} DOF(i)] = ...
%             deltamoveblocking_onestep(Nsim,nfull,nred,N,double(dibtype{i}))
%         d01 = [d01; d0(1,1)];
%         d02 = [d02; d0(2,1)];
%         d0n = [d0n; d0];
%         % ploting
%         hold on;
%         plot(DOF(i),objval(i), G{i,1});
%         xlabel('degrees of freedom');
%         ylabel('worst case error (outputs)');
%         legend('DIB = [2 2 6]','DIB = [2 3 5]','DIB = [2 4 4]');
% %         legend('DIB = [6 2 2]','DIB = [5 3 2]','DIB = [4 4 2]');
%         grid on;
%     end

%% save Nsimtest.mat nred objval objval_scaling
% save(['IB_Nsim' num2str(Nsim) '.mat'])
% save(['IB_type' num2str() '.mat'])

end