代码之家  ›  专栏  ›  技术社区  ›  k88

多时间窗口vrp[或工具]

  •  0
  • k88  · 技术社区  · 6 年前

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

        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) . 你知道我做错什么了吗?

    在这里 time_windows 是lis,例如:[[100,200],[300,400]]和 index 从中检索索引 NodeToIndex .

    0 回复  |  直到 6 年前
        1
  •  2
  •   k88    6 年前

    正如评论中提到的,问题似乎确实在第一个解决策略中。当所有东西都未分配或工具根本无法构建第一个解决方案时。不幸的是,这不是很清楚从日志。我在这方面取得了成功 FirstSolutionStrategy s ALL_UNEPRFORMED PATH_MOST_CONSTRAINED_ARC .

    ALL_UNPERFORMED 无法解决琐碎的案件,但是 PATH_MOST_COSNTRAINED_ARC

    推荐文章