routsolbytribalga.m

来自「一个用于自然数编码遗传算法的工具包indexGA」· M 代码 · 共 53 行

M
53
字号
%solve the rout problem by tribleGA
clc

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

popSize=10;
solSize=16;
MaxGen=50;
tribalSize=10;
tribalHistory=1;

s=[1:solSize];

best=[s 0];

tribal=zeros(tribalSize,solSize+1);

for lup=1:tribalHistory    
    for y=1:tribalSize 
        %make the initialize
        startpop=initialIndexPop(s,popSize);
        %call ga
        [x,endPop,bPop,traceInfo] = indexTribalGA([1 solSize],'routFitness',0,startpop,...
        'termFN',MaxGen,'normGeomSelect',[0.08],'pmxIndexXover',[0,0],'indexMutate',[popSize,0.8]);
        tribal(y,:)=x;
        printPop(y,x);       
    end

    [x,endPop,bPop,traceInfo] = indexTribalGA([1 solSize],'routFitness',0,tribal,...
    'termFN',MaxGen,'normGeomSelect',[0.08],'pmxIndexXover',[0,0],'indexMutate',[0,0]);

    if x(solSize+1) > best(solSize+1)
        best=x;
    end    
    
end


%display the Result

%the Best solution
printPop(MaxGen,best);

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

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

⌨️ 快捷键说明

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