Cohort Intelligence MATLAB Code for Optimization of CFRP Composites for Aerospace Applications

MATLAB Code of Cohort Intelligence Algorithm with Alienation variation for Optimization of cutting forces for Micro Drilling Process of CFRP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear allclcticc = 5;  % number of candidatesn = 2;   % number of dimensionsupper_bound = [39.2 5];     lower_bound = [15.7 1];
max_iterations = 1500;for cnt_runs = 1:1x = (upper_bound - lower_bound).*rand(c,n) + lower_bound; % random value generationrange = upper_bound - lower_bound;                       % original range calculationcnt_iterations =1;        while (cnt_iterations <= max_iterations) % loop for max iterations%            if cnt_iterations < 200               r = 0.99;%            else%                r = 0.8;%            end                       for cnt_candi = 1:c            Fun(cnt_candi,:)= fx (x(cnt_candi,1:n)); % call objective function here          end                 inverse_F = Fun.^-1;                     % 1/fxn         denominator_pc = sum(inverse_F,1);     %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation                 for cnt_pc = 1:c            prob1(cnt_pc,1) = inverse_F(cnt_pc,1)/denominator_pc; % probability pc1,...,pcm         end                 pcsum = sum(prob1);  % checking cummulative sum = 1?                         [prob , c_follow1] = sort(prob1,'descend');         for cnt_candi = 1:c            c_unfollow(cnt_candi) = RouletteWheelSelection(prob1); %  Roulette Wheel            c_unfollow1(cnt_candi) = c_unfollow(cnt_candi);        end         for cnt_candi = 1:c                          c_unfollow1(cnt_candi)=[];             msize = numel(c_unfollow1);             idx = randperm(msize);             c_follow(cnt_candi)= c_unfollow1(idx(1:1));             c_unfollow1= c_unfollow;%             ww(cnt_candi,:) =  find(cnt_candi~=c_unfollow(cnt_candi));          end                 [M,I] = min(Fun);            Fbest(1,:) = M(1, :);            xvect_best(:,:) = x(I(1),:);                   % x vector for all best         new_matrix = x(c_follow,:); % new matrix generation          range = r*range;                for cnt_column = 1:n            if abs(range(cnt_column))> 1e-8               new_range =  range/2;              else              new_range =  1e-8;              end            end              for cnt_row = 1:c            for cnt_column = 1:n                 new_lower_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)- new_range(cnt_column);                 new_upper_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)+ new_range(cnt_column);            end               end              for cnt_row = 1:c            for cnt_column = 1:n                 if new_lower_bound(cnt_row,cnt_column) < lower_bound(1,cnt_column)                      new_lower_bound(cnt_row,cnt_column) = lower_bound(1,cnt_column);                 end                     if new_upper_bound(cnt_row,cnt_column) > upper_bound(1,cnt_column)                     new_upper_bound(cnt_row,cnt_column) = upper_bound(1,cnt_column) ;                 end              end                end                  x = (new_upper_bound -new_lower_bound).*rand(c,n) + new_lower_bound;        x(c,:) = xvect_best;        if (cnt_iterations <= max_iterations)               function_all(:,cnt_iterations) = abs(Fbest);               cnt_all (cnt_iterations) = cnt_iterations;               x_all(:,:,cnt_iterations) =  x;               end               hold on;               cnt_iterations = cnt_iterations + 1;    end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     figure(1)%                  xlabel('Learning attempts','FontSize',12)%                  ylabel('Behavior','FontSize',12)%                plot(cnt_all,function_all(1,:),'k*');%                plot(cnt_all,function_all(2,:),'ko');%                plot(cnt_all,function_all(3,:),'k+');%                plot(cnt_all,function_all(4,:),'k.');%                plot(cnt_all,function_all(5,:),'ks');%                   legend ('candi1','candi2','candi3','candi4','candi5');% %                %pause(2);% %                hold on;%            %  % %     end

toc;
time_elapsed = toc;
 end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MATLAB Code of Cohort Intelligence Algorithm with Follow Best for Optimization of cutting forces for Micro Drilling Process of CFRP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5;  % number of candidatesn = 2;   % number of dimensionsupper_bound = [39.2 5];     lower_bound = [15.7 1];
max_iterations = 700;for cnt_runs = 1:1x = (upper_bound - lower_bound).*rand(c,n) + lower_bound; % random value generationrange = upper_bound - lower_bound;                       % original range calculationcnt_iterations = 1;        while (cnt_iterations <= max_iterations) % loop for max iterations%            if cnt_iterations < 20%               r = 0.99;% %            else              r = 0.95;%            end                       for cnt_candi = 1:c            Fun(cnt_candi,:)= fx (x(cnt_candi,1:n)); % call objective function here          end                 inverse_F = Fun.^-1;                     % 1/fxn         denominator_pc = sum(inverse_F,1);     %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation                 for cnt_pc = 1:c            prob1(cnt_pc,1) = inverse_F(cnt_pc,1)/denominator_pc; % probability pc1,...,pcm         end                 pcsum = sum(prob1);  % checking cummulative sum = 1?         for cnt_candi = 1:c            c_follow(cnt_candi) = RouletteWheelSelection(prob1); %  Roulette Wheel         end                 [prob , c_follow1] = sort(prob1,'ascend');        for i = 1:c            c_follow(i)= c_follow1(c);        end                    [M,I] = min(Fun);            Fbest(1,:) = M(1, :);            xvect_best(:,:) = x(I(1),:);                     new_matrix = x(c_follow,:); % new matrix generation          range = r*range;                for cnt_column = 1:n            if abs(range(cnt_column))> 1e-16               new_range =  range/2;              else              new_range =  1e-16;              end            end              for cnt_row = 1:c            for cnt_column = 1:n                 new_lower_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)- new_range(cnt_column);                 new_upper_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)+ new_range(cnt_column);            end               end              for cnt_row = 1:c            for cnt_column = 1:n                 if new_lower_bound(cnt_row,cnt_column) < lower_bound(1,cnt_column)                      new_lower_bound(cnt_row,cnt_column) = lower_bound(1,cnt_column);                 end                     if new_upper_bound(cnt_row,cnt_column) > upper_bound(1,cnt_column)                     new_upper_bound(cnt_row,cnt_column) = upper_bound(1,cnt_column) ;                 end              end                end                  x = (new_upper_bound -new_lower_bound).*rand(c,n) + new_lower_bound;                        if (cnt_iterations <= max_iterations)               function_all(:,cnt_iterations) = abs(Fbest);               cnt_all (cnt_iterations) = cnt_iterations;               x_all(:,:,cnt_iterations) =  x;               end               hold on;               cnt_iterations = cnt_iterations + 1;    end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     figure(1)%                  xlabel('Learning attempts','FontSize',12)%                  ylabel('Behavior','FontSize',12)%                plot(cnt_all,function_all(1,:),'k*');%                plot(cnt_all,function_all(2,:),'ko');%                plot(cnt_all,function_all(3,:),'k+');%                plot(cnt_all,function_all(4,:),'k.');%                plot(cnt_all,function_all(5,:),'ks');%                   legend ('candi1','candi2','candi3','candi4','candi5');% %                %pause(2);% %                hold on;%            %  % %     end

toc;
time_elapsed = toc;
 end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MATLAB Code of Cohort Intelligence Algorithm with Follow Better for Optimization of cutting forces for Micro Drilling Process of CFRP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5;  % number of candidatesn = 2;   % number of dimensionsupper_bound = [39.2 5];     lower_bound = [15.7 1];
max_iterations = 1100;for cnt_runs = 1:1x = (upper_bound - lower_bound).*rand(c,n) + lower_bound; % random value generationrange = upper_bound - lower_bound;                       % original range calculationcnt_iterations =1;        while (cnt_iterations <= max_iterations) % loop for max iterations%            if cnt_iterations < 20%               r = 0.99;% %            else              r = 0.99;%            end                       for cnt_candi = 1:c            Fun(cnt_candi,:)= fx (x(cnt_candi,1:n)); % call objective function here          end                 inverse_F = Fun.^-1;                     % 1/fxn         denominator_pc = sum(inverse_F,1);     %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation                 for cnt_pc = 1:c            prob1(cnt_pc,1) = inverse_F(cnt_pc,1)/denominator_pc; % probability pc1,...,pcm         end                 pcsum = sum(prob1);  % checking cummulative sum = 1?         for cnt_candi = 1:c            c_follow(cnt_candi) = RouletteWheelSelection(prob1); %  Roulette Wheel         end                 [prob , c_follow1] = sort(prob1,'ascend');        for i = 1:c-1            c_follow(i)= c_follow1(i+1);        end            for i = c             c_follow(i)= c_follow1(i);          end         [M,I] = min(Fun);            Fbest(1,:) = M(1, :);            xvect_best(:,:) = x(I(1),:);                   % x vector for all best         new_matrix = x(c_follow,:); % new matrix generation          range = r*range;                for cnt_column = 1:n            if abs(range(cnt_column))> 1e-16               new_range =  range/2;              else              new_range =  1e-16;              end            end              for cnt_row = 1:c            for cnt_column = 1:n                 new_lower_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)- new_range(cnt_column);                 new_upper_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)+ new_range(cnt_column);            end               end              for cnt_row = 1:c            for cnt_column = 1:n                 if new_lower_bound(cnt_row,cnt_column) < lower_bound(1,cnt_column)                      new_lower_bound(cnt_row,cnt_column) = lower_bound(1,cnt_column);                 end                     if new_upper_bound(cnt_row,cnt_column) > upper_bound(1,cnt_column)                     new_upper_bound(cnt_row,cnt_column) = upper_bound(1,cnt_column) ;                 end              end                end                  x = (new_upper_bound -new_lower_bound).*rand(c,n) + new_lower_bound;                      if (cnt_iterations <= max_iterations)               function_all(:,cnt_iterations) =  abs(Fbest);               cnt_all (cnt_iterations) = cnt_iterations;               x_all(:,:,cnt_iterations) =  x;               end               hold on;               cnt_iterations = cnt_iterations + 1;    end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     figure(1)%                  xlabel('Learning attempts','FontSize',12)%                  ylabel('Behavior','FontSize',12)%                plot(cnt_all,function_all(1,:),'k*');%                plot(cnt_all,function_all(2,:),'ko');%                plot(cnt_all,function_all(3,:),'k+');%                plot(cnt_all,function_all(4,:),'k.');%                plot(cnt_all,function_all(5,:),'ks');%                   legend ('candi1','candi2','candi3','candi4','candi5');% %                %pause(2);% %                hold on;%            %  % %     end

toc;
time_elapsed = toc;
 end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MATLAB Code of Cohort Intelligence Algorithm with Roulette Wheel for Optimization of cutting forces for Micro Drilling Process of CFRP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5;  % number of candidatesn = 2;   % number of dimensionsupper_bound = [39.2 5];     lower_bound = [15.7 1];r = 0.99;max_iterations = 500;for cnt_runs = 1:1x = (upper_bound - lower_bound).*rand(c,n) + lower_bound; % random value generationrange = upper_bound - lower_bound;                       % original range calculationcnt_iterations = 1;        while (cnt_iterations <= max_iterations) % loop for max iterations                     for cnt_candi = 1:c            Fun(cnt_candi,:)= fx (x(cnt_candi,1:n)); % call objective function here          end                 inverse_F = Fun.^-1;                     % 1/fxn         denominator_pc = sum(inverse_F,1);     %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation                 for cnt_pc = 1:c            prob(cnt_pc,1) = inverse_F(cnt_pc,1)/denominator_pc; % probability pc1,...,pcm         end                 pcsum = sum(prob);  % checking cummulative sum = 1?                            for cnt_candi = 1:c            c_follow(cnt_candi) = RouletteWheelSelection(prob);          end                 [M,I] = min(Fun);            Fbest(1,:) = M(1, :);            xvect_best(:,:) = x(I(1),:);                   % x vector for all best         new_matrix = x(c_follow,:); % new matrix generation          range = r*range;                for cnt_column = 1:n            if abs(range(cnt_column))> 1e-16               new_range =  range/2;              else              new_range =  1e-16;              end            end              for cnt_row = 1:c            for cnt_column = 1:n                 new_lower_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)- new_range(cnt_column);                 new_upper_bound(cnt_row,cnt_column) = new_matrix(cnt_row,cnt_column)+ new_range(cnt_column);            end               end              for cnt_row = 1:c            for cnt_column = 1:n                 if new_lower_bound(cnt_row,cnt_column) < lower_bound(1,cnt_column)                      new_lower_bound(cnt_row,cnt_column) = lower_bound(1,cnt_column);                 end                     if new_upper_bound(cnt_row,cnt_column) > upper_bound(1,cnt_column)                     new_upper_bound(cnt_row,cnt_column) = upper_bound(1,cnt_column) ;                 end              end                end                  x = (new_upper_bound -new_lower_bound).*rand(c,n) + new_lower_bound;        x(c,:) = xvect_best;                                    if (cnt_iterations <= max_iterations)               function_all(:,cnt_iterations) = abs(Fbest);               cnt_all (cnt_iterations) = cnt_iterations;               x_all(:,:,cnt_iterations) =  x;               end               hold on;               cnt_iterations = cnt_iterations + 1;    end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     if (rem(cnt_iterations,1)==0)%         stop_1=1;%     end%     figure(1)%                  xlabel('Learning attempts','FontSize',12)%                  ylabel('Behavior','FontSize',12)%                plot(cnt_all,function_all(1,:),'k*');%                plot(cnt_all,function_all(2,:),'ko');%                plot(cnt_all,function_all(3,:),'k+');%                plot(cnt_all,function_all(4,:),'k.');%                plot(cnt_all,function_all(5,:),'ks');%                   legend ('candi1','candi2','candi3','candi4','candi5');% %                %pause(2);% %                hold on;%            %  % %     end

toc;
time_elapsed = toc;
 end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%% Roulette Wheel Selection Code %%%%%%%%%%%%%%%%%%%%%%%%
function choice = RouletteWheelSelection(prob) total = cumsum(prob); p = rand() * total(end); leader = -1; for index = 1:length(total)   if (total(index) > p)     leader = index;     break;   end end choice = leader;
%%%%%%%%%%%%%%%%%%% Objective Functions %%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% Fx %%%%%%%%%%%%%%%%%%%%%%%%%function y = microdrill(x)y = 0.38607 - 0.014983*x(1)- 0.1322*x(2)+ 0.0012*x(1)* x(2) + 0.0003*x(1)*x(1) + 0.019583*x(2)*x(2);end
%%%%%%%%%%%%%%%%%%%%% Fy %%%%%%%%%%%%%%%%%%%%%%%%%function y = microdrill(x)y = 0.25371 - 0.00375*x(1) -0.12116*x(2)+0.00063*x(1)*x(2)+0.000093*x(1)*x(1)+0.021*x(2)*x(2);end
%%%%%%%%%%%%%%%%%%%%% Fz %%%%%%%%%%%%%%%%%%%%%%%%%function y = microdrill(x)y = 0.64841+0.078424*x(1)+0.59493*x(2)-0.0017*x(1)*x(2)-0.0009*x(1)*x(1)-0.0204*x(2)*x(2);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%