Google OR-Tools
v9.15
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-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
// 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 ORTOOLS_BOP_COMPLETE_OPTIMIZER_H_
28
#define ORTOOLS_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"
36
#include "
ortools/bop/bop_base.h
"
37
#include "
ortools/bop/bop_parameters.pb.h
"
38
#include "
ortools/bop/bop_solution.h
"
39
#include "
ortools/bop/bop_types.h
"
40
#include "
ortools/sat/boolean_problem.pb.h
"
41
#include "
ortools/sat/encoding.h
"
42
#include "
ortools/sat/model.h
"
43
#include "
ortools/sat/pb_constraint.h
"
44
#include "
ortools/sat/sat_solver.h
"
45
#include "
ortools/util/time_limit.h
"
46
47
namespace
operations_research
{
48
namespace
bop
{
49
50
// TODO(user): Merge this with the code in sat/optimization.cc
51
class
SatCoreBasedOptimizer
:
public
BopOptimizerBase
{
52
public
:
53
explicit
SatCoreBasedOptimizer
(absl::string_view
name
);
54
~SatCoreBasedOptimizer
()
override
;
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
// ORTOOLS_BOP_COMPLETE_OPTIMIZER_H_
boolean_problem.pb.h
bop_base.h
bop_parameters.pb.h
bop_solution.h
bop_types.h
operations_research::TimeLimit
Definition
time_limit.h:97
operations_research::bop::BopOptimizerBase::BopOptimizerBase
BopOptimizerBase(absl::string_view name)
Definition
bop_base.cc:44
operations_research::bop::BopOptimizerBase::Status
Status
Definition
bop_base.h:68
operations_research::bop::BopOptimizerBase::name
const std::string & name() const
Definition
bop_base.h:53
operations_research::bop::BopParameters
Definition
bop_parameters.pb.h:599
operations_research::bop::ProblemState
Definition
bop_base.h:118
operations_research::bop::SatCoreBasedOptimizer::ShouldBeRun
bool ShouldBeRun(const ProblemState &problem_state) const override
Definition
complete_optimizer.cc:114
operations_research::bop::SatCoreBasedOptimizer::~SatCoreBasedOptimizer
~SatCoreBasedOptimizer() override
operations_research::bop::SatCoreBasedOptimizer::Optimize
Status Optimize(const BopParameters ¶meters, const ProblemState &problem_state, LearnedInfo *learned_info, TimeLimit *time_limit) override
Definition
complete_optimizer.cc:119
operations_research::bop::SatCoreBasedOptimizer::SatCoreBasedOptimizer
SatCoreBasedOptimizer(absl::string_view name)
Definition
complete_optimizer.cc:42
operations_research::sat::Model
Definition
model.h:38
operations_research::sat::ObjectiveEncoder
Definition
encoding.h:232
operations_research::sat::SatSolver
Definition
sat_solver.h:64
operations_research::sat::SatSolver::Status
Status
Definition
sat_solver.h:206
encoding.h
operations_research::bop
Definition
bop_base.cc:39
operations_research
OR-Tools root namespace.
Definition
binary_indexed_tree.h:21
pb_constraint.h
model.h
sat_solver.h
operations_research::bop::LearnedInfo
Definition
bop_base.h:254
time_limit.h
ortools
bop
complete_optimizer.h
Generated by
1.15.0