1

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

4

2 回答 2

1

最简单的方法是调整距离矩阵,使“第一次”的唯一传入弧来自仓库,而从最后一个传出的弧只有到仓库。

于 2020-02-27T07:40:50.833 回答
1

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

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

爪哇:

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);
}

。网

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节点基本相同。

爪哇:

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);
}

。网

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)
于 2020-02-27T07:44:35.793 回答