У меня есть реализация, которая должна установить несколько раз windows для отгрузки:
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
- это список, например: [[100, 200], [300, 400]] и index
- индекс, полученный из NodeToIndex
,