资源简介

蚁群-微分进化算法解TSP的matlab实现,有详尽的报告

资源截图

代码片段和文件信息

function [bestRouteminLength] = AcoDeTsp(DistantsNumgroupNummaxIter)
%%
    if mod(antsNumgroupNum)~=0
        error(‘antsNum must be divided exactly by groupNum‘);
    end
    n = size(Dist1);
    m = antsNum;
    g = groupNum;
    gs = m/g;%groupSize
    
    pherP = 1;
    expP = 5;
    volR = 0.1;
    pherC = 1;
    muteC = 2;
    crossR = 0.5;
    
    Exp = 1./Dist;
    groupPher = cell(1g);
    for i=1:g
        groupPher{i}=ones(nn);
    end
    Route = zeros(mn); 
    %groupBestRoute = zeros(gn);
    bestRoute = zeros(maxItern);
    minLength = zeros(maxIter1);
%%   
    citiesIdx = 1:n;
    iter = 1;
    while iter <= maxIter
        %% ************** ACO **************
        %******* ants move according to pheromone *******
        for i=1:m
            %ant i
            curG = ceil(i/gs);
            curPher = groupPher{curG};
            Route(i1) = randi(n);
            for j=2:n
                %jth step 
                tabu = Route(i1:j-1);
                avail = ~ismember(citiesIdxtabu);
                availIdx = citiesIdx(avail);
                availNum = length(availIdx);
                Prob = zeros(availNum1);
                lastC = Route(ij-1);
                for k=1:availNum
                    Prob(k) = curPher(availIdx(k)lastC)^pherP * Exp(availIdx(k)lastC)^expP;
                end
                Prob = Prob/sum(Prob);
                cumP = cumsum(Prob);
                nextIdx = find(cumP >= rand);
                nextCIdx = availIdx(nextIdx(1));
                Route(ij) = nextCIdx;
            end
        end
        %******* calculate route length *******
        len = zeros(m1);
        for i=1:m
            r = Route(i:);
            for j=1:n-1
                len(i) = len(i) + Dist(r(j)r(j+1));
            end
            len(i) = len(i) + Dist(r(n)r(1));
        end
        %******* find overall-best route *******
        [minLenminIdx] = min(len);
        bestRoute(iter:) = Route(minIdx:);
        minLength(iter) = minLen;
        %******* update pheromone *******
        for curG=1:g
            deltaPher = zeros(nn);
            for i=1:gs
                idx = (curG-1)*gs+i;
                curR = Route(idx:);
                for j=1:n-1
                    deltaPher(curR(j)curR(j+1)) = deltaPher(curR(j)curR(j+1)) + pherC/len(idx);
                end
                deltaPher(curR(n)curR(1)) = deltaPher(curR(n)curR(1)) + pherC/len(idx);
            end
            groupPher{curG} = (1-volR)*groupPher{curG} + deltaPher;
        end
        
        %%************** DE **************
        for curG=1:g
            %******* mute *******
            curPher = groupPher{curG};
            r1 = randi(curG);
            r2 = randi(curG);
            r3 = randi(curG);
            vPher = groupPher{r1} + muteC*(groupPher{r2}-groupPher{r3});
            %******* cross *******
      

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1562  2013-12-02 18:34  Main.m

     文件     424405  2013-12-08 23:54  蚁群-微分进化算法之TSP.docx

     文件       6332  2013-12-02 18:06  AcoDeTsp.m

     文件       2073  2013-12-02 16:14  AcoTsp.m

     文件        328  2013-11-01 14:10  cities.mat

----------- ---------  ---------- -----  ----

               434700                    5


评论

共有 条评论