运筹系列92:vrp算法包VROOM

1. 介绍

VROOM is an open-source optimization engine written in C++20 that aim at providing good solutions to various real-life vehicle routing problems (VRP) within a small computing time.
可以解决如下问题:
TSP (travelling salesman problem)
CVRP (capacitated VRP)
VRPTW (VRP with time windows)
MDHVRPTW (multi-depot heterogeneous vehicle VRPTW)
PDPTW (pickup-and-delivery problem with TW)

2. 入门

安装:pip install pyvroom
注意vroom目前在mac m系列上还无法编译通过。

2.1 基本样例

基础用法样例,需要输入:

  1. 距离矩阵
  2. 车辆清单
  3. 工作清单
import vroom
problem_instance = vroom.Input()
problem_instance.set_durations_matrix(profile="car",matrix_input=[[0, 2104, 197, 1299],[2103, 0, 2255, 3152],[197, 2256, 0, 1102],[1299, 3153, 1102, 0]],)
problem_instance.add_vehicle([vroom.Vehicle(47, start=0, end=0),vroom.Vehicle(48, start=2, end=2)])
problem_instance.add_job([vroom.Job(1414, location=0), vroom.Job(1515, location=1),vroom.Job(1616, location=2),vroom.Job(1717, location=3)])
solution = problem_instance.solve(exploration_level=5, nb_threads=4)
solution.routes[["vehicle_id", "type", "arrival", "location_index", "id"]]

输出为
在这里插入图片描述
其中id为job的编号,location index为地点的编号。

2.2 文件输入

也可以通过json文件输入:

{ "vehicles": [{"id":0, "start_index":0, "end_index":3} ],"jobs": [{"id":1414,"location_index":1},{ "id":1515,"location_index":2}],"matrices": { "car": {"durations": [ [0,2104,197,1299],[2103,0,2255,3152],[197,2256,0,1102],[1299,3153,1102,0]]}}
}

然后使用命令行:
vroom -i test2.json
结果如下:
在这里插入图片描述

2.3 调用引擎

VROOM可以通过下面几个引擎来计算距离:OSRM,Openrouteservice,Valhalla。在Input中指定servers和router即可,基础用法样例:

import vroom
problem_instance = vroom.Input(servers={"auto": "valhalla1.openstreetmap.de:443"},router=vroom._vroom.ROUTER.VALHALLA)
problem_instance.add_vehicle(vroom.Vehicle(1, start=(2.44, 48.81), profile="auto"))
problem_instance.add_job([vroom.Job(1, location=(2.44, 48.81)),vroom.Job(2, location=(2.46, 48.7)),vroom.Job(3, location=(2.42, 48.6)),])
sol = problem_instance.solve(exploration_level=5, nb_threads=4)
print(sol.summary.duration)

The only difference is no need to define the duration/distance matrix.

3. 详细介绍

详见:https://github.com/VROOM-Project/vroom/blob/master/docs/API.md
需要定义

  1. resources (vehicles)
  2. single-location pickup and/or delivery tasks (jobs/shipments)
  3. 如果没有指定经纬度和地图server的话,则需要定义matrices

3.1 jobs/shipments

最基础的版本需要定义id和location。location可以是编号(如果已经给了matrix),也可以是坐标,也可以是封装了坐标的vroom.Location。
剩下的顾名思义:1)如果有时间窗约束的话,需要定义timewindows,可选setup,service;2)如果是pickup&delivery问题的话,可以定义pickup和delivery的数量;3)可以用skills约束车辆和路径的匹配关系;4)可以用priority提升或降低任务的优先级。

    id:Job identifier number. Two jobs can not have the sameidentifier.location:Location of the job. If interger, value interpreted as an thecolumn in duration matrix. If pair of numbers, valueinterpreted as longitude and latitude coordinates respectively.setup:The cost of preparing the vehicle before actually going out fora job.service:The time (in secondes) it takes to pick up/deliver shipmentwhen at customer.delivery:The amount of how much is being carried to customer.pickup:The amount of how much is being carried back from customer.skills:Skills required to perform job. Only vehicles which satisfiesall required skills (i.e. has at minimum all skills valuesrequired) are allowed to perform this job.priority:The job priority level, where 0 is the lowest priorityand 100 is the highest priority.time_windows:Windows for where service is allowed to begin.Defaults to have not restraints.

shipments其实和job没有太大差别,可用于定义dial-a-ride类型的问题。
首先定义shipmentStep,字段包括:

    id:Job identifier number. Two jobs can not have the sameidentifier.location:Location of the job. If interger, value interpreted as an thecolumn in duration matrix. If pair of numbers, valueinterpreted as longitude and latitude coordinates respectively.setup:The cost of preparing the vehicle before actually going out fora job.service:The time (in secondes) it takes to pick up/deliver shipmentwhen at customer.time_windows:Windows for where service is allowed to begin.Defaults to have not restraints.description:Optional string descriping the job.

然后定义shipment:

    pickup:Description of the pickup part of the shipment.delivery:Description of the delivery part of the shipment.amount:An interger representation of how much is being carried backfrom customer.skills:Skills required to perform job. Only vehicles which satisfiesall required skills (i.e. has at minimum all skills valuesrequired) are allowed to perform this job.priority:The job priority level, where 0 is the lowest priorityand 100 is the highest priority.

3.2 vehicles

定义vehicle一定要配置id,start和end。其他可配属性如下:

    id:Vehicle idenfifier number. Two vehicle can not have the sameidentifier.start:The location where the vehicle starts at before any jobs are done.If omitted, the vehicle will start at the first task it will beassigned. If interger, value interpreted as an the column induration matrix. If pair of numbers, value interpreted as longitudeand latitude coordinates respectively.end:The location where the vehicle should end up after all jobs arecompleted. If omitted, the vehicle will end at the last task itwill be assigned. If interger, value interpreted as an the columnin duration matrix. If pair of numbers, value interpreted aslongitude and latitude coordinates respectively.profile:The name of the profile this vehicle falls under.capacity:Array of intergers representing the capacity to carry differentgoods.skills:Skills provided by this vehilcle needed to perform various tasks.time_window:The time window for when this vehicle is available for usage.breaks:Breaks this vehicle should take.description:Optional string descriping the vehicle.speed_factor:The speed factor for which this vehicle runs faster or slower thanthe default.max_tasks:The maximum number of tasks this vehicle can perform.steps:Set of custom steps this vehicle should take.

如果我们需要指定一辆车的已分配工作,可以用VehicleStep类指定:

    step_type:The type of step in question. Choose from: `start`, `end`, `break`,`single`, `pickup`, and `delivery`.id:Reference to the job/break the step is associated with.Not used for `step_type == "start"` and `step_type == "end"`.service_at:Hard constraint that the step in question should be performedat a give time point.service_after:Hard constraint that the step in question should be performedafter a give time point.service_before:Hard constraint that the step in question should be performedbefore a give time point.

3.3 其他

vroom.break:指定午休时间等

    id:Job identifier number. Two jobs can not have thesame identifier.time_windows:Time windows for where breaks is allowed to begin.Defaults to have not restraints.service:The time duration of the break.description:A string describing this break

4. 输出

输出包括:
code:status code
error:error message (present iff code is different from 0)
summary:object summarizing solution indicators
unassigned:array of objects describing unassigned tasks with their id, type, and if provided, description, location and location_index
routes:array of route objects

4.1 code

在这里插入图片描述

4.2 summary

提供汇总信息,字段包括:
在这里插入图片描述

4.3 routes

展示具体路径,包括如下字段
在这里插入图片描述
routes中的每一行都是一个step类型:
在这里插入图片描述
其中violation对应的字段含义为:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/1421541.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

Linux提权--SUDO(CVE-2021-3156)Polkit(CVE-2021-4034)

免责声明:本文仅做技术学习与交流... 目录 SUDO(CVE-2021-3156) 影响版本 -判断: -利用: Polkit(CVE-2021-4034) ​ -判断: -利用: 添加用户 SUDO(CVE-2021-3156) another: SUDO权限配置不当. 影响版本 由系统的内核和发…

MODIFY DUMP

写了一个modify的语句,但是dump了 查阅资料 参考一下链接 ABAP 内表修改 MODIFY 和 MODIFY table 的区别-CSDN博客

品鉴中的风味轮:如何运用专业工具解读红酒的复杂风味

品鉴云仓酒庄雷盛红酒时,我们常常会遇到各种各样复杂的味道。为了更好地理解和描述这些风味,专业工具——风味轮被引入到红酒品鉴中。通过运用风味轮,我们可以更科学、更具体地解读红酒的复杂风味。 风味轮是一种包含一系列风味和味道描述的圆…

PCIE协议-2-事务层规范-Message Request Rules-Vendor_Defined Messages

2.2.8.6 厂商定义消息 厂商定义消息允许扩展PCI Express消息功能,可以作为PCI Express规范的一般扩展,也可以是厂商特定的扩展。本节通用地定义了与这些消息相关的规则。 厂商定义消息(见表2-25)使用图2-28中显示的头标格式。re…

【车企招聘】Android车载开发全套学习资料(收藏版)

前言 随着人工智能技术的迅速发展,智能车机系统已成为汽车行业的热门趋势,旨在提升驾乘人员的体验和安全性。在中高端车型中广泛应用智能车机系统,其中包含了语音识别控制、人脸识别、手势识别、智能紧急刹车等功能,为驾驶者提供…

常用的内外网文件传输方式及优缺点

在现代企业环境中,内外网文件传输是一项至关重要的任务。这涉及到数据的安全性、传输效率以及操作的便捷性等多个方面。 每种方式都有其独特的优缺点,下面我们将逐一进行分析。 1、FileLink 优势:FileLink是一款专用于企业内外网隔离后的文…

MySQL从入门到高级 --- 6.函数

文章目录 第六章:6.函数6.1 聚合函数6.2 数学函数6.3 字符串函数6.4 日期函数6.4.1 日期格式 6.5 控制流函数6.5.1 if逻辑判断语句6.5.2 case when语句 6.6 窗口函数6.6.1 序号函数6.6.2 开窗聚合函数6.6.3 分布函数6.6.4 前后函数6.6.5 头尾函数6.6.6 其他函数6.7 …

申贷时,银行级大数据自己能查到吗?

随着金融风控的不断健全,大数据作为辅助的风控工具正在被越来越多的银行和机构使用。在进行申贷时,银行通常会进行大数据查询,以便评估申请人的信用状况。那么,这些大数据自己能查到吗?接下来本文就为大家详细介绍一下&#xff0…

怎样才能不当数据泄露的下一个受害者?

在数字化时代,数据泄露成为了所有企业必须面对的难题。无论规模大小,每家公司都可能成为黑客攻击的目标,从而遭受数据泄露的风险。然而,通过采取一系列预防措施,企业可以极大地降低成为下一个受害者的可能性。 教育员…

哪些AI软件可以帮助我快速制作PPT?推荐几个aippt工具

提起PPT,大家的第一反应就是痛苦。经常接触PPT的学生党和打工人,光看到这3个字母,就已经开始头痛了: 1、PPT内容框架与文案挑战重重,任务艰巨,耗费大量精力。 2、PPT的排版技能要求高,并非易事…

paddle ocr v4 2.6.1实战笔记

目录 效果图: 安装 模型权重是自动下载,如果提前下载会报错。 识别orc,并opencv可视化结果,支持中文可视化 官方原版预测可视化: 效果图: 安装 安装2.5.2识别结果为空 pip install paddlepaddle-gpu…

如何通过香港站群服务器高效实现网站内容的快速更新?

如何通过香港站群服务器高效实现网站内容的快速更新? 在当今激烈的数字市场竞争中,网站内容的快速更新对于吸引用户和保持竞争优势至关重要。而利用香港站群服务器实现这一目标,则具备诸多优势。下面将详细探讨如何通过香港站群服务器高效实现网站内容…

tomcat 的启动流程

tomcat 的启动流程 中 使用的Lifecycle 生命流程 。在这里还使用了设计模式中的模板模式(LifecycleBase 是一个模板类) init()方法 start() 方法 container 的处理

Linux修炼之路之权限

目录 引言 一:Linux中用户的分类 二:在Linux中的权限 1.权限的两种属性 1.人的属性 2.事物属性 -主要以文件属性为主 3.文件权限值的两种表示方式方法 2.更改文件访问者(拥有者,所属组,其他人)权限属性 3.更改文件的拥有…

FastAPI:Python打造高效API的终极武器

在Python的世界里,如果你想要一个既快速又现代的方式来构建API,那么FastAPI可能是你的首选。这个库基于Starlette(用于Web编程)和Pydantic(用于数据验证),专门为速度和易用性设计。 什么是FastA…

微信小程序Vue+uniapp餐饮美食订餐骑手配送系统9g60o

本小程序uniapp菜品帮采用Java语言和Mysql数据库进行设计,技术采用微信小程序,可以不安装App软件就实现订餐。本系统实现管理员和用户、商家、配送员四个角色的功能。用户主要在微信端操作,内容有菜品信息,用户可以在线点餐和管理…

能源管理系统中,倍讯科技Modbus TCP转CAN网关具体的连接方案

在能源管理系统中,使用倍讯科技Modbus TCP转CAN网关的连接方案通常涉及以下几个步骤: 1. 设备调研与规划: 首先,需要了解能源管理系统中所涉及的各种设备和传感器,以及它们所使用的通信协议和接口类型。 确定需要连接…

使用System.Drawing进行几何图形绘制

1.概要 使用System.Drawing进行几何图形绘制 System.Drawing 是.NET框架中的一个命名空间,提供了基本的绘图功能,包括绘制几何图形(如矩形、椭圆、线条等)。它通常用于Windows Forms应用程序中的绘图。你可以使用 Graphics 类来…

上位机图像处理和嵌入式模块部署(树莓派4b 应用的注意事项)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing 163.com】 树莓派系列开发板最早的时候,价格还是比较高的。不过由于它生态比较丰富,使用起来比较方便,所以大家都默认了它…

MPLAB X IDE编译attiny1616工程报错却无报错信息

MPLAB X IDE(XC-8编译器)编译报错,无具体错误内容,仅显示需要xc-8 pro的警告。 内存占用率显示为81%,未超标。 原因:软件使用了microchip的bootloader功能。应用程序起始地址(也是bootloader结束地址)设置错…