1

我有一个应该为装运设置多个时间窗口的实现:

    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)

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

time_windows是一个 lis,例如: [[100, 200], [300, 400]] 并且index是从 检索到的索引NodeToIndex

4

1 回答 1

2

正如评论中提到的,问题似乎确实出在 FirstSolutionStrategy 中。当一切都出现未分配或工具时,根本无法构建第一个解决方案。不幸的是,这从日志中不是很清楚。我在FirstSolutionStrategysALL_UNEPRFORMEDPATH_MOST_CONSTRAINED_ARC.

不幸的是,在我的案例ALL_UNPERFORMED中无法解决琐碎的案例,但PATH_MOST_COSNTRAINED_ARC效果很好。我只是希望算法有更深入的描述,以便更容易选择合适的算法。

于 2020-05-15T06:19:47.860 回答