【路径规划】邮政运输网络中的邮路规划和邮车调度【含Matlab源码 648期】

86 阅读3分钟

一、简介

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
2 问题分析
在这里插入图片描述
3 基本假设
在这里插入图片描述
在这里插入图片描述
4 符号说明
在这里插入图片描述
5 模型的建立与求解
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
模型2 区级邮路
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、源代码

clear,clc
%问题一求解 
m=[5,5,6];%三个车队的分组数

B = [10 15 6 9 13 6 11 4 13 17 11 2 11 21 13 14;
    9 14 5 10 9 10 13 9 15 9 6 7 13 15 10 16];%问题116个支局收寄邮件数量

%问题一各个支局之间的距离矩阵
% dist=[0    31    27    49   Inf   Inf   Inf   Inf   Inf   Inf   Inf    52    21    41   Inf   Inf    27;
%     31     0    19   Inf    27    32   Inf   Inf   Inf    47   Inf   Inf   Inf    50   Inf   Inf    44;
%     27    19     0    14   Inf   Inf   Inf   Inf   Inf    30   Inf   Inf   Inf    31   Inf   Inf    17;
%     49   Inf    14     0    13    20   Inf   Inf    28    15   Inf   Inf   Inf    15    25    30    11;
%    Inf    27   Inf    13     0     9    21   Inf    26    26   Inf   Inf   Inf    28    29   Inf    27;
%    Inf    32   Inf    20     9     0    13   Inf    32   Inf   Inf   Inf   Inf   Inf    33   Inf    42;
%    Inf   Inf   Inf   Inf    21    13     0    19   Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf;
%    Inf   Inf   Inf   Inf   Inf   Inf    19     0    11    20   Inf   Inf   Inf   Inf    33    21   Inf;
%    Inf   Inf   Inf    28    26    32   Inf    11     0    10    20   Inf   Inf    29    14    13   Inf;
%    Inf    47    30    15    26   Inf   Inf    20    10     0    18   Inf   Inf    14     9    20    20;
%    Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf    20    18     0    23   Inf   Inf    14   Inf    25;
%     52   Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf    23     0    27    22   Inf   Inf    21;
%     21   Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf   Inf    27     0   Inf   Inf   Inf    21;
%     41    50    31    15    28   Inf   Inf   Inf    29    14   Inf    22   Inf     0    11   Inf    18;
%    Inf   Inf   Inf    25    29    33   Inf    33    14     9    14   Inf   Inf    11     0     9    27;
%    Inf   Inf   Inf    30   Inf   Inf   Inf    21    13    20   Inf   Inf   Inf   Inf     9     0   Inf;
%     27    44    17    11    27    42   Inf   Inf   Inf    20    25    21    21    18    27   Inf  0]

p1=[];p2=[];p3=[];pp1=[];pp2=[];pp3=[];
cost0 = 100;distan0=0;

for i=1:100000
    S=randperm(16);
    p1=S(1:m(1));
    if sum(B(1,p1))>65 | sum(B(1,p1))<46 | sum(B(2,p1))>65 | sum(B(2,p1))<40
        continue;
    end
    p1(m(1)+1)=17;
    [cost1, distan1] = vrp_cost(p1);
    if distan1/30+5*m(1) > 360
        continue;
    end
    
    p2=S(m(1)+1:m(1)+m(2));
    if sum(B(1,p2))>65 | sum(B(1,p2))<46 | sum(B(2,p2))>65 | sum(B(2,p2))<40
        continue;
    end
    p2(m(2)+1)=17;
    [cost2, distan2] = vrp_cost(p2);
    if distan2/30+5*m(2) > 360
        continue;
    end
    
    p3=S(m(1)+m(2)+1:16);
    if sum(B(1,p3))>65 | sum(B(1,p3))<46 | sum(B(2,p3))>65 | sum(B(2,p3))<40
        continue;
    end
    p3(m(3)+1)=17;
    [cost3, distan3] = vrp_cost(p3);
    if distan3/30+5*m(3) > 360
        continue;
    end
    
    cost=cost1+cost2+cost3;distan=distan1+distan2+distan3;
    if cost<cost0
        cost10=cost1;cost20=cost2;cost30=cost3;
        distan10=distan1;distan20=distan2;distan30=distan3;
        cost0=cost;distan0=distan;
        pp1=p1;pp2=p2;pp3=p3;
    end
end

pp1
cost10
distan10

pp2
cost20
distan20
function [ sum_cost,sum_dist] = vrp_cost(s)

%计算因空车率而减少的收入
%sum_cost为总减少的收入,sum_dist为总路程
B = [10 15 6 9 13 6 11 4 13 17 11 2 11 21 13 14;
    9 14 5 10 9 10 13 9 15 9 6 7 13 15 10 16];%问题116个支局收寄邮件数量

% 各个支局之间的最短距离
D=[  0    31    27    38    51    58    71    67    57    47    52    48    21    41  52    61    27;
    31     0    19    33    27    32    45    64    53    47    61    57    52    48 56    63    36;
    27    19     0    14    27    34    47    49    39    29    42    38    38    29    38    44    17;
    38    33    14     0    13    20    33    35    25    15    33    32    32    15    24    30    11;
    51    27    27    13     0     9    21    37    26    26    43    45    45    28    29    38    24;
    58    32    34    20     9     0    13    32    32    35    47    52    52    35    33    42    31;
    71    45    47    33    21    13     0    19    30    39    50    65    65    48    44    40    44;
    67    64    49    35    37    32    19     0    11    20    31    54    61    34    25    21    40;
    57    53    39    25    26    32    30    11     0    10    20    43    51    24    14    13    30;
    47    47    29    15    26    35    39    20    10     0    18    36    41    14   9    18    20;
    52    61    42    33    43    47    50    31    20    18     0    23    46    25   14    23    25;
    48    57    38    32    45    52    65    54    43    36    23     0    27    22    33    42    21;
    21    52    38    32    45    52    65    61    51    41    46    27     0    39    48    57    21;
    41    48    29    15    28    35    48    34    24    14    25    22    39     0    11    20    18;
    52    56    38    24    29    33    44    25    14     9    14    33    48    11     0     9    27;
    61    63    44    30    38    42    40    21    13    18    23    42    57    20     9     0    36;
    27    36    17    11    24    31    44    40    30    20    25    21    21    18    27    36     0];

 
end

C=65;
sum_dist=D(17,s(1));
 

for i=1:n-1
    carry=carry-B(1,s(i))+B(2,s(i));
    if carry>C
        carry=C;
    end
    EmpRate=1-carry/C;
    
    sum_dist=sum_dist+D(s(i),s(i+1));
end
clc,clear
%TSP算法求最短路径
A = xlsread('shuju1.xls','A2:C341');
distance=zeros(79);
for i=1:340
    for j=1:79
        for k=1:79
            if A(i,1)==j & A(i,2)==k
                distance(j,k)=A(i,3);
            end
        end
    end
end
distance=distance+distance';
distance(find(distance==0))=inf;
for i=1:79
    for j=1:79
        if i==j
            distance(i,j)=0;
        end
    end
end

%以下是市局到县局经过的点
x1=[62 8 9 10 74 14 15 11 16];%注:由于X1特殊,此圈中暂时不包含X1点,求出距离后再把X1添上
x2=[79 66 63 18 75 17 27 64 65 67];
x3=[79 28 29 30 31 32 33 68 69 70 76 34 35];
x4=[79 72 73 41 42 43 36 71 77];
x5=[79 61 60 59 53 78 52 58];

%以下是县局内部经过的支局点
xx1=[1:8 12 13 74];
xx1_1=[1 12 13];
xx1_2=[2:7];
xx2=[19:26 75];
xx4=[37:40 77];
xx5=[44:51 54:57 78];
xx5_1=[54:57 78];
xx5_2=[44:51 78];

x=xx1_2;

L=size(x,2);
for i=1:L
    for j=1:L
        a(i,j) = distance(x(i),x(j));
    end
end

三、运行结果

在这里插入图片描述

四、备注

版本:2014a