From ecead1406dcb47f53b6f075c66d062eafd3c77f4 Mon Sep 17 00:00:00 2001 From: Laurent Perron Date: Sat, 27 Apr 2024 08:00:50 +0200 Subject: [PATCH] propagate hints when creating var value encoding --- ortools/sat/presolve_context.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ortools/sat/presolve_context.cc b/ortools/sat/presolve_context.cc index 7fe0c5a497..e30f159553 100644 --- a/ortools/sat/presolve_context.cc +++ b/ortools/sat/presolve_context.cc @@ -1492,6 +1492,18 @@ bool PresolveContext::InsertVarValueEncoding(int literal, int ref, } literal = GetLiteralRepresentative(literal); InsertVarValueEncodingInternal(literal, ref, value, /*add_constraints=*/true); + + if (hint_is_loaded_) { + const int bool_var = PositiveRef(literal); + const int int_var = PositiveRef(ref); + if (!hint_has_value_[bool_var] && hint_has_value_[int_var]) { + const int64_t int_value = RefIsPositive(ref) ? value : -value; + const int64_t hint_value = hint_[int_var] == int_value ? 1 : 0; + hint_has_value_[bool_var] = true; + hint_[bool_var] = RefIsPositive(literal) ? hint_value : 1 - hint_value; + } + } + return true; }