gpt4 book ai didi

java - 如何在 Google OR 工具的 VRP 中强制执行硬约束,某些节点不应首先和最后访问

转载 作者:行者123 更新时间:2023-12-02 01:02:53 26 4
gpt4 key购买 nike

我试图强制执行一个约束,即在行程开始时或行程因 VRP 问题结束时不应访问某些节点。有没有办法在 Google OR 工具中强制执行此类约束?仅供引用,我使用的语言是java。

最佳答案

您可以尝试修改nextVar变量的范围。

例如禁止每辆车的弧 start -> index

Java:

long toIndex = manager.nodeToIndex(index); 
for(int i = 0; i < vehicleNumber; ++i) {
long fromIndex = routing.start(i);
logger.info("Forbidding connection " + fromIndex + " -> " + toIndex);
routing.nextVar(fromIndex).removeValue(toIndex);
}

.Net

long toIndex = manager.NodeToIndex(index); 
for (int i = 0; i < vehicleNumber; ++i) {
long fromIndex = routing.Start(i);
Console.WriteLine($"Forbidding connection {fromIndex} -> {toIndex}");
routing.NextVar(fromIndex).RemoveValue(toIndex);
}

Python

to_index = manager.NodeToIndex(index);
for i in range(vehicle_number):
from_index = routing.Start(i)
print(f"Forbidding connection {from_index} -> {to_index}")
routing.NextVar(from_index).RemoveValue(to_index)

index -> end 节点基本相同。

Java:

long fromIndex = manager.nodeToIndex(index); 
for(int i = 0; i < vehicleNumber; ++i) {
long toIndex = routing.end(i);
logger.info("Forbidding connection " + fromIndex + " -> " + toIndex);
routing.nextVar(fromIndex).removeValue(toIndex);
}

.Net

long fromIndex = manager.NodeToIndex(index); 
for (int i = 0; i < vehicleNumber; ++i) {
long toIndex = routing.End(i);
Console.WriteLine($"Forbidding connection {fromIndex} -> {toIndex}");
routing.NextVar(fromIndex).RemoveValue(toIndex);
}

Python

from_index = manager.NodeToIndex(index);
for i in range(vehicle_number):
to_index = routing.End(i)
print(f"Forbidding connection {from_index} -> {to_index}")
routing.NextVar(from_index).RemoveValue(to_index)

关于java - 如何在 Google OR 工具的 VRP 中强制执行硬约束,某些节点不应首先和最后访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60427019/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com