【ACO-VRPTW】基于蚁群优化算法的时间窗的车辆配送(VRP)优化(Matlab代码实现)

本文探讨了物流行业中如何通过车辆路径优化降低运输成本并提高服务质量。文章介绍了带时间窗车辆路径问题(VRPTW)的背景及其复杂性,并提供了一个使用蚁群算法求解的Matlab代码实现。该算法旨在找到最佳配送路线,兼顾时间和成本,通过迭代更新信息并优化路径。实验结果显示了算法的运行情况及成本变化趋势。
摘要由CSDN通过智能技术生成

💥💥💥💞💞💞欢迎来到本博客❤️❤️❤️💥💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者

⛳️座右铭:行百里者,半于九十。

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

👨‍💻4 Matlab代码实现

💥1 概述

      对于物流配送企业来说,想在激烈的竞争环境中获得优势,就需要为客户提供高质量的服务,还要将成本降到最低。高效快速的商品配送能够提高客户的满意度,提高服务质量,但若盲目提高时效性,则人力需求量、运输费用、车辆需求都会大大增加,导致运输成本的增加。如何通过合理化运输来实现既能降低物流成本,又能提高物流配送的服务质量、准时为客户提供服务,对物流企业来说是一个亟待解决的问题。

       正确的选择车辆的行驶路径,制定出切实可行的车辆配送路线方案对降低成本十分关键,这类问题就是车辆路径优化问题(Vehicle Routing Problem,VRP),简称VRP问题。为了增强物流企业时效性,货物配送方和接收方约定送货时间段,若送货迟到,货物接收方有理由提出时间补偿,配送方需要向接收货物的客户支付惩罚费用,这个时间段被称为时间窗(Time Windows),在VRP的基础上加入时间窗因素,就是带时间窗车辆路径问题(Vehicle Routing Problem with Time Windows, VRPTW)。从理论研究方面来看,带时间窗车辆路径优化问题属于复杂的组合优化问题,求解复杂度较高,计算量较大,已被证实属于NP-hard问题。

📚2 运行结果

主函数代码:

clear; clc; close all;
tic
%% input 
c101 = importdata('c101.txt');
% c101 = importdata('my_test_data.xlsx');
% depot_time_window1 = c101(1,5); % time window of depot
% depot_time_window2 = c101(1,6);

depot_time_window1 = TimeTrans(c101(1,5)); % time window of depot
depot_time_window2 = TimeTrans(c101(1,6));
vertexs = c101(:,2:3); 
customer = vertexs(2:end,:); % customer locations
customer_number = size(customer,1);
% vehicle_number = 25;
% time_window1 = c101(2:end,5);
% time_window2 = c101(2:end,6);

time_window1 = TimeTrans(c101(2:end,5));
time_window2 = TimeTrans(c101(2:end,6));

width = time_window2-time_window1; % width of time window
service_time = c101(2:end,7); 
h = pdist(vertexs);
dist = squareform(h); % distance matrix
%% initialize the parameters
ant_number = floor(customer_number * 1.5);                                                  % number of ants
alpha = 4;                                                        % parameter for pheromone
beta = 5;                                                         % paremeter for heuristic information
gamma = 2;                                                        % parameter for waiting time
delta = 3;                                                        % parameter for width of time window
r0 = 0.5;                                                         % a constant to control the movement of ants
rho = 0.85;                                                       % pheromone evaporation rate
Q = 5;                                                            % a constant to influence the update of pheromene
Eta = 1./dist;                                                    % heuristic function
iter = 1;                                                         % initial iteration number
iter_max = 200;                                                    % maximum iteration number

Tau = ones(customer_number+1,customer_number+1);                  % a matrix to store pheromone
Table = zeros(ant_number,customer_number);                        % a matrix to save the route
Route_best = zeros(iter_max,customer_number);                     % the best route
Cost_best = zeros(iter_max,1);                                    % the cost of best route

iter_time = [];
last_dist = 0;
stop_count = 0;

%% find the best route 
while iter <= iter_max
    %tic;
    % ConstructAntSolutions
    for i = 1:ant_number
        for j = 1:customer_number
            r = rand;
            np = NextPoint(i,Table,Tau,Eta,alpha,beta,gamma,delta,r,r0,time_window1,time_window2,width,service_time,depot_time_window2,dist);
            Table(i,j) = np;
        end
    end
    %% calculate the cost for each ant
    cost = zeros(ant_number,1);
    NV = zeros(ant_number,1);
    TD = zeros(ant_number,1);
    for i=1:ant_number
        VC = decode(Table(i,:),time_window1,time_window2,depot_time_window2,service_time,dist);
        [cost(i,1),NV(i,1),TD(i,1)] = CostFun(VC,dist);
    end
    %% find the minimal cost and the best route
    if iter == 1
        [min_Cost,min_index] = min(cost);
        Cost_best(iter) = min_Cost;
        Route_best(iter,:) = Table(min_index,:);
    else
        % compare the min_cost in this iteration with the last iter
        [min_Cost,min_index] = min(cost);
        Cost_best(iter) = min(Cost_best(iter - 1),min_Cost); 
        if Cost_best(iter) == min_Cost
            Route_best(iter,:) = Table(min_index,:);
        else
            Route_best(iter,:) = Route_best((iter-1),:);
        end
    end
    %% update the pheromene
    bestR = Route_best(iter,:); % find out the best route
    [bestVC,bestNV,bestTD] = decode(bestR,time_window1,time_window2,depot_time_window2,service_time,dist); 
    Tau = updateTau(Tau,bestR,rho,Q,time_window1,time_window2,depot_time_window2,service_time,dist);

    %% print 
    disp(['Iterration: ',num2str(iter)])
    disp(['Number of Robots: ',num2str(bestNV),', Total Distance: ',num2str(bestTD)]);
    fprintf('\n')
    %
    iter = iter+1;
    Table = zeros(ant_number,customer_number);
    
    %iter_time(iter) = toc;
    
%     if last_dist == bestTD
%         stop_count = stop_count + 1;
%         if stop_count > 30
%             break;
%         end
%     else
%         last_dist = bestTD;
%         stop_count = 0;
%     end
    
end
%% draw
bestRoute=Route_best(iter-1,:);
[bestVC,NV,TD]=decode(bestRoute,time_window1,time_window2,depot_time_window2,service_time,dist);
draw_Best(bestVC,vertexs);
figure(2)
plot(1:iter_max,Cost_best,'b')
xlabel('Iteration')
ylabel('Cost')
title('Change of Cost')
%% check the constraints, 1 == no violation
flag = Check(bestVC,time_window1,time_window2,depot_time_window2,service_time,dist)

toc

🎉3 参考文献

[1]胡俊桥. 蚁群混合算法求解带时间窗车辆路径问题[D].西安科技大学,2017.

[2]魏志秀. 基于改进蚁群算法研究带时间窗的配送车辆路径优化问题[D].江苏大学,2021.DOI:10.27170/d.cnki.gjsuu.2021.002182.

👨‍💻4 Matlab代码实现

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荔枝科研社

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值