OR-Tools  8.1
complete_optimizer.h
Go to the documentation of this file.
1 // Copyright 2010-2018 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 <deque>
31 
32 #include "ortools/bop/bop_base.h"
34 #include "ortools/bop/bop_types.h"
36 #include "ortools/sat/encoding.h"
37 #include "ortools/sat/sat_solver.h"
38 
39 namespace operations_research {
40 namespace bop {
41 
42 // TODO(user): Merge this with the code in sat/optimization.cc
44  public:
45  explicit SatCoreBasedOptimizer(const std::string& name);
46  ~SatCoreBasedOptimizer() override;
47 
48  protected:
49  bool ShouldBeRun(const ProblemState& problem_state) const override;
50  Status Optimize(const BopParameters& parameters,
51  const ProblemState& problem_state, LearnedInfo* learned_info,
52  TimeLimit* time_limit) override;
53 
54  private:
55  BopOptimizerBase::Status SynchronizeIfNeeded(
56  const ProblemState& problem_state);
57  sat::SatSolver::Status SolveWithAssumptions();
58 
59  int64 state_update_stamp_;
60  bool initialized_;
61  bool assumptions_already_added_;
62  sat::SatSolver solver_;
63  sat::Coefficient offset_;
64  sat::Coefficient lower_bound_;
65  sat::Coefficient upper_bound_;
66  sat::Coefficient stratified_lower_bound_;
67  std::deque<sat::EncodingNode> repository_;
68  std::vector<sat::EncodingNode*> nodes_;
69 };
70 
71 } // namespace bop
72 } // namespace operations_research
73 
74 #endif // OR_TOOLS_BOP_COMPLETE_OPTIMIZER_H_
operations_research::sat::SatSolver::Status
Status
Definition: sat_solver.h:181
operations_research::bop::BopOptimizerBase::name
const std::string & name() const
Definition: bop_base.h:46
encoding.h
operations_research::sat::SatSolver
Definition: sat_solver.h:58
operations_research::bop::SatCoreBasedOptimizer::Optimize
Status Optimize(const BopParameters &parameters, const ProblemState &problem_state, LearnedInfo *learned_info, TimeLimit *time_limit) override
Definition: complete_optimizer.cc:81
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
bop_solution.h
operations_research::bop::BopOptimizerBase
Definition: bop_base.h:40
int64
int64_t int64
Definition: integral_types.h:34
sat_solver.h
operations_research::TimeLimit
A simple class to enforce both an elapsed time limit and a deterministic time limit in the same threa...
Definition: time_limit.h:105
time_limit
SharedTimeLimit * time_limit
Definition: cp_model_solver.cc:2103
operations_research::bop::SatCoreBasedOptimizer::ShouldBeRun
bool ShouldBeRun(const ProblemState &problem_state) const override
Definition: complete_optimizer.cc:76
operations_research::bop::LearnedInfo
Definition: bop_base.h:245
bop_types.h
operations_research::bop::ProblemState
Definition: bop_base.h:111
boolean_problem.pb.h
operations_research::bop::SatCoreBasedOptimizer::SatCoreBasedOptimizer
SatCoreBasedOptimizer(const std::string &name)
Definition: complete_optimizer.cc:22
bop_base.h
operations_research::bop::SatCoreBasedOptimizer::~SatCoreBasedOptimizer
~SatCoreBasedOptimizer() override
Definition: complete_optimizer.cc:32
operations_research::bop::BopOptimizerBase::Status
Status
Definition: bop_base.h:61
parameters
SatParameters parameters
Definition: cp_model_fz_solver.cc:108
operations_research::bop::SatCoreBasedOptimizer
Definition: complete_optimizer.h:43