routfitness.m

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

M
33
字号
function [sol,val]=routFitness(sol,options)
% make out the fitness of sol
n=size(sol,2)-1; % not use the fitness value
bk=[8 8]; % cap of trucks
l=8;      % num of shops
d=[1 2 1 2 1 4 2 2]; %demand of shops
[b,r]=isFeasible(sol(1:n),bk,l,d); %if the sol realizable

global c %the cost(distance)

%if realizable make out the sum distance on roots
if b     
    rts=size(r,1);
    sum=0;
    for k=1:rts
        tmp=r(k,find(r(k,:)));
        tmp=tmp+1;
        tmp=[1 tmp];       
        n=size(tmp,2);
        for x=1:n-1           
            sum=sum+c(tmp(x),tmp(x+1));
        end
        sum=sum+c(tmp(n),1);
    end
    sum;
    val=1/sum;
else
    mess='no realizable';
    val=realmin;
end


⌨️ 快捷键说明

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