function [bestnest,fmin]=cuckoo_search(n) global centroids Lb = [1 30]; Ub = [100 40]; if nargin<1, % Number of nests (or different solutions) n = 25; end % Discovery rate of alien eggs/solutions pa = 0.25; %D;T1;T2;W1;W2 %% Change this if you want to get better results % Tolerance %Tol = 3; % Número máximo de iterações Nmi = 100; %% Simple bounds of the search domain % Random initial solutions for i=1:n nest(i,:)=Lb+(Ub-Lb).*rand(size(Lb)); end % Get the current best fitness=10^10*ones(n,1); [fmin,bestnest,nest,fitness]=get_best_nest(nest,nest,fitness); N_iter=0; %% Starting iterations c = 1; while (c < Nmi+1) % Generate new solutions (but keep the current best) new_nest=get_cuckoos(nest,bestnest,Lb,Ub); [fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness); % Update the counter N_iter=N_iter+n; % Discovery and randomization new_nest=empty_nests(nest,Lb,Ub,pa); % Evaluate this set of solutions [fnew,best,nest,fitness]=get_best_nest(nest,new_nest,fitness); % Update the counter again N_iter=N_iter+n; % Find the best objective so far if fnewpa; % In the real world, if a cuckoo's egg is very similar to a host's eggs, then % this cuckoo's egg is less likely to be discovered, thus the fitness should % be related to the difference in solutions. Therefore, it is a good idea % to do a random walk in a biased way with some random step sizes. %% New solution by biased/selective random walks stepsize=rand*(nest(randperm(n),:)-nest(randperm(n),:)); new_nest=int16(nest+stepsize.*K); for j=1:size(new_nest,1) s=new_nest(j,:); new_nest(j,:)=simplebounds(s,Lb,Ub); end end % Application of simple constraints function s=simplebounds(s,Lb,Ub) % Apply the lower bound ns_tmp=s; I=ns_tmpUb; ns_tmp(J)=Ub(J); % Update this new move s=ns_tmp; end %% You can replace the following by your own functions % A d-dimensional objective function function z=fobj(u) global populacao_data2; w=[0.7 0.3]; inicio=int16(u(1)); dados22(inicio); for i=1:length(centroids) numerocentroide=i; %para o python deveria ser i-1 num=1; contador=0; for j=1:length(populacao_data2), if numerocentroide==populacao_data2(j,3), if ((centroids(i,1)~=populacao_data2(j,2)) && (centroids(i,2)~= populacao_data2(j,1))), hav=haversine([centroids(i,1) populacao_data2(j,2)],[centroids(i,2) populacao_data2(j,1)]); distanciahaversine=hav;%metros x=[13.958 5.8 0.759 1.862]; ht=40;%40;%metros hr=1.6;%%1.6;%metros f=3.5e9;%Hertz pl=ecc33(x,ht,hr,f,distanciahaversine); pt=u(2);%dBm gt=3;%15.6;%dBi gr=0; %dBi pr(num)=pt-pl+gt+gr;%dBm if pr(num)>=-90 contador=contador+1; end; num=num+1; end end end %percentualdecoberturaporcentroide(i)=(contador/length(pr))*100; percentualdecoberturaporcentroide(i)=(contador/num)*100; % mediapotencia(i)=mean(pr); clear pr end mediadopercentualdecoberturadetodososclusters=mean(percentualdecoberturaporcentroide); %clear mediapotencia; clear percentualdecoberturaporcentroide; centroids; mediadopercentualdecoberturadetodososclusters; obj1 = 100 - mediadopercentualdecoberturadetodososclusters; obj2 = abs(pt-30); z=(obj1*w(1,1)+obj2*w(1,2)) end end