forked from google/or-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete_optimizer.h
74 lines (63 loc) · 2.72 KB
/
complete_optimizer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2010-2018 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// This file contains some BopOptimizerBase implementations that are "complete"
// solvers. That is, they work on the full problem, and can solve the problem
// (and prove optimality) by themselves. Moreover, they can be run for short
// period of time and resumed later from the state they where left off.
//
// The idea is that it is worthwhile spending some time in these algorithms,
// because in some situation they can improve the current upper/lower bound or
// even solve the problem to optimality.
//
// Note(user): The GuidedSatFirstSolutionGenerator can also be used as a
// complete SAT solver provided that we keep running it after it has found a
// first solution. This is the default behavior of the kNotGuided policy.
#ifndef OR_TOOLS_BOP_COMPLETE_OPTIMIZER_H_
#define OR_TOOLS_BOP_COMPLETE_OPTIMIZER_H_
#include <deque>
#include "ortools/bop/bop_base.h"
#include "ortools/bop/bop_solution.h"
#include "ortools/bop/bop_types.h"
#include "ortools/sat/boolean_problem.pb.h"
#include "ortools/sat/encoding.h"
#include "ortools/sat/sat_solver.h"
namespace operations_research {
namespace bop {
// TODO(user): Merge this with the code in sat/optimization.cc
class SatCoreBasedOptimizer : public BopOptimizerBase {
public:
explicit SatCoreBasedOptimizer(const std::string& name);
~SatCoreBasedOptimizer() override;
protected:
bool ShouldBeRun(const ProblemState& problem_state) const override;
Status Optimize(const BopParameters& parameters,
const ProblemState& problem_state, LearnedInfo* learned_info,
TimeLimit* time_limit) override;
private:
BopOptimizerBase::Status SynchronizeIfNeeded(
const ProblemState& problem_state);
sat::SatSolver::Status SolveWithAssumptions();
int64 state_update_stamp_;
bool initialized_;
bool assumptions_already_added_;
sat::SatSolver solver_;
sat::Coefficient offset_;
sat::Coefficient lower_bound_;
sat::Coefficient upper_bound_;
sat::Coefficient stratified_lower_bound_;
std::deque<sat::EncodingNode> repository_;
std::vector<sat::EncodingNode*> nodes_;
};
} // namespace bop
} // namespace operations_research
#endif // OR_TOOLS_BOP_COMPLETE_OPTIMIZER_H_