日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 人工智能 > 循环神经网络 >内容正文

循环神经网络

matlab教程蚁群算法,蚁群算法怎样用MATLAB仿真

發(fā)布時(shí)間:2023/12/20 循环神经网络 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 matlab教程蚁群算法,蚁群算法怎样用MATLAB仿真 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

蟻群算法采用matlab開(kāi)發(fā)的仿真平臺(tái):算法實(shí)現(xiàn),路徑顯示,人機(jī)交互控制等

希望對(duì)你有幫助!

是可以運(yùn)行的

%? ? the procedure of ant colony algorithm for VRP

%

%? ? %? ? %? ? %? ? %? ? %? ? %? ? %? ? %? ? %? ? %

%initialize the parameters of ant colony algorithms

load data.txt;

d=data(:,2:3);

g=data(:,4);

m=31; %螞蟻數(shù)

alpha=1;

belta=4;% 決定tao和miu重要性的參數(shù)

lmda=0;

rou=0.9; %衰減系數(shù)

q0=0.95;

% 概率

tao0=1/(31*841.04);%初始信息素

Q=1;% 螞蟻循環(huán)一周所釋放的信息素

defined_phrm=15.0;? ?% initial pheromone level value

QV=100;??% 車輛容量

vehicle_best=round(sum(g)/QV)+1; %所完成任務(wù)所需的最少車數(shù)

V=40;

% 計(jì)算兩點(diǎn)的距離

for i=1:32;

for j=1:32;

dist(i,j)=sqrt((d(i,1)-d(j,1))^2+(d(i,2)-d(j,2))^2);

end;

end;

%給tao miu賦初值

for i=1:32;

for j=1:32;

if i~=j;

%s(i,j)=dist(i,1)+dist(1,j)-dist(i,j);

tao(i,j)=defined_phrm;

miu(i,j)=1/dist(i,j);

end;

end;

end;

for k=1:32;

for k=1:32;

deltao(i,j)=0;

end;

end;

best_cost=10000;

for n_gen=1:50;

print_head(n_gen);

for i=1:m;

%best_solution=[];

print_head2(i);

sumload=0;

cur_pos(i)=1;

rn=randperm(32);

n=1;

nn=1;

part_sol(nn)=1;

%cost(n_gen,i)=0.0;

n_sol=0;? ?% 由螞蟻產(chǎn)生的路徑數(shù)量

M_vehicle=500;

t=0;??%最佳路徑數(shù)組的元素?cái)?shù)為0

while sumload<=QV;

for k=1:length(rn);

if sumload+g(rn(k))<=QV;

gama(cur_pos(i),rn(k))=(sumload+g(rn(k)))/QV;

A(n)=rn(k);

n=n+1;

end;

end;

fid=fopen('out_customer.txt','a+');

fprintf(fid,'%s??%i\t','the current position is:',cur_pos(i));

fprintf(fid,'\n%s','the possible customer set is:')

fprintf(fid,'\t%i\n',A);

fprintf(fid,'------------------------------\n');

fclose(fid);

p=compute_prob(A,cur_pos(i),tao,miu,alpha,belta,gama,lmda,i);

maxp=1e-8;

na=length(A);

for j=1:na;

if p(j)>maxp

maxp=p(j);

index_max=j;

end;

end;

old_pos=cur_pos(i);

if rand(1)

cur_pos(i)=A(index_max);

else

krnd=randperm(na);

cur_pos(i)=A(krnd(1));

bbb=[old_pos cur_pos(i)];

ccc=[1 1];

if bbb==ccc;

cur_pos(i)=A(krnd(2));

end;

end;

tao(old_pos,cur_pos(i))=taolocalupdate(tao(old_pos,cur_pos(i)),rou,tao0);%對(duì)所經(jīng)弧進(jìn)行局部更新

sumload=sumload+g(cur_pos(i));

nn=nn+1;

part_sol(nn)=cur_pos(i);

temp_load=sumload;

if cur_pos(i)~=1;

rn=setdiff(rn,cur_pos(i));

n=1;

A=[];

end;

if cur_pos(i)==1;??% 如果當(dāng)前點(diǎn)為車場(chǎng),將當(dāng)前路徑中的已訪問(wèn)用戶去掉后,開(kāi)始產(chǎn)生新路徑

if setdiff(part_sol,1)~=[];

n_sol=n_sol+1;??% 表示產(chǎn)生的路徑數(shù),n_sol=1,2,3,..5,6...,超過(guò)5條對(duì)其費(fèi)用加上車輛的派遣費(fèi)用

fid=fopen('out_solution.txt','a+');

fprintf(fid,'%s%i%s','NO.',n_sol,'條路徑是:');

fprintf(fid,'%i??',part_sol);

fprintf(fid,'\n');

fprintf(fid,'%s','當(dāng)前的用戶需求量是:');

fprintf(fid,'%i\n',temp_load);

fprintf(fid,'------------------------------\n');

fclose(fid);

% 對(duì)所得路徑進(jìn)行路徑內(nèi)3-opt優(yōu)化

final_sol=exchange(part_sol);

for nt=1:length(final_sol); % 將所有產(chǎn)生的路徑傳給一個(gè)數(shù)組

temp(t+nt)=final_sol(nt);

end;

t=t+length(final_sol)-1;

sumload=0;

final_sol=setdiff(final_sol,1);

rn=setdiff(rn,final_sol);

part_sol=[];

final_sol=[];

nn=1;

part_sol(nn)=cur_pos(i);

A=[];

n=1;

end;

end;

if setdiff(rn,1)==[];% 產(chǎn)生最后一條終點(diǎn)不為1的路徑

n_sol=n_sol+1;

nl=length(part_sol);

part_sol(nl+1)=1;%將路徑的最后1位補(bǔ)1

% 對(duì)所得路徑進(jìn)行路徑內(nèi)3-opt優(yōu)化

final_sol=exchange(part_sol);

for nt=1:length(final_sol); % 將所有產(chǎn)生的路徑傳給一個(gè)數(shù)組

temp(t+nt)=final_sol(nt);

end;

cost(n_gen,i)=cost_sol(temp,dist)+M_vehicle*(n_sol-vehicle_best);? ?%計(jì)算由螞蟻i產(chǎn)生的路徑總長(zhǎng)度

for ki=1:length(temp)-1;

deltao(temp(ki),temp(ki+1))=deltao(temp(ki),temp(ki+1))+Q/cost(n_gen,i);

end;

if cost(n_gen,i)

best_cost=cost(n_gen,i);

old_cost=best_cost;

best_gen=n_gen;??% 產(chǎn)生最小費(fèi)用的代數(shù)

best_ant=i; %產(chǎn)生最小費(fèi)用的螞蟻

best_solution=temp;

end;

if i==m;  %如果所有螞蟻均完成一次循環(huán),,則用最佳費(fèi)用所對(duì)應(yīng)的路徑對(duì)弧進(jìn)行整體更新

for ii=1:32;

for jj=1:32;

tao(ii,jj)=(1-rou)*tao(ii,jj);

end;

end;

for kk=1:length(best_solution)-1;

tao(best_solution(kk),best_solution(kk+1))=tao(best_solution(kk),best_solution(kk+1))+deltao(best_solution(kk),best_solution(kk+1));

end;

end;

fid=fopen('out_solution.txt','a+');

fprintf(fid,'%s%i%s','NO.',n_sol,'路徑是:');

fprintf(fid,'%i ',part_sol);

fprintf(fid,'\n');

fprintf(fid,'%s %i\n','當(dāng)前的用戶需求量是:',temp_load);

fprintf(fid,'%s %f\n','總費(fèi)用是:',cost(n_gen,i));

fprintf(fid,'------------------------------\n');

fprintf(fid,'%s\n','最終路徑是:');

fprintf(fid,'%i-',temp);

fprintf(fid,'\n');

fclose(fid);

temp=[];

break;

end;

end;

end;

end;

總結(jié)

以上是生活随笔為你收集整理的matlab教程蚁群算法,蚁群算法怎样用MATLAB仿真的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。