1 简介
车辆路径优化问题是典型的组合优化问题,是基于系统优化的思想,对运输作业服务中车辆的路径进行优化的方式,以达到运输作业服务中目标函数最优化的问题。随着经济节奏的加快对运输作业服务所提出的要求多样化,以及车辆路径优化问题研究的深入,车辆路径优化问题衍生出了数量繁多的种类、取得了不菲的成就,也更一步贴近了实际运输作业服务所面临的场景。本文采用水滴算法求解多仓库车辆路径规划问题。
智能水滴算法是一种群智能算法,它通过模拟自然界水系统和其周围环境的相互作用而形成河道的过程进行迭代运算,最终获得优化结果。在自然界的河道中有无数流动着的水滴,这些流动的水滴与河道具有作用与反作用的关系。一方面,无数流动的水滴形成巨大的移动群体,这个巨大的水滴群体创造了河流流经的河道; 另一方面河道本身也在影响着水滴的流向。如果河道中没有障碍物,那么水滴会以直线路径到达目的地,形成水滴流动的最短路径。如果有障碍物存在,水滴就会改变流动路径,形成弯曲的河道。经过科学家的研究发现,在考虑河流从源点到目的地的距离和中间障碍物存在的情况下,水滴建立起来的河道往往是最优的。流动中水滴具有一定的速度和携带一定量的泥土,水滴能够将泥土从一个地方搬运到另一个地方。由于水滴速度越快其动能越大,因此泥土会从流速较高的地方被搬运到流速较低的地方; 当流速减缓时,泥土在地球重力作用下会沉积下来。水滴流速快的地方随着时间推移会变得越来越深,同时越来越深的河道又会吸引后续更多的水滴。因此,自然界中水滴与泥土的关系满足三个规则: ( 1) 流速快的水滴比流速慢的水滴携带更多的泥土; ( 2) 水滴在泥土较少的路径比泥土较多的路径获得更多的速度增量; ( 3) 水滴会以更大的概率选择泥土较少的路径前进。在智能水滴算法中,水滴具有两个属性: 水滴前进的速度和水滴携带的泥土量。这两个属性在水滴的流动过程中不断变化,目的是寻找一条最优路径。由于智能水滴有有效汇聚的能力,所以,随着迭代次数的增大,该算法找到最优解的概率也随之增大。为了简化问题,在智能水滴算法迭代过程中,假设水滴是按照离散步骤运动的。
2 部分代码
clc; close all; clear all;
%% Variable initialization
iterations = 60;
pIter = 3; % # of parallel sol'ns calculated to find totalbest
stats = zeros(iterations, 2); % rows are iteration number, columns are best/worst
% Initial variables
tempInit = 150; % initial temperature for SA
temp = tempInit;
tempDec = 0.95; % temperature decrease rate
tempIter = 1; % number of iterations at each step
soilInit = 1000;
velocityInit = 100;
a_v = 1000; a_s = 1000;
b_v = 0.01; b_s = 0.01;
c_v = 1; c_s = 1;
vel_params = [a_v b_v c_v];
soil_params = [a_s b_s c_s];
% Soil updating params
rho_o = 0.9;
rho_n = 1 - rho_o;
% Global soil updating params
rho_s = 0.8;
rho_iwd = -1.5;
% Data sets
pind = 1; % problem index
problempath = './../data/problems/';
problemfiles = { 'p01', 'p02', 'p03', 'p04', 'p05' };
solutionpath = './../data/solutions/';
solutionfiles = { 'p01.res', 'p02.res', 'p03.res', 'p04.res', 'p05.res' };
%% Load and format data
% Grab the first fileset
[desc, depot_desc, cust, depot] = parseProblemSet(strcat(problempath, problemfiles{pind}));
num_customers = desc(3);
num_depots = desc(4);
num_vehicles = desc(2);
all_coords = [cust(:,2:3); depot(:,2:3)];
% Build adjacency matrix row is source, col is dest
[ distMat globalSoilMat ] = prepareBoard(desc, depot_desc, cust, depot, soilInit);
soilMat = globalSoilMat;
% Soil weightings based on edge length
soilMat = log(distMat+1).*globalSoilMat; %logarithmic
%soilMat = distMat.*globalSoilMat; %linear
%soilMat = exp(distMat).*globalSoilMat; %exponential
soilMat = normalizeSoilMat(soilMat, soilInit);
globalSoilMat = soilMat; % globalSoilMat contains the soil going forward
%% Initialize agents
for i = 1:pIter
dropstemp = [];
for d = 1:num_depots % for each depot
for v = 1:num_vehicles % populate vehicles
dep = depot(d,1);
capacity = depot_desc(d,2);
dropstemp = [ dropstemp; WaterDrop(dep,capacity,velocityInit, ...
vel_params, soil_params) ];
end
end
drops(:, 1, i) = dropstemp;
end
clear dropstemp;
% Best solution
best_sol = 0;
best_cost = 0;
temp_counter = 0;
hold on;
for i = 1:length(best_sol)
r = best_sol(i).route;
r_coord = all_coords(r,:);
A = zeros(length(r));
for j = 2:length(r)
A(j-1, j) = 1;
end
gplot(A, r_coord, colours(mod(i,6)+1));
end
title(['Best MDVRP Routes by IWD Meta-Heuristic for ', num2str(iterations), ' Iterations']);
xlabel('x coordinate');
ylabel('y coordinate');
hold off;
% visualize the stats
f = figure;
plot(stats(:, 1), 'Color', 'b');
hold on
plot(stats(:, 2), 'Color', 'r');
title('IWD Solution Cost Iteration');
xlabel('Iteration');
ylabel('Route Cost');
legend('Best solution', 'Worst Solution');
% error with respect to optimal solution
figure;
best_sol_error = 100*(stats(:,1) - sol_cost)/sol_cost;
worst_sol_error = 100*(stats(:,2) - sol_cost)/sol_cost;
plot(best_sol_error, 'Color', 'b');
hold on
plot(worst_sol_error, 'Color', 'r');
title('IWD Solution Error with Respect to Optimal');
xlabel('Iteration');
ylabel('Route Cost Error (%)');
legend('Best solution', 'Worst Solution');
ylim([0, 400]);
3 仿真结果
4 参考文献
[1]唐小刚. 半开放式多配送中心多车型车辆路径优化问题研究. Diss. 广东工业大学, 2015.
[2]李珍萍, 赵菲, and 刘洪伟. "多时间窗车辆路径问题的智能水滴算法." 运筹与管理 24.6(2015):10.
部分理论引用网络文献,若有侵权联系博主删除。
5 MATLAB代码与数据下载地址
见博客主页