当前位置: 首页 > news >正文

运筹系列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对应的字段含义为:
在这里插入图片描述

相关文章:

运筹系列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的酒店(预约)客房管理系统的设计与实现+毕业论文

系统介绍 酒店客房管理系统为酒店管理者和用户、清洁人员提供一个在线管理酒店客房的系统。在网站的设计中,一共分为了两个模块设计,一个是前台模块,一个是后台模块,前台主要用于提供查看客房信息,酒店资讯&#xff0…...

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_动态规划(超时&#xf…...

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主要有四个用途&#xff0c;分别是应用解耦、异步提速、削峰填谷、消息分发。详情讲解如下&#xff1a; RabbitMQ介绍、解耦、提速、削峰、分发 详解、RabbitMQ安装 可视化界面讲解 1.应用解耦&#xff1a;提高系统容错性和可维护性 2.异步提速&#xff1a;提升用户体验…...

R语言软件安装及配置

1、下载 网址&#xff1a;www.r-project.org 1.1 下载R 选择download R 选择清华源进行下载 根据自己系统情况下载&#xff0c;我选择windows系统。 先选择base。 选择最新的版本下载。 1.2 下载RTools 下载好后&#xff0c;返回&#xff0c;选择RTools进入后&#xff0c;选…...

网络配置的加密存储

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

基于FPGA的PID算法学习———实现PID比例控制算法

基于FPGA的PID算法学习 前言一、PID算法分析二、PID仿真分析1. PID代码2.PI代码3.P代码4.顶层5.测试文件6.仿真波形 总结 前言 学习内容&#xff1a;参考网站&#xff1a; PID算法控制 PID即&#xff1a;Proportional&#xff08;比例&#xff09;、Integral&#xff08;积分&…...

MySQL 隔离级别:脏读、幻读及不可重复读的原理与示例

一、MySQL 隔离级别 MySQL 提供了四种隔离级别,用于控制事务之间的并发访问以及数据的可见性,不同隔离级别对脏读、幻读、不可重复读这几种并发数据问题有着不同的处理方式,具体如下: 隔离级别脏读不可重复读幻读性能特点及锁机制读未提交(READ UNCOMMITTED)允许出现允许…...

条件运算符

C中的三目运算符&#xff08;也称条件运算符&#xff0c;英文&#xff1a;ternary operator&#xff09;是一种简洁的条件选择语句&#xff0c;语法如下&#xff1a; 条件表达式 ? 表达式1 : 表达式2• 如果“条件表达式”为true&#xff0c;则整个表达式的结果为“表达式1”…...

跨链模式:多链互操作架构与性能扩展方案

跨链模式&#xff1a;多链互操作架构与性能扩展方案 ——构建下一代区块链互联网的技术基石 一、跨链架构的核心范式演进 1. 分层协议栈&#xff1a;模块化解耦设计 现代跨链系统采用分层协议栈实现灵活扩展&#xff08;H2Cross架构&#xff09;&#xff1a; 适配层&#xf…...

【C语言练习】080. 使用C语言实现简单的数据库操作

080. 使用C语言实现简单的数据库操作 080. 使用C语言实现简单的数据库操作使用原生APIODBC接口第三方库ORM框架文件模拟1. 安装SQLite2. 示例代码:使用SQLite创建数据库、表和插入数据3. 编译和运行4. 示例运行输出:5. 注意事项6. 总结080. 使用C语言实现简单的数据库操作 在…...

汇编常见指令

汇编常见指令 一、数据传送指令 指令功能示例说明MOV数据传送MOV EAX, 10将立即数 10 送入 EAXMOV [EBX], EAX将 EAX 值存入 EBX 指向的内存LEA加载有效地址LEA EAX, [EBX4]将 EBX4 的地址存入 EAX&#xff08;不访问内存&#xff09;XCHG交换数据XCHG EAX, EBX交换 EAX 和 EB…...

Redis数据倾斜问题解决

Redis 数据倾斜问题解析与解决方案 什么是 Redis 数据倾斜 Redis 数据倾斜指的是在 Redis 集群中&#xff0c;部分节点存储的数据量或访问量远高于其他节点&#xff0c;导致这些节点负载过高&#xff0c;影响整体性能。 数据倾斜的主要表现 部分节点内存使用率远高于其他节…...

技术栈RabbitMq的介绍和使用

目录 1. 什么是消息队列&#xff1f;2. 消息队列的优点3. RabbitMQ 消息队列概述4. RabbitMQ 安装5. Exchange 四种类型5.1 direct 精准匹配5.2 fanout 广播5.3 topic 正则匹配 6. RabbitMQ 队列模式6.1 简单队列模式6.2 工作队列模式6.3 发布/订阅模式6.4 路由模式6.5 主题模式…...

通过 Ansible 在 Windows 2022 上安装 IIS Web 服务器

拓扑结构 这是一个用于通过 Ansible 部署 IIS Web 服务器的实验室拓扑。 前提条件&#xff1a; 在被管理的节点上安装WinRm 准备一张自签名的证书 开放防火墙入站tcp 5985 5986端口 准备自签名证书 PS C:\Users\azureuser> $cert New-SelfSignedCertificate -DnsName &…...

DeepSeek源码深度解析 × 华为仓颉语言编程精粹——从MoE架构到全场景开发生态

前言 在人工智能技术飞速发展的今天&#xff0c;深度学习与大模型技术已成为推动行业变革的核心驱动力&#xff0c;而高效、灵活的开发工具与编程语言则为技术创新提供了重要支撑。本书以两大前沿技术领域为核心&#xff0c;系统性地呈现了两部深度技术著作的精华&#xff1a;…...