⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 routsolbyindexga.m

📁 一个用于自然数编码遗传算法的工具包indexGA
💻 M
字号:
%us indexGA for route problem
clc

%matrix of cost (distance)
load thedist.txt;
global c
c=thedist;

popSize=20;
solSize=16;
MaxGen=50;

%make the initialize
startpop=zeros(popSize,solSize);

s=[1:solSize];

for n=1:popSize
    startpop(n,:)=randArray(s);
end

tm=zeros(popSize,1);
startpop=[startpop tm];

%make out the fitness of every sol in startpop
for n=1:popSize   
    [startpop(n,:) startpop(n,solSize+1)]=routFitness(startpop(n,:),0);
end

%call ga
[x,endPop,bPop,traceInfo] = indexGA([1 solSize],'routFitness',0,startpop,...
'termFN',MaxGen,'normGeomSelect',[0.08],'pmxIndexXover',[popSize,0.7],'indexMutate',[popSize,0.4]);

%display the Result

%the Best solution
%printPop(MaxGen,x);

%[b,r]=solToRouts(x);
%the Best Rount
%r

%the Best Pop
printPop(MaxGen,endPop);

%the Sum of distance
sumDist=1/x(solSize+1);
fprintf(1,'\n\n sumDist = %f',sumDist);

%the traceInfo
%traceInfo

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -