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

📄 lrp.m

📁 用matlab 编写的LRP问题的基本程序
💻 M
字号:
%无时间窗模型的主程序。
function Objval=OBJ(Chrom);
Dim=116;
[Nind,Nvar]=size(Chrom);
Chroml=Chrom(:,1);
Chrom2=Chrom(:,2:101);
Chrom3=Chrom(:,102:116);
if Nvar==Dim
    Objval=zeros(Nind,1);
    c=Chrom;
    Objval=[];
    for i=1:Nind
        cost=zeros(1,6);
        fq=zeros(1,6);
        ic=0;
        tc=0;
        tq=zeros(1,25);
        for j=1:15
            a=find(Chrom2(i,:)==j);
            b=size(a);
            c=b(1,2);
            if c~=0
                for k=1:c
                    tq(1,j)=tq(1,j)+G(1,a(1,k));
                end
                if tq(1,j)>200
                    tq(1,j)=200;
                end
                tempcost=0;
                for k=1:c-1
                    tq(1,j)=tq(1,j)-G(1,a(1,k)),
                    if tq(1,j)>0
                        tempcost=tempcost+(sqrt((D(a(1,k),1)-D(a(1-k+1)-1))^2+(D(a(1,k),2)-D(a(1,k+1),1))^2));
                    else
                        tempcost=tempcost+(sqrt((D(a(1,k),1)-D(a(1,k+1),1))^2+(D(a(1,k),2)-D(a(1,k+1),l))^2))*5000;
                    end
                end
                tempin=0;
                for k=1:c
                    tempin=tempin+G(1,a(1,k));
                end
                switch Chrom3(i,j)
                    case 1
                    if cost(1,1)~=0
                        cost(1,1)=cost(1,1)+tempcost+(sqrt((D(a(1,1),1)-L(1,1))^2+(D(a(1,1),2)-L(1,2))^2));
                        fq(1,1)=fq(1,1)+tempin;
                    else
                        if Chroml(i,1)==1
                            cost(1,1)=tempcost+cl(1,1)+(sqrt((D(a(1,1),1)-L(1,1))^2+(D(a(1,1),2)-L(1,2))^2))+(sqrt((fa(1,1)-L(1,1))^2+(fa(1,2)-L(1,2))^2));
                        elseif Chroml(i,1)==2
                            cost(1,1)=tempcost+cl(1,1)+(sqrt((D(a(1,1),1)-L(1,l))^2+(D(a(1,1),2)-L(1,2))^2))+(sqrt((fa(2,1)-L(1,1))^2+(fa(3,2)-L(1,2))^2));
                        elseif Chroml(i,1)==3
                            cost(1,1)=tempcost+cl(l,1)+(sqrt((D(a(1,1),1)-L(1,1))^2+(D(a(1,1),2)-L(1,2))^2))+(sqrt((fa(3,1)-L(1,1))^2+(fa(3,2)-L(l,2))^2));
                        else
                        end
                        fq(1,1)=fq(1,1)+tempin;
                    end
                    case 2
                        if cost(1,2)~=0
                            cost(1,2)=cost(1,2)+tempcost+(sqrt((D(a(1,1),1)-L(2,1))^2+(D(a(1,1),2)-L(2,2))^2));
                            fq(1,2)=fq(1,2)+tempin;
                        else
                            if Chroml(i,1)==l
                                cost(1,2)=tempcost+cl(1,2)+(sqrt((D(a(1,1),1)-L(2,1))^2+(D(a(1,1),2)-L(2,2))^2))+(sqrt((fa(1,1)-L(2,1))^2+(fa(1,2)-L(2,2))^2));
                            elseif Chroml(i,1)==2
                                cost(1,2)=tempcost+el(1,2)+(sqrt((D(a(1,1),l)-L(2,l))^2+(D(a(1,1),2)-L(2,2))^2))+(sqrt((fa(2,1)-L(2,1))^2+(fa(2,2)-L(2,2))^2));
                            elseif Chroml(i,1)==3
                                cost(1,2)=tempcost+cl(1,2)+(sqrt((D(a(1,1),l)-L(2,1))^2+(D(a(1,1),2)-L(2,2))^2))+(sqrt((fa(3,1)-L(2,1))^2+(fa(3,2)-L(2,2))^2));
                            else
                            end
                            fq(1,2)=fq(1,2)+tempin;
                        end
                    case 3
                        if cost(1,3)~=0
                            cost(1,3)=cost(1,3)+tempcost+(sqrt((D(a(1,1),1)-L(3,1))^2+(D(a(1,1),2)-L(3,2))^2));
                            fq(1,3)=fq(1,3)+tempin;
                        else
                            if Chroml(i,1)==1
                                cost(1,3)=tempcost+cl(1,3)+(sqrt((D(a(1,1),1)-L(3,l))^2+(D(a(1,1),2)-L(3,2))^2))+(sqrt((fa(1,1)-L(3,1))^2+(fa(1,2)-L(3,2))^2));
                            elseif Chroml(i,1)==2
                                cost(1,3)=tempcost+cl(1,3)+(sqrt((D(a(1,1),1)-L(3,1))^2+(D(a(1,1),2)-L(3,2))^2))+(sqrt((fa(2,1)-L(3,1))^2+(fa(2,2)-L(3,2))^2));
                            elseif Chroml(i,1)==3
                                cost(1,3)=tempcost+cl(1,3)+(sqrt((D(a(1,1),1)-L(3,1))^2+(D(a(1,1),2)-L(3,2))^2))+(sqrt((fa(3,1)-L(3,1))^2+(fa(3,2)-L(3,2))^2));
                            else
                            end
                            fq(1,3)=fq(1,3)+tempin;
                        end
                    case 4
                        if cost(1,4)~=0
                            cost(1,4)=cost(1,4)+tempcost+(sqrt((D(a(1,1),1)-L(4,1))^2+(D(a(1,1),2)-L(4,2))^2));
                            fq(1,4)=fq(1,4)+tempin;
                        else
                            if Chroml(i,1)==l
                                cost(1,4)=tempcost+cl(1,4)+(sqrt((D(a(1,1),1)-L(4,1))^2+(D(a(1,1),2)-L(4,2))^2))+(sqrt((fa(1,1)-L(4,1))^2+(fa(1,2)-L(4,2))^2));
                            elseif Chroml(i,l)==2
                                cost(1,4)=tempcost+cl(l,4)+(sqrt((D(a(1,1),1)-L(4,1))^2+(D(a(1,1),2)-L(4,2))^2))+(sqrt((fa(2,1)-L(4,1))^2+(fa(2,2)-L(4,2))^2));
                            elseif Chroml(i,1)==3
                                cost(1,4)=rempcost+cl(1,4)+(sqrt((D(a(1,1),1)-L(4,1))^2+(D(a(1,1),2)-L(4,2))^2))+(sqrt((fa(3,1)-L(4,1))^2+(fa(3,2)-L(4,2))^2));
                            else
                            end
                            fq(1,4)=fq(1,4)+tempin;
                        end
                    case 5
                        if cost(1,5)~=0
                            cost(1,5)=cost(1,5)+tempcost+(sqrt((D(a(1,1),1)-L(5,1))^2+(D(a(1,1),2)-L(5,2))^2));
                            fq(1,5)=fq(1,5)+tempin;
                        else
                            if Chroml(i,1)==1
                                cost(1,5)=tempcost+cl(1,5)+(sqrt((D(a(1,1),1)-L(5,1))^2+(D(a(1,1),2)-L(5,2))^2))+(sqrt((fa(1,1)-L(5,1))^2+(fa(1,2)-L(5,2))^2));
                            elseif Chroml(i,1)==2
                                cost(1,5)=tempcost+cl(1,5)+(sqrt((D(a(1,1),1)-L(5,1))^2+(D(a(1,1),2)-L(5,2))^2))+(sqrt((fa(2,1)-L(5,1))^2+(fa(2,2)-L(5,2))^2));
                            elseif Chroml(i,1)==3
                                cost(1,5)=tempcost+cl(1,5)+(sqrt((D(a(1,1),1)-L(5,1))^2+(D(a(1,1),2)-L(5,2))^2))+(sqrt((fa(3,1)-L(5,1))^2+(fa(3,2)-L(5,2))^2));
                            else
                            end
                            fq(1,5)=fq(1,5)+tempin;
                        end
                        case6
                        if cost(1,6)~=0
                            cost(1,6)=cost(1,6)+tempcost+(sqrt((D(a(1,1),1)-L(6,1))^2+(D(a(1,1),2)-L(6,2))^2));
                            fq(1,6)=fq(1,6)+tempin;
                        else
                            if Chroml(i,1)==1
                                cost(1,6)=tempcost+cl(1,6)+(sqrt((D(a(1,1),1)-L(6,1))^2+(D(a(1,1),2)-L(6,2))^2))+(sqrt((fa(1,1)-L(6,l))^2+(fa(1,2)-L(6,2))^2));
                            elseif Chroml(i,1)==2
                                cost(1,6)=tempcost+cl(1,6)+(sqrt((D(a(1,1),1)-L(6,1))^2+(D(a(1,1),2)-L(6,2))^2))+(sqrt((fa(2,1)-L(6,1))^2+(fa(2,2)-L(6,2))^2));
                            elseif Chroml(i,1)==3
                                cost(1,6)=tempcost+cl(1,6)+(sqrt((D(a(1,1),1)-L(6,1))^2+(D(a(1,1),2)-L(6,2))^2))+(sqrt((fa(3,1)-L(6,1))^2+(fa(3,2)-L(6,2))^2));
                            else
                            end
                            fq(1,6)=fq(1,6)+tempin;
                        end
                    otherwise
                end
            end
        end
        for w=1:8
            if fq(1,w)>600
                ic=ic+fq(1,w)*cf(1,w)*1.2+20000;
            else
                ic=ic+fq(1,w)*cf(1,w)*1.2;
            end
        end
        Objval(i,1)=sum(cost);
    end
    Chrom=[Chrom1 Chrom2 Chrom3];
end



                            

⌨️ 快捷键说明

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