運籌系列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.pswp.cn/web/11299.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/11299.shtml
英文地址,請注明出處:http://en.pswp.cn/web/11299.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

九、 個人信息出境標準合同的簽署及備案流程是怎樣的?

為指導和幫助個人信息處理者規范有序備案個人信息出境標準合同,國家網信辦結合此前備案實踐經驗發布了《標準合同備案指南(第二版)》,并就個人信息出境標準合同備案的適用范圍、備案方式、備案流程和材料以及咨詢、舉報聯系方式等…

F5 BIG-IP Next Central Manager SQL注入漏洞(CVE-2024-26026、CVE-2024-21793)

0x01 產品簡介 BIG-IP Next Central Manager是BIG-IP Next的原生默認用戶界面,它可跨平臺管理BIG-IP Next實例。BIG-IP Next是F5 Networks公司推出的一款下一代BIG-IP軟件,提供了多云應用安全和應用交付服務。 0x02 漏洞概述 CVE-2024-26026:BIG-IP Next Central Manager…

產品推薦 | 基于AMD Virtex 7 FPGA VC709 的高速連接功能開發板

01 產品概述 Virtex? 7 FPGA VC709 連接功能套件是一款速率為 40Gb/s 的高速平臺,您可以通過評估和開發連接功能,迅速為包含所有必要軟硬件和 IP 核的高帶寬和高性能應用提供強大的支持。它包括一個含有 PCI Express Gen 3、Northwest Logic 公司推出的…

4.1 文本相似度(二)

目錄 1 文本相似度評估 2 代碼 2.1 load_dataset 方法 2.2 AutoTokenizer、AutoModelForSequenceClassification 1 文本相似度評估 對兩個文本拼接起來,然后作為一個樣本喂給模型,作為一個二分類的任務; 數據處理的方式以及訓練的基本流程…

c 指針基礎

/* 指針練習*/ #include <stdio.h> #include <stdlib.h> void printAll(int n1, int n2, int *p1, int *p2); int main(){ //賦值操作語法演示 int num1 1111; int num2 2222; int *prt1 &num1; int *prt2 &num2; printAll(num1, num2, prt1…

maven .lastUpdated文件作用

現象 有時候我在用maven管理項目時會發現有些依賴報錯&#xff0c;這時你可以看一下本地倉庫中是否有.lastUpdated文件&#xff0c;也許與它有關。 原因 有這個文件就表示依賴下載過程中發生了錯誤導致依賴沒成功下載&#xff0c;可能是網絡原因&#xff0c;也有可能是遠程…

平面設計基礎指南:從零開始的學習之旅!

平面設計師主要做什么&#xff1f; 平面設計師通過創建視覺概念來傳達信息。他們創造了從海報和廣告牌到包裝、標志和營銷材料的所有內容&#xff0c;并通過使用形狀、顏色、排版、圖像和其他元素向觀眾傳達了他們的想法。平面設計師可以在內部工作&#xff0c;專門為品牌創建…

Mac安裝jadx

1、使用命令brew安裝 : brew install jadx 輸入完命令,等待安裝完畢 備注&#xff08;關于Homebrew &#xff09;&#xff1a; Homebrew 是 MacOS 下的包管理工具&#xff0c;類似 apt-get/apt 之于 Linux&#xff0c;yum 之于 CentOS。如果一款軟件發布時支持了 homebrew 安…

mac定時任務、自啟動任務

https://quail.ink/mynotes/p/mac-startup-configuration-detailed-explanation <?xml version"1.0" encoding"UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.d…

【2024年5月備考新增】】 考前篇(2)《官方平臺 - 考生模擬練習平臺常用操作(一)》

軟考考生常用操作說明 說明:模擬作答系統是旨在讓考生熟悉計算機化考試環境和作答方式,模擬作答不保存考生作答 歷史記錄。考試題型、題量、分值、界面及文字內容以正式考試答題系統為準。 1 如何標記試題、切換試題 2 簡答題如何查看歷史記錄、切換輸入法 3 選做題,已作答…

游戲找不到steam_api64.dll如何解決,介紹5種簡單有效的方法

面對“找不到steam_api64.dll&#xff0c;無法繼續執行代碼”的問題&#xff0c;許多游戲玩家或軟件使用者可能會感到手足無措。這個錯誤提示意味著你的計算機系統在嘗試運行某個游戲或應用程序時&#xff0c;無法定位到一個至關重要的動態鏈接庫文件——steam_api64.dll&#…

《深入Linux內核架構》第3章 內存管理(6)

目錄 3.5.7 內核中不連續頁的分配 3.5.8 內核映射 本專欄文章將有70篇左右&#xff0c;歡迎關注&#xff0c;訂閱后續文章。 本節講解vmalloc, vmap&#xff0c;kmap原理。 3.5.7 內核中不連續頁的分配 kmalloc函數&#xff1a;分配物理地址和虛擬地址都連續的內存。 kmall…

MongoDB聚合運算符:$type

MongoDB聚合運算符&#xff1a;$type 文章目錄 MongoDB聚合運算符&#xff1a;$type語法使用可用的類型 舉例 $type聚合運算符用來返回指定參數的BSON類型的字符串。。 語法 { $type: <expression> }<expression>可以是任何合法的表達式。 使用 不像查詢操作符$…

Selenium + Pytest自動化測試框架實戰(上)

前言 今天呢筆者想和大家來聊聊selenium自動化 pytest測試框架&#xff0c;在這篇文章里你需要知道一定的python基礎——至少明白類與對象&#xff0c;封裝繼承&#xff1b;一定的selenium基礎。這篇文章不會selenium&#xff0c;不會的可以自己去看selenium中文翻譯網喲。 一…

六西格瑪管理培訓公司:事業進階的充電站,助你沖破職場天花板!

六西格瑪&#xff0c;源于制造業&#xff0c;卻不僅僅局限于制造業。它是一種以數據為基礎、以顧客為中心、以流程優化為手段的全面質量管理方法。通過六西格瑪管理&#xff0c;企業可以系統性地識別并解決運營過程中的問題&#xff0c;提高產品和服務的質量&#xff0c;降低成…

導航app為什么知道還有幾秒變綠燈?

在使用地圖導航app行駛至信號燈的交叉路口時&#xff0c;這些應用程序會貼心地告知用戶距信號燈變化還有多少秒&#xff0c;無論是即將轉為綠燈還是紅燈。這一智能化提示不僅使得駕駛員能適時做好起步或剎車的準備&#xff0c;有效緩解了因等待時間不確定而產生的焦慮情緒&…

GBPC2510-ASEMI工業電源專用GBPC2510

編輯&#xff1a;ll GBPC2510-ASEMI工業電源專用GBPC2510 型號&#xff1a;GBPC2510 品牌&#xff1a;ASEMI 封裝&#xff1a;GBPC-4 最大重復峰值反向電壓&#xff1a;1000V 最大正向平均整流電流(Vdss)&#xff1a;25A 功率(Pd)&#xff1a;中小功率 芯片個數&#x…

分布式鎖之RedissonLock

什么是Redisson&#xff1f; 俗話說他就是看門狗&#xff0c;看門狗機制是一種用于保持Redis連接活躍性的方法&#xff0c;通常用于分布式鎖的場景。看門狗的工作原理是&#xff1a;當客戶端獲取到鎖之后&#xff0c;會對Redis中的一個特定的鍵設置一個有限的過期時間&#xff…

[附源碼]傳世手游_玲瓏傳世_GM_安卓搭建教程

本教程僅限學習使用&#xff0c;禁止商用&#xff0c;一切后果與本人無關&#xff0c;此聲明具有法律效應&#xff01;&#xff01;&#xff01;&#xff01; 教程是本人親自搭建成功的&#xff0c;絕對是完整可運行的&#xff0c;踩過的坑都給你們填上了。 如果你是小白也沒…

C++ 509. 斐波那契數

文章目錄 一、題目描述二、參考代碼 一、題目描述 示例 1&#xff1a; 輸入&#xff1a;n 2 輸出&#xff1a;1 解釋&#xff1a;F(2) F(1) F(0) 1 0 1 示例 2&#xff1a; 輸入&#xff1a;n 3 輸出&#xff1a;2 解釋&#xff1a;F(3) F(2) F(1) 1 1 2 示例 3…