how to make this code for multiple ant colonies

조회 수: 1 (최근 30일)
Filza Ashraf
Filza Ashraf 2014년 5월 19일
this is a code that generate only a single ant colony but i want to make 2 colonies of ants but i dont know how to change the code please help me to generate another clique
img = imread('R.jpg');
img = double(I)./255;
[nrow, ncol] = size(img);
v = zeros(size(I));
v_norm = 0;
for rr =1:nrow
for cc=1:ncol
%defination of clique
temp1 = [rr-2 cc-1; rr-2 cc+1; rr-1 cc-2; rr-1 cc-1; rr-1 cc; rr-1 cc+1; rr-1 cc+2; rr cc-1];
temp2 = [rr+2 cc+1; rr+2 cc-1; rr+1 cc+2; rr+1 cc+1; rr+1 cc; rr+1 cc-1; rr+1 cc-2; rr cc+1];
temp0 = find(temp1(:,1)>=1 & temp1(:,1)<=nrow & temp1(:,2)>=1 & temp1(:,2)<=ncol & temp2(:,1)>=1 & temp2(:,1)<=nrow & temp2(:,2)>=1 & temp2(:,2)<=ncol);
temp02 = find(temp1(:,1)<=1 & temp1(:,1)>=nrow & temp1(:,2)<=1 & temp1(:,2)>=ncol & temp2(:,1)<=1 & temp2(:,1)>=nrow & temp2(:,2)<=1 & temp2(:,2)>=ncol);
temp11 = temp1(temp0, :);
temp22 = temp2(temp0, :);
temp00 = zeros(size(temp11,1));
for kk = 1:size(temp11,1)
temp00(kk) = abs(img(temp11(kk,1), temp11(kk,2))-img(temp22(kk,1), temp22(kk,2)));
end
if size(temp11,1) == 0
v(rr, cc) = 0;
v_norm = v_norm + v(rr, cc);
else
lambda = 10;
temp00 = sin(pi .* temp00./2./lambda);
v(rr, cc) = sum(sum(temp00.^2));
v_norm = v_norm + v(rr, cc);
end
end
end
v = v./v_norm;
v = v.*100;
% pheromone function initialization
p = 0.0001 .* ones(size(img));
%paramete setting
alpha = 10;
beta = 0.1;
rho = 0.1;
phi = 0.05;
ant_total_num = round(sqrt(nrow*ncol));
ant_pos_idx = zeros(ant_total_num, 2); % record the location of ant
this code generate 490 ants for image of size 490*490 but i want to generate another clique of 490 ants to increase the number of ants
PLEASE HELP ME

답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by