运筹系列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进入后,选…...

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

你写代码,会关注时间复杂度吗?
虽然面试的时候总是被问到这个问题,但你写代码的时候,真的会想到这个问题吗?时间复杂度,说的当然不是你写的代码执行用了多长时间,而是代码执行语句的次数。 目录 每行代码都需要注意 计算方法 1 例如常量增长 2 …...

【连连国际注册/登录安全分析报告】
连连国际注册/登录安全分析报告 前言 由于网站注册入口容易被黑客攻击,存在如下安全问题: 暴力破解密码,造成用户信息泄露短信盗刷的安全问题,影响业务及导致用户投诉带来经济损失,尤其是后付费客户,风险巨…...

linux进阶高级配置,你需要知道的有哪些(10)-远程访问
1、ssh协议的功能 为客户机提供安全的shell环境(字符界面),用于远程管理 2、openssh的服务说明 服务名:sshd 重启服务:systemctl restart sshd 主配置文件:/etc/ssh/sshd/_config 端口号:tcp 2…...

不显示 表格 style=“display: none;“ 这个默认是不显示的
不显示 表格 style“display: none;” 这个默认是不显示的 取消就可以或者 $(‘#modifyStatusBtn’).show(); <div id"userInfoContainer" style"display: none;"></div>...

Bittensor怎么挖?手把手教你,使用bitget钱包
4月 Binance 上新 TheBittensorHub (TAO), 这个项目究竟做了什么可以令其在上大舞台前就已经在所有通证中排名前 30? 本文将深度解析。 该项目既不直接贡献数据,也不直接贡献算力。 而是通过区块链网络和激励机制,来对不同的算法进行调度和…...

领略Java内部类的“内部”
内部类有两种情况: (1) 在类中定义一个类(私有内部类,静态内部类) (2) 在方法中定义一个类(局部内部类,匿名内部类) 1、私有内部类 —— 在方法之间定义的内部类,非静态 我们首先看看类中内部类的两个特点: (1) 在外部…...

PHP 提取数组中的特定的值
需求: 前端展示: (1)之前的页面: (2)修改后的页面: 之前接口返回的数据 : 解决办法:提取tags 中的 ’约 的数组 添加到一个新的数组中去 1:一开…...

SpringBoot、JAVA中excel、rtf、doc转PDF
话不多说,直接上干货 // 官方文档的要求 无需理会public static boolean getLicense() {boolean result false;try {String s "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Wo…...

生信技能45 - 基于docker容器运行生信软件
1. 获取docker镜像 以运行xhmm CNV分析软件为例。 # 搜索仓库镜像 sudo docker search xhmm# 拉取镜像 sudo docker pull ksarathbabu/xhmm_v1.0# 启动镜像,非后台 sudo docker run -it ksarathbabu/xhmm_v1.0 /bin/bash # -i: 交互式操作。 # -t: 终端。 # ksarathbabu/xhmm…...

算法训练营第63天|LeetCode 84.柱状图中最大的矩形
完结!撒花! LeetCode 84.柱状图中最大的矩形 题目链接: LeetCode 84.柱状图中最大的矩形 代码: class Solution { public:int largestRectangleArea(vector<int>& heights) {heights.insert(heights.begin(),0);he…...