Google OR-Tools
v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
bop_solver.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
#ifndef ORTOOLS_BOP_BOP_SOLVER_H_
15
#define ORTOOLS_BOP_BOP_SOLVER_H_
16
17
// Solver for Boolean Optimization Problems built on top of the SAT solver.
18
// To optimize a problem the solver uses several optimization strategies like
19
// Local Search (LS), Large Neighborhood Search (LNS), and Linear
20
// Programming (LP). See bop_parameters.proto to tune the strategies.
21
//
22
// Note that the BopSolver usage is limited to:
23
// - Boolean variables,
24
// - Linear constraints and linear optimization objective,
25
// - Integral weights for both constraints and objective,
26
// - Minimization.
27
// To deal with maximization, integral variables and floating weights, one can
28
// use the bop::IntegralSolver.
29
//
30
// Usage example:
31
// const LinearBooleanProblem problem = BuildProblem();
32
// BopSolver bop_solver(problem);
33
// BopParameters bop_parameters;
34
// bop_parameters.set_max_deterministic_time(10);
35
// bop_solver.SetParameters(bop_parameters);
36
// const BopSolveStatus solve_status = bop_solver.Solve();
37
// if (solve_status == BopSolveStatus::OPTIMAL_SOLUTION_FOUND) { ... }
38
39
#include "
ortools/bop/bop_base.h
"
40
#include "
ortools/bop/bop_parameters.pb.h
"
41
#include "
ortools/bop/bop_solution.h
"
42
#include "
ortools/bop/bop_types.h
"
43
#include "
ortools/sat/boolean_problem.pb.h
"
44
#include "
ortools/util/stats.h
"
45
#include "
ortools/util/time_limit.h
"
46
47
namespace
operations_research
{
48
namespace
bop
{
49
// Solver of Boolean Optimization Problems based on Local Search.
50
class
BopSolver
{
51
public
:
52
explicit
BopSolver
(
const
sat::LinearBooleanProblem
& problem);
53
virtual
~BopSolver
();
54
55
// Parameters management.
56
void
SetParameters
(
const
BopParameters
& parameters) {
57
parameters_ = parameters;
58
}
59
60
// Returns the status of the optimization.
61
BopSolveStatus
Solve
();
62
BopSolveStatus
Solve
(
const
BopSolution
& first_solution);
63
64
// Runs the solver with an external time limit.
65
BopSolveStatus
SolveWithTimeLimit
(
TimeLimit
* time_limit);
66
BopSolveStatus
SolveWithTimeLimit
(
const
BopSolution
& first_solution,
67
TimeLimit
* time_limit);
68
69
const
BopSolution
&
best_solution
()
const
{
return
problem_state_.solution(); }
70
bool
GetSolutionValue
(VariableIndex var_id)
const
{
71
return
problem_state_.solution().Value(var_id);
72
}
73
74
// Returns the scaled best bound.
75
// In case of minimization (resp. maximization), the best bound is defined as
76
// the lower bound (resp. upper bound).
77
double
GetScaledBestBound
()
const
;
78
double
GetScaledGap
()
const
;
79
80
private
:
81
void
UpdateParameters();
82
BopSolveStatus
InternalMonothreadSolver(
TimeLimit
* time_limit);
83
BopSolveStatus
InternalMultithreadSolver(
TimeLimit
* time_limit);
84
85
const
sat::LinearBooleanProblem
& problem_;
86
ProblemState
problem_state_;
87
BopParameters
parameters_;
88
89
mutable
StatsGroup
stats_;
90
};
91
}
// namespace bop
92
}
// namespace operations_research
93
#endif
// ORTOOLS_BOP_BOP_SOLVER_H_
boolean_problem.pb.h
bop_base.h
bop_parameters.pb.h
bop_solution.h
bop_types.h
operations_research::StatsGroup
Definition
stats.h:129
operations_research::TimeLimit
Definition
time_limit.h:97
operations_research::bop::BopParameters
Definition
bop_parameters.pb.h:599
operations_research::bop::BopSolution
Definition
bop_solution.h:39
operations_research::bop::BopSolver::GetSolutionValue
bool GetSolutionValue(VariableIndex var_id) const
Definition
bop_solver.h:70
operations_research::bop::BopSolver::Solve
BopSolveStatus Solve()
Definition
bop_solver.cc:65
operations_research::bop::BopSolver::SetParameters
void SetParameters(const BopParameters ¶meters)
Definition
bop_solver.h:56
operations_research::bop::BopSolver::GetScaledBestBound
double GetScaledBestBound() const
Definition
bop_solver.cc:161
operations_research::bop::BopSolver::~BopSolver
virtual ~BopSolver()
Definition
bop_solver.cc:63
operations_research::bop::BopSolver::SolveWithTimeLimit
BopSolveStatus SolveWithTimeLimit(TimeLimit *time_limit)
Definition
bop_solver.cc:71
operations_research::bop::BopSolver::best_solution
const BopSolution & best_solution() const
Definition
bop_solver.h:69
operations_research::bop::BopSolver::GetScaledGap
double GetScaledGap() const
Definition
bop_solver.cc:166
operations_research::bop::BopSolver::BopSolver
BopSolver(const sat::LinearBooleanProblem &problem)
Definition
bop_solver.cc:55
operations_research::bop::ProblemState
Definition
bop_base.h:118
operations_research::sat::LinearBooleanProblem
Definition
boolean_problem.pb.h:798
operations_research::bop
Definition
bop_base.cc:39
operations_research::bop::BopSolveStatus
BopSolveStatus
Definition
bop_types.h:34
operations_research
OR-Tools root namespace.
Definition
binary_indexed_tree.h:21
stats.h
time_limit.h
ortools
bop
bop_solver.h
Generated by
1.15.0