运筹系列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 基本样例
基础用法样例,需要输入:
- 距离矩阵
- 车辆清单
- 工作清单
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
需要定义
- resources (vehicles)
- single-location pickup and/or delivery tasks (jobs/shipments)
- 如果没有指定经纬度和地图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对应的字段含义为:
相关文章:

运筹系列92:vrp算法包VROOM
1. 介绍 VROOM is an open-source optimization engine written in C20 that aim at providing good solutions to various real-life vehicle routing problems (VRP) within a small computing time. 可以解决如下问题: TSP (travelling salesman problem) CVRP …...
【Spring Security注解详解】
Spring Security 是一个强大的、高度可定制的身份验证和访问控制框架,广泛用于Java应用程序中以确保安全。它提供了多种注解来简化安全控制的实现,特别是在方法级别的权限控制上。以下是几个核心的Spring Security注解及其用途的详细介绍: 1…...

C++学习笔记3
A. 求出那个数 题目描述 喵喵是一个爱睡懒觉的姑娘,所以每天早上喵喵的妈妈都花费很大的力气才能把喵喵叫起来去上学。 在放学的路上,喵喵看到有一家店在打折卖闹钟,她就准备买个闹钟回家叫自己早晨起床,以便不让妈妈这么的辛苦…...

基于SpringBoot的酒店(预约)客房管理系统的设计与实现+毕业论文
系统介绍 酒店客房管理系统为酒店管理者和用户、清洁人员提供一个在线管理酒店客房的系统。在网站的设计中,一共分为了两个模块设计,一个是前台模块,一个是后台模块,前台主要用于提供查看客房信息,酒店资讯࿰…...
Rust 中的声明可见性
Rust 中的声明可见性 在 Rust 编程语言中,声明可见性是一个核心概念,它决定了代码中的项(如函数、结构体、枚举等)在哪些范围内可以被访问。Rust 通过一套严谨的规则来控制这些可见性,以确保代码的安全性和封装性。下…...

让 计算机 将 数学 公式 表达式 的计算过程绘制出来 【mathematical-expression(MAE)】
目录 文章目录 目录介绍开始实战引入数学表达式计算库引入流程图代码生成库开始进行生成 介绍 大家好 今天我们来分享一个新知识,将数学表达式的整个计算过程,以及计算繁多结果在 Java 中绘制出来,计算机中的数学表达式计算的功能很常见了&a…...
Django——中间件
Django——中间件 中间件可以介入 Django 的请求和响应的处理过程,修改 Django 的响应数据。中间件的设计为程序开发者提供了一种无侵入式的开发方式,增强 Django 框架的健壮性。 中间件可以在 Django 处理视图的不同阶段的干预。 Django 框架中原先内…...

景联文科技:用高质量数据采集标注赋能无人机技术,引领无人机迈入新纪元!
随着无人机技术的不断发展与革新,它已成为现代社会中一个前景无限的科技领域。 无人机应用领域 边境巡逻与安防:边境管理部门利用无人机监控边境线,防止非法越境和其他安全威胁,同时也能监控地面安保人员的工作状态和行动路线。 …...
SpringBoot集成Redis,使用RedisTemple存储对象使用纯JSON格式
SpringBoot集成Redis,使用RedisTemple存储对象使用纯JSON格式 1、对象使用Json序列化 import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.parser.ParserConfig; import com.alibaba.fastjson.serializer.SerializerFeature; import org.springframework.data.r…...

[muduo网络库]——muduo库的Reactor模型(剖析muduo网络库核心部分、设计思想)
一、前言 在学习 C 服务端的过程中,必不可少的一项就是熟悉一个网络库,包括网络库的应用和其底层实现。我们熟知的网络库有 libevent、libev、muduo、Netty 等,其中 muduo 是由陈硕大佬个人开发的 TCP 网络库,最近跟着课程正在深…...
vue中怎样清除computed的缓存
vue中computed计算属性自带缓存,会提高程序的渲染性能,但根据业务需求以及相应的优化,可能要清除computed的缓存,具体方法和场景分为了vue2和vue3 vue2: this.$delete(this.someObject, cachedProperty); 使用 this…...

代码大师的工具箱:现代软件开发利器
✨✨ 欢迎大家来访Srlua的博文(づ ̄3 ̄)づ╭❤~✨✨ 🌟🌟 欢迎各位亲爱的读者,感谢你们抽出宝贵的时间来阅读我的文章。 我是Srlua小谢,在这里我会分享我的知识和经验。&am…...
整理好了!2024年最常见 100 道 Java基础面试题(四十三)
上一篇地址:整理好了!2024年最常见 100 道 Java基础面试题(四十二)-CSDN博客 八十五、Java 常用的元注解有哪些? 在Java中,元注解(Meta-Annotation)是指那些用于其他注解上的注解&…...
【TypeScript模块简介以及使用方法】
TypeScript模块简介 TypeScript中的模块(Modules)是代码的封装体,它们可以包含变量、函数、类和接口等。在TypeScript中,模块可以被其他模块引用和使用,从而实现代码的复用和模块化开发。 TypeScript支持两种模块系统…...

Offer必备算法38_贪心算法四_八道力扣题详解(由易到难)
目录 ①力扣56. 合并区间 解析代码 ②力扣435. 无重叠区间 解析代码 ③力扣452. 用最少数量的箭引爆气球 解析代码 ④力扣397. 整数替换 解析代码1_递归改记忆化搜索 解析代码2_贪心策略 ⑤力扣354. 俄罗斯套娃信封问题 解析代码1_动态规划(超时…...
java8 转对象,Java8转Map,Java8转Llist
1.准备数据 public static List<Persion> getData(){List<Persion> arrayList new ArrayList<>();arrayList.add(new Persion("李四","20","男"));arrayList.add(new Persion("王麻子","30","男&q…...
【Pytest官方文档翻译及学习】2.1 如何调用pytest
目录 2.1 如何调用pytest 2.1.1 指定要运行的测试 2.1.2 获取有关版本、选项名称、环境变量的帮助 2.1.3 分析测试执行时间 2.1.4 管理加载插件 2.1.5 调用pytest的其他方式 2.1 如何调用pytest 2.1.1 指定要运行的测试 Pytest支持几种从命令行运行和选择测试的方法。、…...

RabbitMQ的用途
RabbitMQ主要有四个用途,分别是应用解耦、异步提速、削峰填谷、消息分发。详情讲解如下: RabbitMQ介绍、解耦、提速、削峰、分发 详解、RabbitMQ安装 可视化界面讲解 1.应用解耦:提高系统容错性和可维护性 2.异步提速:提升用户体验…...

R语言软件安装及配置
1、下载 网址:www.r-project.org 1.1 下载R 选择download R 选择清华源进行下载 根据自己系统情况下载,我选择windows系统。 先选择base。 选择最新的版本下载。 1.2 下载RTools 下载好后,返回,选择RTools进入后,选…...

网络配置的加密存储
随着数据泄露事件的增加,扰乱了公司的正常工作周期,企业遭受了损失。事实上,数据泄露可以通过存储加密来控制,存储加密是防止黑客对网络数据库造成严重破坏的最有效方法之一。在网络配置管理器中,存储加密可用于存储设…...

C++实现分布式网络通信框架RPC(3)--rpc调用端
目录 一、前言 二、UserServiceRpc_Stub 三、 CallMethod方法的重写 头文件 实现 四、rpc调用端的调用 实现 五、 google::protobuf::RpcController *controller 头文件 实现 六、总结 一、前言 在前边的文章中,我们已经大致实现了rpc服务端的各项功能代…...

理解 MCP 工作流:使用 Ollama 和 LangChain 构建本地 MCP 客户端
🌟 什么是 MCP? 模型控制协议 (MCP) 是一种创新的协议,旨在无缝连接 AI 模型与应用程序。 MCP 是一个开源协议,它标准化了我们的 LLM 应用程序连接所需工具和数据源并与之协作的方式。 可以把它想象成你的 AI 模型 和想要使用它…...

对WWDC 2025 Keynote 内容的预测
借助我们以往对苹果公司发展路径的深入研究经验,以及大语言模型的分析能力,我们系统梳理了多年来苹果 WWDC 主题演讲的规律。在 WWDC 2025 即将揭幕之际,我们让 ChatGPT 对今年的 Keynote 内容进行了一个初步预测,聊作存档。等到明…...

React19源码系列之 事件插件系统
事件类别 事件类型 定义 文档 Event Event 接口表示在 EventTarget 上出现的事件。 Event - Web API | MDN UIEvent UIEvent 接口表示简单的用户界面事件。 UIEvent - Web API | MDN KeyboardEvent KeyboardEvent 对象描述了用户与键盘的交互。 KeyboardEvent - Web…...
Java入门学习详细版(一)
大家好,Java 学习是一个系统学习的过程,核心原则就是“理论 实践 坚持”,并且需循序渐进,不可过于着急,本篇文章推出的这份详细入门学习资料将带大家从零基础开始,逐步掌握 Java 的核心概念和编程技能。 …...
css3笔记 (1) 自用
outline: none 用于移除元素获得焦点时默认的轮廓线 broder:0 用于移除边框 font-size:0 用于设置字体不显示 list-style: none 消除<li> 标签默认样式 margin: xx auto 版心居中 width:100% 通栏 vertical-align 作用于行内元素 / 表格单元格ÿ…...
Java线上CPU飙高问题排查全指南
一、引言 在Java应用的线上运行环境中,CPU飙高是一个常见且棘手的性能问题。当系统出现CPU飙高时,通常会导致应用响应缓慢,甚至服务不可用,严重影响用户体验和业务运行。因此,掌握一套科学有效的CPU飙高问题排查方法&…...

html css js网页制作成品——HTML+CSS榴莲商城网页设计(4页)附源码
目录 一、👨🎓网站题目 二、✍️网站描述 三、📚网站介绍 四、🌐网站效果 五、🪓 代码实现 🧱HTML 六、🥇 如何让学习不再盲目 七、🎁更多干货 一、👨…...

宇树科技,改名了!
提到国内具身智能和机器人领域的代表企业,那宇树科技(Unitree)必须名列其榜。 最近,宇树科技的一项新变动消息在业界引发了不少关注和讨论,即: 宇树向其合作伙伴发布了一封公司名称变更函称,因…...
jmeter聚合报告中参数详解
sample、average、min、max、90%line、95%line,99%line、Error错误率、吞吐量Thoughput、KB/sec每秒传输的数据量 sample(样本数) 表示测试中发送的请求数量,即测试执行了多少次请求。 单位,以个或者次数表示。 示例:…...