20 #include "absl/synchronization/mutex.h"
26 using ::operations_research::sat::LinearBooleanProblem;
27 using ::operations_research::sat::LinearObjective;
41 return "OPTIMAL_SOLUTION_FOUND";
43 return "SOLUTION_FOUND";
47 return "LIMIT_REACHED";
49 return "INFORMATION_FOUND";
57 LOG(DFATAL) <<
"Invalid Status " <<
static_cast<int>(status);
58 return "UNKNOWN Status";
67 : original_problem_(problem),
69 update_stamp_(kInitialStampValue + 1),
70 is_fixed_(problem.num_variables(), false),
71 fixed_values_(problem.num_variables(), false),
73 solution_(problem,
"AllZero"),
74 assignment_preference_(),
79 const LinearObjective& objective = problem.objective();
81 for (
int i = 0; i < objective.coefficients_size(); ++i) {
83 lower_bound_ += std::min<int64>(
int64{0}, objective.coefficients(i));
93 const std::string kIndent(25,
' ');
95 bool new_lp_values =
false;
97 if (lp_values_ != learned_info.
lp_values) {
100 VLOG(1) << kIndent +
"New LP values.";
104 bool new_binary_clauses =
false;
106 const int old_num = binary_clause_manager_.
NumClauses();
108 const int num_vars = original_problem_.num_variables();
110 binary_clause_manager_.
Add(c);
113 if (binary_clause_manager_.
NumClauses() > old_num) {
114 new_binary_clauses =
true;
115 VLOG(1) << kIndent +
"Num binary clauses: "
120 bool new_solution =
false;
126 VLOG(1) << kIndent +
"New solution.";
129 bool new_lower_bound =
false;
132 new_lower_bound =
true;
133 VLOG(1) << kIndent +
"New lower bound.";
140 parameters_.relative_gap_limit() *
151 int num_newly_fixed_variables = 0;
153 const VariableIndex
var(
literal.Variable().value());
154 if (
var >= original_problem_.num_variables()) {
158 if (is_fixed_[
var]) {
164 is_fixed_[
var] =
true;
166 ++num_newly_fixed_variables;
169 if (num_newly_fixed_variables > 0) {
170 int num_fixed_variables = 0;
171 for (
const bool is_fixed : is_fixed_) {
173 ++num_fixed_variables;
176 VLOG(1) << kIndent << num_newly_fixed_variables
177 <<
" newly fixed variables (" << num_fixed_variables <<
" / "
178 << is_fixed_.size() <<
").";
179 if (num_fixed_variables == is_fixed_.size()) {
182 for (VariableIndex
var(0);
var < is_fixed_.size(); ++
var) {
186 solution_ = fixed_solution;
190 VLOG(1) << kIndent <<
"Optimal";
197 bool known_status =
false;
206 const bool updated = new_lp_values || new_binary_clauses || new_solution ||
207 new_lower_bound || num_newly_fixed_variables > 0 ||
209 if (updated) ++update_stamp_;
216 if (is_fixed_[
var]) {
242 lower_bound_ = upper_bound_ - 1;