isfeasible.m

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

M
30
字号
function [b,r]=isFeasible(s,bk,l,d)
% realize a pop
%pop code of rount
%bk cap of truck
%l the num of shop
n=size(s,2);   %num of element of s
nt=size(bk,2); % num of trucks
dz=zeros(1,l); % flag
nk=zeros(1,nt);% shop num at root K
r=zeros(nt,l); 

for x=1:n     
    m=s(x)-(ceil((s(x)-l)/l))*l; %the m th shop 
    k=(ceil((s(x)-l)/l))+1;      %the k th root
    if dz(m)==0
        if d(m)<=bk(k)
            dz(m)=1;
            bk(k)=bk(k)-d(m);
            nk(k)=nk(k)+1;
            r(k,nk(k))=m;
        end
    end    
end
if all(dz)
    b=1;
else
    b=0;
end

⌨️ 快捷键说明

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