【问题标题】:How are min and max of cumulative variables assigned?如何分配累积变量的最小值和最大值?
【发布时间】:2018-07-17 00:01:47
【问题描述】:

我创建了一个路由问题并为其添加了一些维度。找到了解决方案分配,我想知道每个索引处的累积值。我注意到赋值的CumulVar 不仅有Value 方法,还有MinMax 方法。显然,累积变量是以它们可以表示间隔的方式实现的。我可以看看如何设置

  • slack_max>0
  • fix_start_cumul_to_zero=False

为累积变量引入了歧义,因为它们是如何开始以及在每次停止时添加多少松弛的选择。但是

问题:如何计算每个索引处的MinMax

【问题讨论】:

  • 为什么会被标记为 Python?
  • or-tools 可用于 C++、Java、C# 和 Python 并且存在差异,但我同意对于这个问题它不相关。将其删除。

标签: or-tools


【解决方案1】:

您可以从solution.Min(dimension.Cumulvar(index))获取给定节点索引的Min和Max范围

请注意,当您使用 slack_max=0 时,您会得到完全相同的 Min 和 Max,除非您知道我不知道的事情;) 假设您使用的是输出解决方案对象 solution 和时间维度 time_dimension,这会将 em 存储为具有 min-max 元组的 dict,您可能希望根据需要调整输出格式:

time_dict = {}
for vehicle_id in range(num_vehicles):
  vehicle_time_dict={}
  index = routing.Start(vehicle_id)
  start_time = solution.Min(time_dimension.CumulVar(index))
  vehicle_time_dict[index]=(index_min,index_max)
  while not routing.isEnd(index):
    previous_index = index
    index = solution.Value(routing.NextVar(index))
    index_min = solution.Min(time_dimension.CumulVar(index))
    index_max = solution.Max(time_dimension.CumulVar(index))
    vehicle_time_dict[index]=(index_min,index_max)
  time_dict[vehicle_id]=vehicle_time_dict

routing.IsEnd(index) 返回 True 如果它是该车辆路线的最后一个索引(或最后一个索引之后的任何位置,所以如果它有 10 个节点长:

  • routing.IsEnd(8) 将返回 False
  • routing.IsEnd(9) 将返回 True
  • routing.IsEnd(10) 也会返回 True 等)

【讨论】:

  • “计算”是指 or-tools 如何计算它们。
猜你喜欢
  • 2022-12-31
  • 1970-01-01
  • 2016-04-04
  • 2012-08-09
  • 1970-01-01
  • 1970-01-01
  • 2013-01-22
  • 1970-01-01
  • 2020-12-19
相关资源
最近更新 更多