Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
complete_optimizer.h
Go to the documentation of this file.
1// Copyright 2010-2024 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// This file contains some BopOptimizerBase implementations that are "complete"
15// solvers. That is, they work on the full problem, and can solve the problem
16// (and prove optimality) by themselves. Moreover, they can be run for short
17// period of time and resumed later from the state they where left off.
18//
19// The idea is that it is worthwhile spending some time in these algorithms,
20// because in some situation they can improve the current upper/lower bound or
21// even solve the problem to optimality.
22//
23// Note(user): The GuidedSatFirstSolutionGenerator can also be used as a
24// complete SAT solver provided that we keep running it after it has found a
25// first solution. This is the default behavior of the kNotGuided policy.
26
27#ifndef OR_TOOLS_BOP_COMPLETE_OPTIMIZER_H_
28#define OR_TOOLS_BOP_COMPLETE_OPTIMIZER_H_
29
30#include <cstdint>
31#include <deque>
32#include <string>
33#include <vector>
34
35#include "absl/strings/string_view.h"
37#include "ortools/bop/bop_parameters.pb.h"
40#include "ortools/sat/boolean_problem.pb.h"
42#include "ortools/sat/model.h"
46
47namespace operations_research {
48namespace bop {
49
50// TODO(user): Merge this with the code in sat/optimization.cc
52 public:
53 explicit SatCoreBasedOptimizer(absl::string_view name);
55
56 protected:
57 bool ShouldBeRun(const ProblemState& problem_state) const override;
58 Status Optimize(const BopParameters& parameters,
59 const ProblemState& problem_state, LearnedInfo* learned_info,
60 TimeLimit* time_limit) override;
61
62 private:
63 BopOptimizerBase::Status SynchronizeIfNeeded(
64 const ProblemState& problem_state);
65 sat::SatSolver::Status SolveWithAssumptions();
66
67 sat::Model model_;
68 sat::SatSolver* sat_solver_;
69 sat::ObjectiveEncoder encoder_;
70
71 int64_t state_update_stamp_;
72 bool initialized_;
73 bool assumptions_already_added_;
74 sat::Coefficient offset_;
75 sat::Coefficient lower_bound_;
76 sat::Coefficient upper_bound_;
77 sat::Coefficient stratified_lower_bound_;
78};
79
80} // namespace bop
81} // namespace operations_research
82
83#endif // OR_TOOLS_BOP_COMPLETE_OPTIMIZER_H_
const std::string & name() const
Returns the name given at construction.
Definition bop_base.h:54
bool ShouldBeRun(const ProblemState &problem_state) const override
Only run this if there is an objective.
Status Optimize(const BopParameters &parameters, const ProblemState &problem_state, LearnedInfo *learned_info, TimeLimit *time_limit) override
SatParameters parameters
time_limit
Definition solve.cc:22
In SWIG mode, we don't want anything besides these top-level includes.