Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
bop_lns.cc
Go to the documentation of this file.
1// Copyright 2010-2025 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#include "ortools/bop/bop_lns.h"
15
16#include <algorithm>
17#include <cmath>
18#include <deque>
19#include <memory>
20#include <vector>
21
22#include "absl/cleanup/cleanup.h"
23#include "absl/log/check.h"
24#include "absl/log/log.h"
25#include "absl/random/bit_gen_ref.h"
26#include "absl/random/distributions.h"
27#include "absl/strings/string_view.h"
44#include "ortools/util/stats.h"
47
48namespace operations_research {
49namespace bop {
50
51using ::operations_research::glop::ColIndex;
53using ::operations_research::sat::LinearBooleanConstraint;
54using ::operations_research::sat::LinearBooleanProblem;
55
56//------------------------------------------------------------------------------
57// BopCompleteLNSOptimizer
58//------------------------------------------------------------------------------
59
60namespace {
61void UseBopSolutionForSatAssignmentPreference(const BopSolution& solution,
62 sat::SatSolver* solver) {
63 for (int i = 0; i < solution.Size(); ++i) {
64 solver->SetAssignmentPreference(
65 sat::Literal(sat::BooleanVariable(i), solution.Value(VariableIndex(i))),
66 1.0);
67 }
68}
69} // namespace
70
72 absl::string_view name, const BopConstraintTerms& objective_terms)
74 state_update_stamp_(ProblemState::kInitialStampValue),
75 objective_terms_(objective_terms) {}
76
78
79BopOptimizerBase::Status BopCompleteLNSOptimizer::SynchronizeIfNeeded(
80 const ProblemState& problem_state, int num_relaxed_vars) {
81 if (state_update_stamp_ == problem_state.update_stamp()) {
83 }
84 state_update_stamp_ = problem_state.update_stamp();
85
86 // Load the current problem to the solver.
87 sat_solver_ = std::make_unique<sat::SatSolver>();
88 const BopOptimizerBase::Status status =
89 LoadStateProblemToSatSolver(problem_state, sat_solver_.get());
90 if (status != BopOptimizerBase::CONTINUE) return status;
91
92 // Add the constraint that forces the solver to look for a solution
93 // at a distance <= num_relaxed_vars from the current one. Note that not all
94 // the terms appear in this constraint.
95 //
96 // TODO(user): if the current solution didn't change, there is no need to
97 // re-run this optimizer if we already proved UNSAT.
98 std::vector<sat::LiteralWithCoeff> cst;
99 for (BopConstraintTerm term : objective_terms_) {
100 if (problem_state.solution().Value(term.var_id) && term.weight < 0) {
101 cst.push_back(sat::LiteralWithCoeff(
102 sat::Literal(sat::BooleanVariable(term.var_id.value()), false), 1.0));
103 } else if (!problem_state.solution().Value(term.var_id) &&
104 term.weight > 0) {
105 cst.push_back(sat::LiteralWithCoeff(
106 sat::Literal(sat::BooleanVariable(term.var_id.value()), true), 1.0));
107 }
108 }
109 sat_solver_->AddLinearConstraint(
110 /*use_lower_bound=*/false, sat::Coefficient(0),
111 /*use_upper_bound=*/true, sat::Coefficient(num_relaxed_vars), &cst);
112
113 if (sat_solver_->ModelIsUnsat()) return BopOptimizerBase::ABORT;
114
115 // It sounds like a good idea to force the solver to find a similar solution
116 // from the current one. On another side, this is already somewhat enforced by
117 // the constraint above, so it will need more investigation.
118 UseBopSolutionForSatAssignmentPreference(problem_state.solution(),
119 sat_solver_.get());
121}
122
123bool BopCompleteLNSOptimizer::ShouldBeRun(
124 const ProblemState& problem_state) const {
125 return problem_state.solution().IsFeasible();
126}
127
128BopOptimizerBase::Status BopCompleteLNSOptimizer::Optimize(
129 const BopParameters& parameters, const ProblemState& problem_state,
130 LearnedInfo* learned_info, TimeLimit* time_limit) {
132 CHECK(learned_info != nullptr);
133 CHECK(time_limit != nullptr);
134 learned_info->Clear();
135
136 const BopOptimizerBase::Status sync_status =
137 SynchronizeIfNeeded(problem_state, parameters.num_relaxed_vars());
138 if (sync_status != BopOptimizerBase::CONTINUE) {
139 return sync_status;
140 }
141
142 CHECK(sat_solver_ != nullptr);
143 const double initial_dt = sat_solver_->deterministic_time();
144 auto advance_dt = ::absl::MakeCleanup([initial_dt, this, &time_limit]() {
145 time_limit->AdvanceDeterministicTime(sat_solver_->deterministic_time() -
146 initial_dt);
147 });
148
149 // Set the parameters for this run.
150 // TODO(user): Because of this, we actually loose the perfect continuity
151 // between runs, and the restart policy is resetted... Fix this.
152 sat::SatParameters sat_params;
153 sat_params.set_max_number_of_conflicts(
154 parameters.max_number_of_conflicts_in_random_lns());
155 sat_params.set_max_time_in_seconds(time_limit->GetTimeLeft());
156 sat_params.set_max_deterministic_time(time_limit->GetDeterministicTimeLeft());
157 sat_params.set_random_seed(parameters.random_seed());
158
159 sat_solver_->SetParameters(sat_params);
160 const sat::SatSolver::Status sat_status = sat_solver_->Solve();
161 if (sat_status == sat::SatSolver::FEASIBLE) {
162 SatAssignmentToBopSolution(sat_solver_->Assignment(),
163 &learned_info->solution);
165 }
166 if (sat_status == sat::SatSolver::LIMIT_REACHED) {
168 }
169
170 // Because of the "LNS" constraint, we can't deduce anything about the problem
171 // in this case.
173}
174
175//------------------------------------------------------------------------------
176// BopAdaptiveLNSOptimizer
177//------------------------------------------------------------------------------
178
179namespace {
180// Returns false if the limit is reached while solving the LP.
181bool UseLinearRelaxationForSatAssignmentPreference(
182 const BopParameters& parameters, const LinearBooleanProblem& problem,
183 sat::SatSolver* sat_solver, TimeLimit* time_limit) {
184 // TODO(user): Re-use the lp_model and lp_solver or build a model with only
185 // needed constraints and variables.
186 glop::LinearProgram lp_model;
188
189 // Set bounds of variables fixed by the sat_solver.
190 const sat::Trail& propagation_trail = sat_solver->LiteralTrail();
191 for (int trail_index = 0; trail_index < propagation_trail.Index();
192 ++trail_index) {
193 const sat::Literal fixed_literal = propagation_trail[trail_index];
194 const glop::Fractional value = fixed_literal.IsPositive() ? 1.0 : 0.0;
195 lp_model.SetVariableBounds(ColIndex(fixed_literal.Variable().value()),
196 value, value);
197 }
198
199 glop::LPSolver lp_solver;
200 NestedTimeLimit nested_time_limit(time_limit, time_limit->GetTimeLeft(),
201 parameters.lp_max_deterministic_time());
202 const glop::ProblemStatus lp_status =
203 lp_solver.SolveWithTimeLimit(lp_model, nested_time_limit.GetTimeLimit());
204
205 if (lp_status != glop::ProblemStatus::OPTIMAL &&
207 lp_status != glop::ProblemStatus::IMPRECISE) {
208 // We have no useful information from the LP, we will abort this LNS.
209 return false;
210 }
211
212 // Set preferences based on the solution of the relaxation.
213 for (ColIndex col(0); col < lp_solver.variable_values().size(); ++col) {
214 const double value = lp_solver.variable_values()[col];
215 sat_solver->SetAssignmentPreference(
216 sat::Literal(sat::BooleanVariable(col.value()), round(value) == 1),
217 1 - fabs(value - round(value)));
218 }
219 return true;
220}
221} // namespace
222
223// Note(user): We prefer to start with a really low difficulty as this works
224// better for large problem, and for small ones, it will be really quickly
225// increased anyway. Maybe a better approach is to start by relaxing something
226// like 10 variables instead of having a fixed percentage.
228 absl::string_view name, bool use_lp_to_guide_sat,
229 NeighborhoodGenerator* neighborhood_generator,
230 sat::SatSolver* sat_propagator)
232 use_lp_to_guide_sat_(use_lp_to_guide_sat),
233 neighborhood_generator_(neighborhood_generator),
234 sat_propagator_(sat_propagator),
235 adaptive_difficulty_(0.001) {
236 CHECK(sat_propagator != nullptr);
237}
238
240
241bool BopAdaptiveLNSOptimizer::ShouldBeRun(
242 const ProblemState& problem_state) const {
243 return problem_state.solution().IsFeasible();
244}
245
246BopOptimizerBase::Status BopAdaptiveLNSOptimizer::Optimize(
247 const BopParameters& parameters, const ProblemState& problem_state,
248 LearnedInfo* learned_info, TimeLimit* time_limit) {
250 CHECK(learned_info != nullptr);
251 CHECK(time_limit != nullptr);
252 learned_info->Clear();
253
254 // Set-up a sat_propagator_ cleanup task to catch all the exit cases.
255 const double initial_dt = sat_propagator_->deterministic_time();
256 auto sat_propagator_cleanup =
257 ::absl::MakeCleanup([initial_dt, this, &learned_info, &time_limit]() {
258 if (!sat_propagator_->ModelIsUnsat()) {
259 (void)sat_propagator_->ResetToLevelZero();
260 ExtractLearnedInfoFromSatSolver(sat_propagator_, learned_info);
261 }
262 time_limit->AdvanceDeterministicTime(
263 sat_propagator_->deterministic_time() - initial_dt);
264 });
265
266 // For the SAT conflicts limit of each LNS, we follow a luby sequence times
267 // the base number of conflicts (num_conflicts_). Note that the numbers of the
268 // Luby sequence are always power of two.
269 //
270 // We dynamically change the size of the neighborhood depending on the
271 // difficulty of the problem. There is one "target" difficulty for each
272 // different numbers in the Luby sequence. Note that the initial value is
273 // reused from the last run.
274 const BopParameters& local_parameters = parameters;
275 int num_tries = 0; // TODO(user): remove? our limit is 1 by default.
276 while (!time_limit->LimitReached() &&
277 num_tries < local_parameters.num_random_lns_tries()) {
278 // Compute the target problem difficulty and generate the neighborhood.
279 adaptive_difficulty_.UpdateLuby();
280 const double difficulty = adaptive_difficulty_.GetParameterValue();
281 neighborhood_generator_->GenerateNeighborhood(problem_state, difficulty,
282 sat_propagator_);
283
284 ++num_tries;
285 VLOG(2) << num_tries << " difficulty:" << difficulty
286 << " luby:" << adaptive_difficulty_.luby_value()
287 << " fixed:" << sat_propagator_->LiteralTrail().Index() << "/"
288 << problem_state.original_problem().num_variables();
289
290 // Special case if the difficulty is too high.
291 if (!sat_propagator_->ModelIsUnsat()) {
292 if (sat_propagator_->CurrentDecisionLevel() == 0) {
293 VLOG(2) << "Nothing fixed!";
294 adaptive_difficulty_.DecreaseParameter();
295 continue;
296 }
297 }
298
299 // Since everything is already set-up, we try the sat_propagator_ with
300 // a really low conflict limit. This allow to quickly skip over UNSAT
301 // cases without the costly new problem setup.
302 if (!sat_propagator_->ModelIsUnsat()) {
303 sat::SatParameters params;
304 params.set_max_number_of_conflicts(
305 local_parameters.max_number_of_conflicts_for_quick_check());
306 params.set_max_time_in_seconds(time_limit->GetTimeLeft());
307 params.set_max_deterministic_time(time_limit->GetDeterministicTimeLeft());
308 params.set_random_seed(parameters.random_seed());
309 sat_propagator_->SetParameters(params);
310 sat_propagator_->SetAssumptionLevel(
311 sat_propagator_->CurrentDecisionLevel());
312
313 const sat::SatSolver::Status status = sat_propagator_->Solve();
314 if (status == sat::SatSolver::FEASIBLE) {
315 adaptive_difficulty_.IncreaseParameter();
316 SatAssignmentToBopSolution(sat_propagator_->Assignment(),
317 &learned_info->solution);
319 } else if (status == sat::SatSolver::ASSUMPTIONS_UNSAT) {
320 // Local problem is infeasible.
321 adaptive_difficulty_.IncreaseParameter();
322 continue;
323 }
324 }
325
326 // Restore to the assumption level.
327 // This is call is important since all the fixed variable in the
328 // propagator_ will be used to construct the local problem below.
329 // Note that calling ResetToLevelZero() might actually prove
330 // the infeasibility. It is important to check the UNSAT status afterward.
331 if (!sat_propagator_->ModelIsUnsat()) {
332 (void)sat_propagator_->ResetToLevelZero();
333 }
334
335 // Check if the problem is proved UNSAT, by previous the search or the
336 // ResetToLevelZero() call above.
337 if (sat_propagator_->ModelIsUnsat()) {
338 return problem_state.solution().IsFeasible()
341 }
342
343 // Construct and Solve the LNS subproblem.
344 //
345 // Note that we don't use the sat_propagator_ all the way because using a
346 // clean solver on a really small problem is usually a lot faster (even we
347 // the time to create the subproblem) that running a long solve under
348 // assumption (like we did above with a really low conflit limit).
349 const int conflict_limit =
350 adaptive_difficulty_.luby_value() *
351 parameters.max_number_of_conflicts_in_random_lns();
352
353 sat::SatParameters params;
354 params.set_max_number_of_conflicts(conflict_limit);
355 params.set_max_time_in_seconds(time_limit->GetTimeLeft());
356 params.set_max_deterministic_time(time_limit->GetDeterministicTimeLeft());
357 params.set_random_seed(parameters.random_seed());
358
359 sat::SatSolver sat_solver;
360 sat_solver.SetParameters(params);
361
362 // Starts by adding the unit clauses to fix the variables.
363 const LinearBooleanProblem& problem = problem_state.original_problem();
364 sat_solver.SetNumVariables(problem.num_variables());
365 for (int i = 0; i < sat_propagator_->LiteralTrail().Index(); ++i) {
366 CHECK(sat_solver.AddUnitClause(sat_propagator_->LiteralTrail()[i]));
367 }
368
369 // Load the rest of the problem. This will automatically create the small
370 // local subproblem using the already fixed variable.
371 //
372 // TODO(user): modify LoadStateProblemToSatSolver() so that we can call it
373 // instead and don't need to over constraint the objective below. As a
374 // bonus we will also have the learned binary clauses.
375 if (!LoadBooleanProblem(problem, &sat_solver)) {
376 // The local problem is infeasible.
377 adaptive_difficulty_.IncreaseParameter();
378 continue;
379 }
380
381 if (use_lp_to_guide_sat_) {
382 if (!UseLinearRelaxationForSatAssignmentPreference(
383 parameters, problem, &sat_solver, time_limit)) {
385 }
386 } else {
387 UseObjectiveForSatAssignmentPreference(problem, &sat_solver);
388 }
389
391 problem, sat::Coefficient(problem_state.solution().GetCost()) - 1,
392 &sat_solver)) {
393 // The local problem is infeasible.
394 adaptive_difficulty_.IncreaseParameter();
395 continue;
396 }
397
398 // Solve the local problem.
399 const sat::SatSolver::Status status = sat_solver.Solve();
400 time_limit->AdvanceDeterministicTime(sat_solver.deterministic_time());
401 if (status == sat::SatSolver::FEASIBLE) {
402 // We found a solution! abort now.
403 SatAssignmentToBopSolution(sat_solver.Assignment(),
404 &learned_info->solution);
406 }
407
408 // Adapt the difficulty.
409 if (sat_solver.num_failures() < 0.5 * conflict_limit) {
410 adaptive_difficulty_.IncreaseParameter();
411 } else if (sat_solver.num_failures() > 0.95 * conflict_limit) {
412 adaptive_difficulty_.DecreaseParameter();
413 }
414 }
415
417}
418
419//------------------------------------------------------------------------------
420// Neighborhood generators.
421//------------------------------------------------------------------------------
422
423namespace {
424
425std::vector<sat::Literal> ObjectiveVariablesAssignedToTheirLowCostValue(
426 const ProblemState& problem_state,
427 const BopConstraintTerms& objective_terms) {
428 std::vector<sat::Literal> result;
429 DCHECK(problem_state.solution().IsFeasible());
430 for (const BopConstraintTerm& term : objective_terms) {
431 if (((problem_state.solution().Value(term.var_id) && term.weight < 0) ||
432 (!problem_state.solution().Value(term.var_id) && term.weight > 0))) {
433 result.push_back(
434 sat::Literal(sat::BooleanVariable(term.var_id.value()),
435 problem_state.solution().Value(term.var_id)));
436 }
437 }
438 return result;
439}
440
441} // namespace
442
443void ObjectiveBasedNeighborhood::GenerateNeighborhood(
444 const ProblemState& problem_state, double difficulty,
445 sat::SatSolver* sat_propagator) {
446 // Generate the set of variable we may fix and randomize their order.
447 std::vector<sat::Literal> candidates =
448 ObjectiveVariablesAssignedToTheirLowCostValue(problem_state,
449 objective_terms_);
450 std::shuffle(candidates.begin(), candidates.end(), random_);
451
452 // We will use the sat_propagator to fix some variables as long as the number
453 // of propagated variables in the solver is under our target.
454 const int num_variables = sat_propagator->NumVariables();
455 const int target = round((1.0 - difficulty) * num_variables);
456
457 sat_propagator->Backtrack(0);
458 for (const sat::Literal literal : candidates) {
459 if (sat_propagator->LiteralTrail().Index() == target) break;
460 if (sat_propagator->LiteralTrail().Index() > target) {
461 // We prefer to error on the large neighborhood side, so we backtrack the
462 // last enqueued literal.
463 sat_propagator->Backtrack(
464 std::max(0, sat_propagator->CurrentDecisionLevel() - 1));
465 break;
466 }
467 sat_propagator->EnqueueDecisionAndBacktrackOnConflict(literal);
468 if (sat_propagator->ModelIsUnsat()) return;
469 }
470}
471
472void ConstraintBasedNeighborhood::GenerateNeighborhood(
473 const ProblemState& problem_state, double difficulty,
474 sat::SatSolver* sat_propagator) {
475 // Randomize the set of constraint
476 const LinearBooleanProblem& problem = problem_state.original_problem();
477 const int num_constraints = problem.constraints_size();
478 std::vector<int> ct_ids(num_constraints, 0);
479 for (int ct_id = 0; ct_id < num_constraints; ++ct_id) ct_ids[ct_id] = ct_id;
480 std::shuffle(ct_ids.begin(), ct_ids.end(), random_);
481
482 // Mark that we want to relax all the variables of these constraints as long
483 // as the number of relaxed variable is lower than our difficulty target.
484 const int num_variables = sat_propagator->NumVariables();
485 const int target = round(difficulty * num_variables);
486 int num_relaxed = 0;
487 std::vector<bool> variable_is_relaxed(problem.num_variables(), false);
488 for (int i = 0; i < ct_ids.size(); ++i) {
489 if (num_relaxed >= target) break;
490 const LinearBooleanConstraint& constraint = problem.constraints(ct_ids[i]);
491
492 // We exclude really large constraints since they are probably note helpful
493 // in picking a nice neighborhood.
494 if (constraint.literals_size() > 0.7 * num_variables) continue;
495
496 for (int j = 0; j < constraint.literals_size(); ++j) {
497 const VariableIndex var_id(constraint.literals(j) - 1);
498 if (!variable_is_relaxed[var_id.value()]) {
499 ++num_relaxed;
500 variable_is_relaxed[var_id.value()] = true;
501 }
502 }
503 }
504
505 // Basic version: simply fix all the "to_fix" variable that are not relaxed.
506 //
507 // TODO(user): Not fixing anything that propagates a variable in
508 // variable_is_relaxed may be better. It is actually a lot better in the
509 // RelationGraphBasedNeighborhood. To investigate.
510 sat_propagator->Backtrack(0);
511 const std::vector<sat::Literal> to_fix =
512 ObjectiveVariablesAssignedToTheirLowCostValue(problem_state,
513 objective_terms_);
514 for (const sat::Literal literal : to_fix) {
515 if (variable_is_relaxed[literal.Variable().value()]) continue;
516 sat_propagator->EnqueueDecisionAndBacktrackOnConflict(literal);
517 if (sat_propagator->ModelIsUnsat()) return;
518 }
519}
520
522 const LinearBooleanProblem& problem, absl::BitGenRef random)
523 : random_(random) {
524 const int num_variables = problem.num_variables();
525 columns_.resize(num_variables);
526
527 // We will ignore constraints that have more variables than this percentage of
528 // the total number of variables in this neighborhood computation.
529 //
530 // TODO(user): Factor this out with the similar factor in
531 // ConstraintBasedNeighborhood? also maybe a better approach is to order the
532 // constraint, and stop the neighborhood extension without considering all of
533 // them.
534 const double kSizeThreshold = 0.1;
535 for (int i = 0; i < problem.constraints_size(); ++i) {
536 const LinearBooleanConstraint& constraint = problem.constraints(i);
537 if (constraint.literals_size() > kSizeThreshold * num_variables) continue;
538 for (int j = 0; j < constraint.literals_size(); ++j) {
539 const sat::Literal literal(constraint.literals(j));
540 columns_[VariableIndex(literal.Variable().value())].push_back(
541 ConstraintIndex(i));
542 }
543 }
544}
545
546void RelationGraphBasedNeighborhood::GenerateNeighborhood(
547 const ProblemState& problem_state, double difficulty,
548 sat::SatSolver* sat_propagator) {
549 // Simply walk the graph until enough variable are relaxed.
550 const int num_variables = sat_propagator->NumVariables();
551 const int target = round(difficulty * num_variables);
552 int num_relaxed = 1;
553 std::vector<bool> variable_is_relaxed(num_variables, false);
554 std::deque<int> queue;
555
556 // TODO(user): If one plan to try of lot of different LNS, maybe it will be
557 // better to try to bias the distribution of "center" to be as spread as
558 // possible.
559 queue.push_back(absl::Uniform(random_, 0, num_variables));
560 variable_is_relaxed[queue.back()] = true;
561 while (!queue.empty() && num_relaxed < target) {
562 const int var = queue.front();
563 queue.pop_front();
564 for (ConstraintIndex ct_index : columns_[VariableIndex(var)]) {
565 const LinearBooleanConstraint& constraint =
566 problem_state.original_problem().constraints(ct_index.value());
567 for (int i = 0; i < constraint.literals_size(); ++i) {
568 const sat::Literal literal(constraint.literals(i));
569 const int next_var = literal.Variable().value();
570 if (!variable_is_relaxed[next_var]) {
571 ++num_relaxed;
572 variable_is_relaxed[next_var] = true;
573 queue.push_back(next_var);
574 }
575 }
576 }
577 }
578
579 // Loops over all the variables in order and only fix the ones that don't
580 // propagate any relaxed variables.
581 DCHECK(problem_state.solution().IsFeasible());
582 sat_propagator->Backtrack(0);
583 for (sat::BooleanVariable var(0); var < num_variables; ++var) {
584 const sat::Literal literal(
585 var, problem_state.solution().Value(VariableIndex(var.value())));
586 if (variable_is_relaxed[literal.Variable().value()]) continue;
587 int index;
588 sat_propagator->EnqueueDecisionAndBacktrackOnConflict(literal, &index);
589 if (sat_propagator->CurrentDecisionLevel() > 0) {
590 for (int i = index; i < sat_propagator->LiteralTrail().Index(); ++i) {
591 if (variable_is_relaxed
592 [sat_propagator->LiteralTrail()[i].Variable().value()]) {
593 sat_propagator->Backtrack(sat_propagator->CurrentDecisionLevel() - 1);
594 }
595 }
596 }
597 if (sat_propagator->ModelIsUnsat()) return;
598 }
599 VLOG(2) << "target:" << target << " relaxed:" << num_relaxed << " actual:"
600 << num_variables - sat_propagator->LiteralTrail().Index();
601}
602
603} // namespace bop
604} // namespace operations_research
void AdvanceDeterministicTime(double deterministic_duration)
Definition time_limit.h:186
double GetDeterministicTimeLeft() const
Definition time_limit.h:177
BopAdaptiveLNSOptimizer(absl::string_view name, bool use_lp_to_guide_sat, NeighborhoodGenerator *neighborhood_generator, sat::SatSolver *sat_propagator)
Definition bop_lns.cc:231
BopCompleteLNSOptimizer(absl::string_view name, const BopConstraintTerms &objective_terms)
Definition bop_lns.cc:73
BopOptimizerBase(absl::string_view name)
Definition bop_base.cc:44
const std::string & name() const
Definition bop_base.h:53
bool Value(VariableIndex var) const
const BopSolution & solution() const
Definition bop_base.h:204
RelationGraphBasedNeighborhood(const sat::LinearBooleanProblem &problem, absl::BitGenRef random)
Definition bop_lns.cc:527
BooleanVariable Variable() const
Definition sat_base.h:88
Status EnqueueDecisionAndBacktrackOnConflict(Literal true_literal, int *first_propagation_index=nullptr)
void Backtrack(int target_level)
ABSL_MUST_USE_RESULT bool ResetToLevelZero()
const Trail & LiteralTrail() const
Definition sat_solver.h:419
BopOptimizerBase::Status LoadStateProblemToSatSolver(const ProblemState &problem_state, sat::SatSolver *sat_solver)
Definition bop_util.cc:98
util_intops::StrongVector< SparseIndex, BopConstraintTerm > BopConstraintTerms
Definition bop_types.h:89
void SatAssignmentToBopSolution(const sat::VariablesAssignment &assignment, BopSolution *solution)
Definition bop_util.cc:132
void ExtractLearnedInfoFromSatSolver(sat::SatSolver *solver, LearnedInfo *info)
Definition bop_util.cc:109
StrictITIVector< ColIndex, Fractional > DenseRow
Definition lp_types.h:351
bool LoadBooleanProblem(const LinearBooleanProblem &problem, SatSolver *solver)
void ConvertBooleanProblemToLinearProgram(const LinearBooleanProblem &problem, glop::LinearProgram *lp)
Definition lp_utils.cc:1650
bool AddObjectiveUpperBound(const LinearBooleanProblem &problem, Coefficient upper_bound, SatSolver *solver)
void UseObjectiveForSatAssignmentPreference(const LinearBooleanProblem &problem, SatSolver *solver)
OR-Tools root namespace.
Select next search node to expand Select next item_i to add this new search node to the search Generate a new search node where item_i is not in the knapsack Check validity of this new partial solution(using propagators) - If valid
#define SCOPED_TIME_STAT(stats)
Definition stats.h:419