2021-03-10 带时间窗口的路径规划 (使用Local Solver求解实例学习)

本文介绍了一个使用Local Solver解决带时间窗口的路径规划问题的实例。问题涉及车辆路径规划,目标是最小化车队规模和总行驶距离,同时满足车辆容量和服务时间限制。文章提供了一个C#调用Local Solver的源代码示例,详细解释了模型构建过程,包括递归数组定义和时间窗口处理。并提供了数据文件和模型下载链接。
摘要由CSDN通过智能技术生成

带时间窗口的路径规划 (使用Local Solver求解实例学习)

学到的原则

  1. 添加多个列表决策变量
  2. 定义表达式序列
  3. 使用lambda表达式定义递归数组

 

在带时间窗的有限能力车辆路径问题(CVRPTW)中,一个具有统一能力的车队必须以已知的需求和单一商品的开放时间为顾客服务。车辆在公共车场开始和结束其路线。每位客户只能乘坐一辆车。其目标是使车队规模最小化,并为车队中的每辆卡车分配一系列客户,使总行驶距离最小化,以便为所有客户提供服务,并且每辆卡车提供的总需求不超过其容量。

 

数   据

提供的实例来自Solomon实例

数据文件的格式如下:

  1. 第一行给出实例的名称
  2. 第五行包含车辆数量及其共同能力
  3. 从第10行开始,每行包含与每个客户相关联的整数数据,从仓库开始:
  4. 客户的索引
  5. x坐标
  6. y坐标
  7. 需求
  8. 最早到达
  9. 最晚到达
  10. 服务时间

程   序

LocalSolver模型是CVRP模型的扩展。我们让读者参考这个模型来了解问题的路由方面。时间窗口作为首要目标处理。如果提前到达,卡车必须等待客户的营业时间。在迟到的情况下,记录迟到时间,并将总迟到时间降至最低。当累计延迟为零时,该方法是可行的。

在该模型中,每辆卡车的结束时间被定义为一个递归数组。到达时间最长为:

  1. 上次访问的结束时间加上行走时间(在这些情况下等于距离)。对于第一次访问,它等于从车站出发的旅行时间(从t=0开始)
  2. 最早允许到达该客户的时间

结束时间仅仅是这个到达时间加上这个客户的服务时间。旅行结束时到达车站的时间为最后一次访问的结束时间加上从该点回到车站的旅行时间。

这种递归定义是通过函数(i,prev)=>。。。。它允许定义数组的第i个元素和数组的第(i-1)个元素的函数。有关详细信息,请参阅我们关于此主题的文档。

 

每次访问的延迟时间是根据此访问的结束时间与此客户允许的最晚结束时间之间的差来计算的。对于到达车站,我们将到达时间与为问题定义的最大展望期进行比较。

最后,我们按字典顺序最小化:总迟到时间、使用的卡车数量和所有卡车行驶的总距离。

以下为问题的源代码,下载链接在最后一行! 更多问题,请联系LocalSolver中国代理商“无锡迅合信息科技有限公司”技术人员。

C#调用LOCAL SOLVER源代码

Compilation / Execution (Windows)

copy %LS_HOME%\bin\localsolvernet.dll .

csc Cvrptw.cs /reference:localsolvernet.dll

Cvrp instances\R101.25.txt

/********** Cvrptw.cs **********/

 

using System;

using System.IO;

using System.Collections.Generic;

using localsolver;

 

public class Cvrptw : IDisposable

{

    // Solver

    LocalSolver localsolver;

 

    // Number of customers (= number of nodes minus 1)

    int nbCustomers;

 

    // Capacity of the trucks

    int truckCapacity;

 

    // Latest allowed arrival to depot

    int maxHorizon;

 

    // Demand on each node

    List<int> demands;

 

    // Earliest arrival on each node

    List<int> earliestStart;

 

    // Latest departure from each node

    List<int> latestEnd;

 

    // Service time on each node

    List<int> serviceTime;

 

    // Distance matrix between customers

    double[][] distanceMatrix;

 

    // Distances between customers and warehouse

    double[] distanceWarehouses;

 

    // Number of trucks

    int nbTrucks;

 

    // Decision variables

    LSExpression[] customersSequences;

 

    // Are the trucks actually used

    LSExpression[] trucksUsed;

 

    // Distance traveled by each truck

    LSExpression[] routeDistances;

 

    // End time array for each truck

    LSExpression[] endTime;

 

    // Home lateness for each truck

    LSExpression[] homeLateness;

 

    // Cumulated Lateness for each truck

    LSExpression[] lateness;

 

    // Cumulated lateness in the solution (must be 0 for the solution to be valid)

    LSExpression totalLateness;

 

    // Number of trucks used in the solution

    LSExpression nbTrucksUsed;

 

    // Distance traveled by all the trucks

    LSExpression totalDistance;

 

    public Cvrptw()

    {

        localsolver = new LocalSolver();

    }

 

    // Reads instance data.

    void ReadInstance(string fileName)

    {

        ReadInputCvrptw(fileName);

    }

 

    public void Dispose()

    {

        if (localsolver != null)

            localsolver.Dispose();

    }

 

    void Solve(int limit)

    {

        // Declares the optimization model.

        LSModel model = localsolver.GetModel();

 

        trucksUsed = new LSExpression[nbTrucks];

        customersSequences = new LSExpression[nbTrucks];

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
>