Cohort Intelligence MATLAB Code for Micro Milling Process
Reference for above sketchesHayajneh, M. T., Tahat, M. S., & Bluhm, J. (2007). A study of the effects of machining parameters on the surface roughness in the end-milling process. Jordan Journal of Mechanical and Industrial Engineering, 1(1), pp. 1-5
Lu, X., Jia, Z., Wang, H., Si, L., Liu, Y., & Wu, W. (2016). Tool wear appearance and failure mechanism of coated carbide tools in micro-milling of Inconel 718 super alloy. Industrial Lubrication and Tribology, 68(2), pp. 267-277
Lu, X., Jia, Z., Wang, H., Si, L., Liu, Y., & Wu, W. (2016). Tool wear appearance and failure mechanism of coated carbide tools in micro-milling of Inconel 718 super alloy. Industrial Lubrication and Tribology, 68(2), pp. 267-277
MATLAB Code of Cohort Intelligence Algorithm with Alienation variation for Optimization of Surface Roughness (Ra) and Machining Time (Mt) of Micromilling Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra_milling(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 variation for Optimization of Surface Roughness (Ra) and Machining Time (Mt) of Micromilling Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra(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 variation for Optimization of Surface Roughness (Ra) and Machining Time (Mt) of Micromilling Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra(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 variation for Optimization of Surface Roughness (Ra) and Machining Time (Mt) of Micromilling Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra(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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MATLAB Code of Multi-Cohort Intelligence Algorithm for Optimization of Surface Roughness (Ra) and Kerf of AWJM Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Multi-Cohort Intelligence: An Intra- and Inter-group Learning and Competing Behavior %%%% Apoorva Shastri and Anand J Kulkarni %%% -------------------------------------------------------------------------% INITIALIZATION% -------------------------------------------------------------------------
close allclear allclcc = 5; % number of candidates n = 2; % number of variablesk = 3; % number of cohortsupper_bound1 = 2500; upper bound of variable 1 lower_bound1 = 1500; lower bound of variable 1 upper_bound2 = 3; upper bound of variable 2 lower_bound2 = 1; lower bound of variable 2
r = 0.99; % interval reduction factormax_iterations = 200; tk = 10; %quality variations for nonpool tpool = 5; %quality variations for poolZtkpool = 15;
for cnt_runs = 1:1 x1 = (upper_bound1 -lower_bound1).*rand(c,1,k) + lower_bound1; % random value generationx2 = (upper_bound2 -lower_bound2).*rand(c,1,k) + lower_bound2; % random value generationx = cat(2,x1,x2);
range1 = upper_bound1 -lower_bound1; % original range calculationrange2 = upper_bound2 -lower_bound2; % original range calculation
upper_bound = cat(2,upper_bound1,upper_bound2);lower_bound = cat(2,lower_bound1,lower_bound2);tic; for cnt_iterations=1:max_iterations % creating a pool of best candidates for cnt_cohort = 1:k for cnt_candi = 1:c Fun(cnt_candi,:,cnt_cohort) = Mt_time(x(cnt_candi,:,cnt_cohort));% call objective function here end% z(cnt_cohort)= min(Fun(cnt_candi,:,cnt_cohort)); end
[M,I] = min(Fun); Fbest = M; pool(1,:) = M(1, :); poolZ = pool'; In(1,:) = I(1, :); for cnt_cohort = 1:k xvect_best1(:,:,cnt_cohort) = x(In(1,cnt_cohort),:,cnt_cohort); % x vector for all best [x_nonpool(:,:,cnt_cohort),PS]= removerows(x(:,:,cnt_cohort),[I(cnt_cohort)]); [fun_non_pool_X(:,:,cnt_cohort),PS]= removerows(Fun(:,:,cnt_cohort),[I(cnt_cohort)]); end A(:,:) = xvect_best1(1, :); xvect_best = vec2mat(A,n);% xvect_best_final cell generated for concatenation
% -------------------------------------------------------------------------% -------------------------------------------------------------------------% procedure for tk% ------------------------------------------------------------------------- for cnt_cohort = 1:k inverse_F(:,:,cnt_cohort) = fun_non_pool_X(:,:,cnt_cohort).^-1; % 1/fxn denominator_pc(:,1,cnt_cohort) = sum(inverse_F(:,:,cnt_cohort),1); %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation prob(:,1,cnt_cohort) = inverse_F(:,1,cnt_cohort)/denominator_pc(:,1,cnt_cohort); % probability pc1,...,pcm % pcsum = cumsum(prob(cnt_cohort)); % checking cummulative sum = 1?
for cnt_candi = 1:c-1 c_follow(cnt_candi) = RouletteWheelSelection(prob(:,1,cnt_cohort)); % Roulette Wheel end nmatrix = x_nonpool(c_follow,:,cnt_cohort); % new matrix generation new_matrix{1,cnt_cohort} = nmatrix; end % display(new_matrix(cnt_cohort)) range1 = r * range1; % range reduced by reduction factor r range2 = r * range2; new_range1 = range1/2; new_range2 = range2/2; new_range = cat(2,new_range1,new_range2); new_range(new_range <= 10^-22)= 10^-10;
for cnt_cohort = 1: k for cnt_candi = 1:c-1 for cnt_variables = 1:n new_upper_bound_tk = new_matrix{cnt_cohort}(:,cnt_variables)+ new_range(:,cnt_variables); new_lower_bound_tk = new_matrix{cnt_cohort}(:,cnt_variables)- new_range(:,cnt_variables); new_upper_bound_tk(new_upper_bound_tk > new_range(:,cnt_variables)) = upper_bound(:,cnt_variables); new_lower_bound_tk(new_lower_bound_tk < new_range(:,cnt_variables)) = lower_bound(:,cnt_variables);
for cnt_tk = 1:tk n_x(cnt_tk,cnt_variables)= (new_upper_bound_tk(cnt_candi,1)- new_lower_bound_tk(cnt_candi,1)) * rand(1,1) + new_lower_bound_tk(cnt_candi,1); end end
x_tk{cnt_cohort} = n_x;
end end % -------------------------------------------------------------------------% -------------------------------------------------------------------------% procedure for tpool% -------------------------------------------------------------------------for cnt_cohort = 1:k inverse_F_poolZ = poolZ.^-1; % 1/fxn denominator_pc_tpoolZ = sum(inverse_F_poolZ,1); %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation prob_tpoolZ= inverse_F_poolZ/denominator_pc_tpoolZ; % probability pc1,...,pcm for cnt_candi = 1:c-1 c_follow_tpoolZ(cnt_candi) = RouletteWheelSelection(prob_tpoolZ); % Roulette Wheel end% nmatrix_tpool = xvect_best(:,:,c_follow_tpoolZ); nmatrix_tpool = xvect_best(c_follow_tpoolZ,:);% new matrix generation new_matrix_tpool{1,cnt_cohort} = nmatrix_tpool; end % display(new_matrix(cnt_cohort))
for cnt_cohort = 1: k for cnt_candi = 1:c-1 for cnt_variables = 1:n new_upper_bound_tpool = new_matrix_tpool{cnt_cohort}(:,cnt_variables)+ new_range(:,cnt_variables); new_lower_bound_tpool = new_matrix_tpool{cnt_cohort}(:,cnt_variables)- new_range(:,cnt_variables); new_upper_bound_tpool(new_upper_bound_tpool > new_range(:,cnt_variables)) = upper_bound(:,cnt_variables); new_lower_bound_tpool( new_lower_bound_tpool < new_range(:,cnt_variables)) = lower_bound(:,cnt_variables); for cnt_tpool = 1:tpool x_tp(cnt_tpool,cnt_variables)= (new_upper_bound_tpool(cnt_candi,1)- new_lower_bound_tpool(cnt_candi,1)) * rand(1,1) + new_lower_bound_tpool(cnt_candi,1); end end x_tpool{cnt_cohort} = x_tp; end end
for cnt_cohort = 1:k for cnt_candi = 1:c-1 x_tpool_tk{cnt_candi,cnt_cohort} = cat(1,x_tk{1,cnt_cohort}, x_tpool{1,cnt_cohort}); end end
for cnt_cohort = 1:k for cnt_candi = 1:c-1 y(:,:,cnt_cohort)= x_tpool_tk{cnt_candi,cnt_cohort}; for cnt_tkpool = 1:tkpool Fun1(cnt_tkpool,:) = Mt_time(y(cnt_tkpool,:)); end [Mf,If] = min(Fun1); Fmin(cnt_candi,:,cnt_cohort) = Mf; xbest = (y(If,:,cnt_cohort)); xi(cnt_candi,:,cnt_cohort) = xbest; end end for cnt_cohort = 1:k F_x(:,:,cnt_cohort) = cat(1, Fmin(:,:,cnt_cohort), Fbest(:,:,cnt_cohort)); end A1(:,:) = F_x(:, :); Fun1_all = reshape(A1,tkpool,1); [f,I] = min(F_x);
f_final(1,:) = f(1, :); f_final_out = f_final'
minima = min(f_final_out) for cnt_cohort = 1:k x(:,:,cnt_cohort) = cat(1, xi(:,:,cnt_cohort), xvect_best1(:,:,cnt_cohort)); end function_all(:,cnt_iterations) = f_final_out; function_all_plot(:,cnt_iterations) = Fun1_all; hold on; cnt_itera_p(cnt_iterations)= cnt_iterations; end %% Multi-CI convergence plot for cnt_1 = 1:5 fun_cohort1(cnt_1,:)= function_all_plot(cnt_1,:) end for cnt_2 = 6:10 fun_cohort2(cnt_2,:)= function_all_plot(cnt_2,:) end for cnt_3 = 11:15 fun_cohort3(cnt_3,:)= function_all_plot(cnt_3,:) 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('Function values','FontSize',12)
plot(cnt_itera_p,function_all(1,:),'k'); legend('cohort1'); plot(cnt_itera_p,function_all(2,:),'k--'); legend('cohort2'); plot(cnt_itera_p,function_all(3,:),'k:'); legend('cohort3'); 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 %%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%% Tool Dia 0.7 mm %%%%%%%%%%%%%%%%%%%%%%%%%%
function y1 = Ra_milling(x)y1 = -0.455378+0.000270*x(1)+0.164220*x(2)-0.000077*x(1)*x(2);end%%%%%%%%%%%%%%%%%%%%%% Tool Dia 1 mm %%%%%%%%%%%%%%%%%%%%%%%%%%
function y1 = Ra_milling(x)y1 = -0.208871+0.000144*x(1)+0.019571*x(2);end%%%%%%%%%%%%%%%%%%%%%% Tool Dia 0.7 mm %%%%%%%%%%%%%%%%%%%%%%%%%%function y1 = Mt_time(x)y1 = 17.7164-0.0002*x(1)-4.8404*x(2)+0.0001*x(1)*x(2);end%%%%%%%%%%%%%%%%%%%%%%%%% Tool Dia 1 mm %%%%%%%%%%%%%%%%%%%%%%%%%%function y1 = Mt_time(x)y1 = 20.2906-0.0015*x(1)-5.8369*x(2)+0.0006*x(1)*x(2);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra_milling(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 variation for Optimization of Surface Roughness (Ra) and Machining Time (Mt) of Micromilling Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra(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 variation for Optimization of Surface Roughness (Ra) and Machining Time (Mt) of Micromilling Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra(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 variation for Optimization of Surface Roughness (Ra) and Machining Time (Mt) of Micromilling Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear allclcticc = 5; % number of candidatesn = 2; % number of dimensionsupper_bound = [2500 3]; lower_bound = [1500 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,:)= Ra(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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MATLAB Code of Multi-Cohort Intelligence Algorithm for Optimization of Surface Roughness (Ra) and Kerf of AWJM Process
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Multi-Cohort Intelligence: An Intra- and Inter-group Learning and Competing Behavior %%%% Apoorva Shastri and Anand J Kulkarni %%% -------------------------------------------------------------------------% INITIALIZATION% -------------------------------------------------------------------------
close allclear allclcc = 5; % number of candidates n = 2; % number of variablesk = 3; % number of cohortsupper_bound1 = 2500; upper bound of variable 1 lower_bound1 = 1500; lower bound of variable 1 upper_bound2 = 3; upper bound of variable 2 lower_bound2 = 1; lower bound of variable 2
r = 0.99; % interval reduction factormax_iterations = 200; tk = 10; %quality variations for nonpool tpool = 5; %quality variations for poolZtkpool = 15;
for cnt_runs = 1:1 x1 = (upper_bound1 -lower_bound1).*rand(c,1,k) + lower_bound1; % random value generationx2 = (upper_bound2 -lower_bound2).*rand(c,1,k) + lower_bound2; % random value generationx = cat(2,x1,x2);
range1 = upper_bound1 -lower_bound1; % original range calculationrange2 = upper_bound2 -lower_bound2; % original range calculation
upper_bound = cat(2,upper_bound1,upper_bound2);lower_bound = cat(2,lower_bound1,lower_bound2);tic; for cnt_iterations=1:max_iterations % creating a pool of best candidates for cnt_cohort = 1:k for cnt_candi = 1:c Fun(cnt_candi,:,cnt_cohort) = Mt_time(x(cnt_candi,:,cnt_cohort));% call objective function here end% z(cnt_cohort)= min(Fun(cnt_candi,:,cnt_cohort)); end
[M,I] = min(Fun); Fbest = M; pool(1,:) = M(1, :); poolZ = pool'; In(1,:) = I(1, :); for cnt_cohort = 1:k xvect_best1(:,:,cnt_cohort) = x(In(1,cnt_cohort),:,cnt_cohort); % x vector for all best [x_nonpool(:,:,cnt_cohort),PS]= removerows(x(:,:,cnt_cohort),[I(cnt_cohort)]); [fun_non_pool_X(:,:,cnt_cohort),PS]= removerows(Fun(:,:,cnt_cohort),[I(cnt_cohort)]); end A(:,:) = xvect_best1(1, :); xvect_best = vec2mat(A,n);% xvect_best_final cell generated for concatenation
% -------------------------------------------------------------------------% -------------------------------------------------------------------------% procedure for tk% ------------------------------------------------------------------------- for cnt_cohort = 1:k inverse_F(:,:,cnt_cohort) = fun_non_pool_X(:,:,cnt_cohort).^-1; % 1/fxn denominator_pc(:,1,cnt_cohort) = sum(inverse_F(:,:,cnt_cohort),1); %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation prob(:,1,cnt_cohort) = inverse_F(:,1,cnt_cohort)/denominator_pc(:,1,cnt_cohort); % probability pc1,...,pcm % pcsum = cumsum(prob(cnt_cohort)); % checking cummulative sum = 1?
for cnt_candi = 1:c-1 c_follow(cnt_candi) = RouletteWheelSelection(prob(:,1,cnt_cohort)); % Roulette Wheel end nmatrix = x_nonpool(c_follow,:,cnt_cohort); % new matrix generation new_matrix{1,cnt_cohort} = nmatrix; end % display(new_matrix(cnt_cohort)) range1 = r * range1; % range reduced by reduction factor r range2 = r * range2; new_range1 = range1/2; new_range2 = range2/2; new_range = cat(2,new_range1,new_range2); new_range(new_range <= 10^-22)= 10^-10;
for cnt_cohort = 1: k for cnt_candi = 1:c-1 for cnt_variables = 1:n new_upper_bound_tk = new_matrix{cnt_cohort}(:,cnt_variables)+ new_range(:,cnt_variables); new_lower_bound_tk = new_matrix{cnt_cohort}(:,cnt_variables)- new_range(:,cnt_variables); new_upper_bound_tk(new_upper_bound_tk > new_range(:,cnt_variables)) = upper_bound(:,cnt_variables); new_lower_bound_tk(new_lower_bound_tk < new_range(:,cnt_variables)) = lower_bound(:,cnt_variables);
for cnt_tk = 1:tk n_x(cnt_tk,cnt_variables)= (new_upper_bound_tk(cnt_candi,1)- new_lower_bound_tk(cnt_candi,1)) * rand(1,1) + new_lower_bound_tk(cnt_candi,1); end end
x_tk{cnt_cohort} = n_x;
end end % -------------------------------------------------------------------------% -------------------------------------------------------------------------% procedure for tpool% -------------------------------------------------------------------------for cnt_cohort = 1:k inverse_F_poolZ = poolZ.^-1; % 1/fxn denominator_pc_tpoolZ = sum(inverse_F_poolZ,1); %denominator calucated((1/fx(c1)+...+1/fx(cn)) for probability calculation prob_tpoolZ= inverse_F_poolZ/denominator_pc_tpoolZ; % probability pc1,...,pcm for cnt_candi = 1:c-1 c_follow_tpoolZ(cnt_candi) = RouletteWheelSelection(prob_tpoolZ); % Roulette Wheel end% nmatrix_tpool = xvect_best(:,:,c_follow_tpoolZ); nmatrix_tpool = xvect_best(c_follow_tpoolZ,:);% new matrix generation new_matrix_tpool{1,cnt_cohort} = nmatrix_tpool; end % display(new_matrix(cnt_cohort))
for cnt_cohort = 1: k for cnt_candi = 1:c-1 for cnt_variables = 1:n new_upper_bound_tpool = new_matrix_tpool{cnt_cohort}(:,cnt_variables)+ new_range(:,cnt_variables); new_lower_bound_tpool = new_matrix_tpool{cnt_cohort}(:,cnt_variables)- new_range(:,cnt_variables); new_upper_bound_tpool(new_upper_bound_tpool > new_range(:,cnt_variables)) = upper_bound(:,cnt_variables); new_lower_bound_tpool( new_lower_bound_tpool < new_range(:,cnt_variables)) = lower_bound(:,cnt_variables); for cnt_tpool = 1:tpool x_tp(cnt_tpool,cnt_variables)= (new_upper_bound_tpool(cnt_candi,1)- new_lower_bound_tpool(cnt_candi,1)) * rand(1,1) + new_lower_bound_tpool(cnt_candi,1); end end x_tpool{cnt_cohort} = x_tp; end end
for cnt_cohort = 1:k for cnt_candi = 1:c-1 x_tpool_tk{cnt_candi,cnt_cohort} = cat(1,x_tk{1,cnt_cohort}, x_tpool{1,cnt_cohort}); end end
for cnt_cohort = 1:k for cnt_candi = 1:c-1 y(:,:,cnt_cohort)= x_tpool_tk{cnt_candi,cnt_cohort}; for cnt_tkpool = 1:tkpool Fun1(cnt_tkpool,:) = Mt_time(y(cnt_tkpool,:)); end [Mf,If] = min(Fun1); Fmin(cnt_candi,:,cnt_cohort) = Mf; xbest = (y(If,:,cnt_cohort)); xi(cnt_candi,:,cnt_cohort) = xbest; end end for cnt_cohort = 1:k F_x(:,:,cnt_cohort) = cat(1, Fmin(:,:,cnt_cohort), Fbest(:,:,cnt_cohort)); end A1(:,:) = F_x(:, :); Fun1_all = reshape(A1,tkpool,1); [f,I] = min(F_x);
f_final(1,:) = f(1, :); f_final_out = f_final'
minima = min(f_final_out) for cnt_cohort = 1:k x(:,:,cnt_cohort) = cat(1, xi(:,:,cnt_cohort), xvect_best1(:,:,cnt_cohort)); end function_all(:,cnt_iterations) = f_final_out; function_all_plot(:,cnt_iterations) = Fun1_all; hold on; cnt_itera_p(cnt_iterations)= cnt_iterations; end %% Multi-CI convergence plot for cnt_1 = 1:5 fun_cohort1(cnt_1,:)= function_all_plot(cnt_1,:) end for cnt_2 = 6:10 fun_cohort2(cnt_2,:)= function_all_plot(cnt_2,:) end for cnt_3 = 11:15 fun_cohort3(cnt_3,:)= function_all_plot(cnt_3,:) 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('Function values','FontSize',12)
plot(cnt_itera_p,function_all(1,:),'k'); legend('cohort1'); plot(cnt_itera_p,function_all(2,:),'k--'); legend('cohort2'); plot(cnt_itera_p,function_all(3,:),'k:'); legend('cohort3'); 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 %%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%% Tool Dia 0.7 mm %%%%%%%%%%%%%%%%%%%%%%%%%%
function y1 = Ra_milling(x)y1 = -0.455378+0.000270*x(1)+0.164220*x(2)-0.000077*x(1)*x(2);end%%%%%%%%%%%%%%%%%%%%%% Tool Dia 1 mm %%%%%%%%%%%%%%%%%%%%%%%%%%
function y1 = Ra_milling(x)y1 = -0.208871+0.000144*x(1)+0.019571*x(2);end%%%%%%%%%%%%%%%%%%%%%% Tool Dia 0.7 mm %%%%%%%%%%%%%%%%%%%%%%%%%%function y1 = Mt_time(x)y1 = 17.7164-0.0002*x(1)-4.8404*x(2)+0.0001*x(1)*x(2);end%%%%%%%%%%%%%%%%%%%%%%%%% Tool Dia 1 mm %%%%%%%%%%%%%%%%%%%%%%%%%%function y1 = Mt_time(x)y1 = 20.2906-0.0015*x(1)-5.8369*x(2)+0.0006*x(1)*x(2);end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%