物流选址基于matlab节约算法求解考虑碳排放及带时间窗的物流选址问题含Matlab源码 1589期

Posted 紫极神光

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了物流选址基于matlab节约算法求解考虑碳排放及带时间窗的物流选址问题含Matlab源码 1589期相关的知识,希望对你有一定的参考价值。

一、节约算法简介


基本思想

行时通过这一条弧。

迭代步骤

二、部分源代码

clc
clear all
p1=0.9;
customer=xlsread('customer.xlsx');           %需求点信息
facility=xlsread('facility.xlsx');           %设施点信息
facilityposition=facility(:,2:3);               %设施坐标
customerposition=customer(:,2:3);               %需求点坐标
position=[facilityposition;customerposition];   
xlswrite('position.xlsx',position)
position1=[position(:,1) position(:,2)];
distMatrix=dists(position1);                    %计算得出的两点之间的距离
xlswrite('distMatrix.xlsx',distMatrix)

ttimeu=fix(distMatrix);                         %两点之间的距离
%%%%%%%%%%%%%%%%%%%%%%%%%固定数据%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Qofcar=200;                                     %车辆容量
costofallcar=5000;                               %车辆固定成本
costofunitdistance=9;                            %单位距离成本
tanpaifangyinzi=1;                               %车辆碳排放因子
danweiyouhao=1;                                  %车辆单位油耗
%%%%%%%%%%%%%%%%%%%%%%%计算出来的数据%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Numberofpoints=size(customer,1);                %需求点数量
Numberoffacilities=size(facility,1);            %设施点数量
quantity=[customer(:,1) customer(:,4) customer(:,4)];     %需求点需求量
Qoffacilities=[facility(:,1) facility(:,4)];    %设施容量
timewindow=[customer(:,1) customer(:,6:7)];     %需求点时间窗
countfacility=facility(:,5);                    %建立设施固定成本
codeofpicture=1;


timewindow

assignofpoint=[2 1 2 1 3 3 1 2 1 1 2 3 2];
[outcome1,outcome2,outcome3]=cw(Numberoffacilities,assignofpoint,ttimeu,timewindow,distMatrix,quantity,Qofcar,p1);
%outcome1=[1 1 2 1 2 3 3 4 4 3 5 5 5];
%outcome2=[9 2 10 4 7 13 1 11 8 3 12 5 6];
[outcome1,outcome2,outcome3]=tabu(outcome1,outcome2,outcome3,distMatrix,ttimeu,Numberoffacilities,timewindow);

[Picture]=picture(codeofpicture,outcome1,outcome2,outcome3,customer,facility);
    function [outcome1,outcome2,outcome3]=cw(Numberoffacilities,assignofpoint,ttimeu,timewindow,distMatrix,quantity,Qofcar,p1)    
    H=1;
    outcome3=zeros(1,Numberoffacilities);%与设施点的伪编号是一一对应的   
    %%%%%%%找到实际分配的设施点,因为之前的chrom中为1的点,可能%%%%%%%%%%%%%
    facilitypop=zeros(1:Numberoffacilities);
    facilitypop(assignofpoint)=1;
    trueSelectefacilities=find(facilitypop(1,:)==1);     %被选择的设施编号    
    trueselectNumberoffacilities=size(trueSelectefacilities,2);
    outcome1=cell(1,trueselectNumberoffacilities);
    outcome2=cell(1,trueselectNumberoffacilities);    
    for i=1:trueselectNumberoffacilities%此时的设施为i
        a=trueSelectefacilities(i);%设施的伪编号        
        pointofsubroute=find(assignofpoint==a);%属于该设施点的所有需求点的伪编号
        Numberofpointsofsubroute=size(pointofsubroute,2);%该设施点的需求点数量           
        judge=zeros(1,Numberofpointsofsubroute);                           %判断需求点的位置情况       
        chrom1=zeros(1,Numberofpointsofsubroute);%最后输入的是伪编号        
        chrom2=sort(pointofsubroute);                                      %需求点伪编号从小到大排序        
        originalchrom2=chrom2;
        
        %%对关键节点先分配一个车辆给它?????????????????????对不对?
        %for j=1:Numberofpointsofsubroute            
            %if timewindow(chrom2(j),2)==timewindow(chrom2(j),3)                  
                %chrom1(j)=H;
                %H=H+1;                
            %end
        %end      
        %%%%%%%%计算到达时间%%%%%%%%%%%%%%%%%%%%        
        arrivetime=zeros(1,Numberofpointsofsubroute);%需求点的到达时间,与当前的originalchrom2位置一一对应,与分配给该设施点的需求点一一对应        
        for j=1:Numberofpointsofsubroute            
            if ttimeu(chrom2(j)+Numberoffacilities,a)<timewindow(chrom2(j),2)                
                arrivetime(j)=timewindow(chrom2(j),2);                
            else
                arrivetime(j)=ttimeu(chrom2(j)+Numberoffacilities,a);                
            end
        end        
        %%%%%%%%%%%%%%%%%%%%%%%%%路径节约值列表%%%%%%%%%%%%%%%%%%%%%%        
        savingnumber=zeros(Numberofpointsofsubroute);%与分配给该设施的需求点的伪编号一一对应        
        for j=1:Numberofpointsofsubroute            
            for z=1:Numberofpointsofsubroute                
                if j~=z                       
                    savingnumber(j,z)=distMatrix(chrom2(j)+Numberoffacilities,a)+distMatrix(chrom2(z)+Numberoffacilities,a)-distMatrix(chrom2(j)+Numberoffacilities,chrom2(z)+Numberoffacilities);                    
                end
            end
        end        
        [a b]=max(savingnumber);%a输入值,b中对应的数字为行,对应的列数为列        
        [c d]=max(a);%c输入具体的当前节约值,d为列数         
        e=b(d);%e为行 
        %%%在节约值列表中e行d列是当前最大的节约量
        E=chrom2(e);%此时的E为节约量最大的需求点伪编号之一
        D=chrom2(d);%此时的D为节约量最大的需求点伪编号之1       
        done=1;            
        while(done<2)                
            if judge(e)==0&&judge(d)==0                 
                PD=0;                
                a=quantity(E,2)+quantity(D,2);
                aa=quantity(E,3)+quantity(D,3);
                pp1=normcdf(Qofcar,a,sqrt(aa));
                a2=find(chrom2==D);                
                b2=find(chrom2==E);
                if pp1>p1                       
                    EFj=arrivetime(e)+ttimeu(E+Numberoffacilities,D+Numberoffacilities)-arrivetime(d);                      
                    if EFj<0                             
                        aheadtime=arrivetime(d)-timewindow(D,2);                           
                        if aheadtime>=-EFj                                
                            PD=1;                                 
                        end
                    elseif EFj==0
                        PD=1;                        
                    elseif EFj>0                          
                        delaytime=timewindow(D,3)-arrivetime(d);                            
                        if delaytime>=EFj                             
                            PD=1;                               
                        end
                    end
                    if PD==1                        
                        chrom1(e)=H;                            
                        chrom1(d)=H;%H为车辆编号                          
                        judge(e)=1;%与设施直接相连的起点为1                          
                        judge(d)=2;%与设施直接相连的终点为2                           
                        H=H+1;                            
                        arrivetime(d)=arrivetime(d)+EFj;
                        if b2>a2
                            chrom2(a2)=E;
                            chrom2(b2)=D;
                        end
                    end
                end
                savingnumber(e,d)=0;                
            elseif judge(e)==0&&judge(d)==1;                 
                a2=find(chrom2==D);                
                b2=find(chrom2==E);                
                a=find(chrom1==chrom1(a2));                
                b=sum(quantity(chrom2(a),2))+quantity(E,2);
                bb=sum(quantity(chrom2(a),3))+quantity(E,3);                
                pp1=normcdf(Qofcar,b,sqrt(bb)); 
                c=size(a,2);
                if pp1>p1                       
                    EFj=arrivetime(e)+ttimeu(E+Numberoffacilities,D+Numberoffacilities)-arrivetime(d);                    
                    if EFj<0                          
                        a1=10000;                            
                        for j=1:c                            
                            b1=find(originalchrom2==chrom2(a(j)));                            
                            Aheadtime=arrivetime(b1)-timewindow(chrom2(a(j)),2);                             
                            if Aheadtime<a1                                     
                                aheadtime=Aheadtime;                                   
                                a1=Aheadtime;                                 
                            end
                        end
                        if aheadtime>=-EFj                            
                            PD=1;                             
                        end
                    elseif EFj==0                        
                        PD=1;                             
                    elseif EFj>0                           
                        a1=10000;                         
                        for j=1:c                               
                            b1=find(originalchrom2==chrom2(a(j)));                            
                            Delaytime=timewindow(chrom2(a(j)),3)-arrivetime(b1);                              
                            if Delaytime<a1                                       
                                delaytime=Delaytime;                                     
                                a1=Delaytime;                                     
                            end
                        end

三、运行结果

四、matlab版本及参考文献

1 matlab版本
2014a

2 参考文献
[1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社,2016.
[2]张岩,吴水根.MATLAB优化算法源代码[M].清华大学出版社,2017.

以上是关于物流选址基于matlab节约算法求解考虑碳排放及带时间窗的物流选址问题含Matlab源码 1589期的主要内容,如果未能解决你的问题,请参考以下文章

matlab求解考虑碳排放的路径优化问题

matlab求解考虑碳排放的路径优化问题

matlab求解考虑碳排放的路径优化问题

matlab求解考虑碳排放的路径优化问题

优化选址基于matlab遗传算法求解物流配送中心选址含Matlab源码 1917期

物流选址基于matlab粒子群算法求解物流选址问题含Matlab源码 410期