diff --git a/ortools/sat/cumulative.cc b/ortools/sat/cumulative.cc index 4326c2919b..b3ce923da0 100644 --- a/ortools/sat/cumulative.cc +++ b/ortools/sat/cumulative.cc @@ -168,6 +168,15 @@ std::function Cumulative( // precedence graph, not just task in direct precedence. Make sure not to // create to many such constraints though. if (parameters.use_hard_precedences_in_cumulative_constraint()) { + // The CumulativeIsAfterSubsetConstraint() always reset the helper to the + // forward time direction, so it is important to also precompute the + // precedence relation using the same direction! This is needed in case + // the helper has already been used and set in the other direction. + if (!helper->SynchronizeAndSetTimeDirection(true)) { + model->GetOrCreate()->NotifyThatModelIsUnsat(); + return; + } + std::vector index_to_end_vars; std::vector index_to_task; std::vector before;