多个时间窗口vrp [或工具]

时间:2020-04-27 10:35:35

标签: or-tools vehicle-routing

我有一个实施方式,应该为货件设置多个时间窗口:

    def _set_allowed_time_window(time_dimension, index, time_windows: list):
        """ Sets the appropriate time windows for a node. """
        # ortools lacks a function to set a list of time windows
        # workaround is to set the min and max of a list of sorted time windows as the allowed range
        # and then to restrict the times in between the allowed time windows
        # see https://github.com/google/or-tools/issues/456 and
        # https://groups.google.com/forum/#!topic/or-tools-discuss/MBq1TcqSQTI
        earliest_start = int(time_windows[0][0])
        latest_end = int(time_windows[len(time_windows)-1][1])
        time_dimension.CumulVar(index).SetRange(earliest_start, latest_end)

        for tw_index, time_window in enumerate(time_windows):
            if tw_index == len(time_windows)-1:
                break
            time_window_end = int(time_window[1])
            next_time_window_start = int(time_windows[tw_index+1][0])

            time_dimension.CumulVar(index).RemoveInterval(time_window_end, next_time_window_start)

逻辑上似乎没有什么错,但是除非我删除行time_dimension.CumulVar(index).RemoveInterval(time_window_end, next_time_window_start),否则or-tools无法返回解决方案。有什么想法我在这里做错了吗?

这里time_windows是一个lis,例如:[[100,200],[300,400]],而index是从NodeToIndex检索的索引。

1 个答案:

答案 0 :(得分:2)

问题似乎确实存在于注释中提到的F​​irstSolutionStrategy中。当一切都出现时,未分配的or-tools根本无法构建第一个解决方案。不幸的是,从日志中并不清楚。我在FirstSolutionStrategy的{​​{1}}和ALL_UNEPRFORMED上取得了成功。

不幸的是,在我的情况下,PATH_MOST_CONSTRAINED_ARC无法解决琐碎的案件,但是ALL_UNPERFORMED运作良好。我只希望算法有更深入的描述,以便更轻松地选择合适的算法。