有时间窗车辆路径问题(vehicle routing problems with time windows,VRPTW)车辆路线问题(VRP)最早是由Dantzig和Ramser于1959年首次提出,它是指一定数量的客户,各自有不同数量的货物需求,配送中心向客户提供货物,由一个车队负责分送货物,组织适当的行车路线,目标是使得客户的需求得到满足,并能在一定的约束下,达到诸如路程最短、成本最小、耗费时间最少等目的。
clear;clc;
close all;
format long;
global strTtile;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% VRPTW参数
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
global site X capacity demand siteStart siteFinish start finish service velocity;
capacity = 8; %车辆装载量
velocity = 55/60; %km/min
demand = []; %需求
start = []; %开始时间
finish = []; %结束时间
service = []; %服务时间
%site = data(1,:);
site = [122.275563,43.607704];
siteStart = 360*velocity;
siteFinish = 1080*velocity;
% X = data(2:50,:);
X = [122.27678,43.718268
% 122.57678,44.118268
% 122.787946,43.135897
123.323948,44.132521
122.360879,42.955817
121.781823,42.743228
120.785148,42.40258
121.321807,43.59698];
% demand = demand(2:50,:);
demand = [3
% 3
% 2.5
4.5
3.5
4.2
3.2
4.6];
timeWindow = [13 15
% 5 12
% 8 16
12 18
7 17
8 16
8 16
8 16]*60;
start = timeWindow(:,1)*velocity;
finish = timeWindow(:,2)*velocity;
service = [0.4
% 0.3
% 0.2
0.1
0.6
0.3
0.1
0.3]*60*velocity;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 遗传算法优化
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NIND=10; %种群大小
MAXGEN=50; %代数
Pc=0.9; %交叉概率
Pm=0.1; %变异概率
GGAP=0.9; %代沟(Generation gap)
D=Distanse(X); %生成距离矩阵
siteD=SiteDistance(site,X); %货仓到各个节点的距离
N=size(D,1); %(34*34)
%% 初始化种群
Chrom=InitPop(NIND,N);
%% 在二维图上画出所有坐标点
% figure
% plot(X(:,1),X(:,2),'o');
%% 画出随机解的路线图
% DrawPath(Chrom(1,:),X)
pause(0.0001)
%% 输出随机解的路线和总距离
disp('初始种群中的一个随机值:')
OutputPath(siteD,D,Chrom(1,:));
Rlength=PathLengthForDemo(siteD,D,Chrom(1,:),false);
disp(['总距离:',num2str(Rlength)]);
disp('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
%% 未优化前路径
[len,result] = PathLengthForDemo(siteD,D,Chrom(1,:),true);
strTtile = '未优化前路径';
DrawPath(Chrom(1,:),site,X,result{1})
%% 优化
tic
gen=0;
figure(100);
hold on;box on
xlim([0,MAXGEN])
title('遗传算法GA 优化过程')
xlabel('代数')
ylabel('最优值')
ObjV=PathLengthForDemo(siteD,D,Chrom,false); %计算路线长度
preObjV=min(ObjV);
while gen
QQ 3538518672
微信 ssttoonn123
顾问费400元