Function definitions are not permitted at the prompt or in scripts.
lb=-100;
ub=100;
dim=10;function [RWs]=Random_walk_around_antlion(Dim,max_iter,lb, ub,antlion,current_iter) if size(lb,1) ==1 && size(lb,2)==1 %Check if the bounds are scalar lb=ones(1,Dim)*lb; ub=ones(1,Dim)*ub; end
if size(lb,1) > size(lb,2) %Check if boundary vectors are horizontal or vertical lb=lb'; ub=ub'; end
I=1; % I is the ratio
if current_iter>max_iter/10 I=1+100*(current_iter/max_iter); end
if current_iter>max_iter/2 I=1+1000*(current_iter/max_iter); end
if current_iter>max_iter*(3/4) I=1+10000*(current_iter/max_iter); end
if current_iter>max_iter*(0.9) I=1+100000*(current_iter/max_iter); end
if current_iter>max_iter*(0.95) I=1+1000000*(current_iter/max_iter); end
% Dicrease boundaries to converge towards antlion lb=lb/(I); % Equation (2.10) in the paper ub=ub/(I); % Equation (2.11) in the paper
% Move the interval of [lb ub] around the antlion [lb+anlion ub+antlion] if rand<0.5 lb=lb+antlion; % Equation (2.8) in the paper else lb=-lb+antlion; end
if rand>=0.5 ub=ub+antlion; % Equation (2.9) in the paper else ub=-ub+antlion; end
% This function creates n random walks and normalize accroding to lb and ub % vectors for i=1:Dim X = [0 cumsum(2*(rand(max_iter,1)>0.5)-1)']; % Equation (2.1) in the paper %[a b]--->[c d] a=min(X); b=max(X); c=lb(i); d=ub(i); X_norm=((X-a).*(d-c))./(b-a)+c; RWs(:,i)=X_norm; end
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!