21#include "absl/log/check.h"
22#include "absl/log/log.h"
23#include "absl/status/status.h"
24#include "absl/strings/str_format.h"
25#include "google/protobuf/text_format.h"
42using ::operations_research::sat::LinearBooleanProblem;
46using ::operations_research::glop::ColIndex;
55 problem_state_(problem),
64 std::unique_ptr<TimeLimit> time_limit =
70 CHECK(time_limit !=
nullptr);
75 LOG(ERROR) <<
"Invalid Boolean problem: " << valid.message();
82 ? InternalMultithreadSolver(time_limit)
83 : InternalMonothreadSolver(time_limit);
87 CHECK(time_limit !=
nullptr);
89 PortfolioOptimizer optimizer(problem_state_, parameters_,
94 parameters_, problem_state_, &learned_info, time_limit);
100 <<
" New solution! ";
106 }
else if (problem_state_.IsInfeasible()) {
113 learned_info.Clear();
116 return problem_state_.solution().IsFeasible()
121BopSolveStatus BopSolver::InternalMultithreadSolver(TimeLimit* time_limit) {
122 CHECK(time_limit !=
nullptr);
128 std::unique_ptr<TimeLimit> time_limit =
138 VLOG(1) <<
"First solution is feasible.";
140 learned_info.solution = first_solution;
141 if (problem_state_.MergeLearnedInfo(learned_info,
143 problem_state_.IsOptimal()) {
148 <<
"First solution is infeasible. Using it as assignment preference.";
149 std::vector<bool> assignment_preference;
150 assignment_preference.reserve(first_solution.
Size());
151 for (
int i = 0; i < first_solution.
Size(); ++i) {
152 assignment_preference.push_back(first_solution.
Value(VariableIndex(i)));
161 problem_, sat::Coefficient(problem_state_.lower_bound()));
166 std::abs(problem_state_.solution().GetScaledCost() -
168 std::abs(problem_state_.solution().GetScaledCost());
171void BopSolver::UpdateParameters() {
175 CHECK(::google::protobuf::TextFormat::ParseFromString(
std::string StatString() const
static std::unique_ptr< TimeLimit > FromParameters(const Parameters ¶meters)
::operations_research::bop::BopSolverOptimizerSet *PROTOBUF_NONNULL add_solver_optimizer_sets()
::int32_t number_of_solvers() const
const ::operations_research::bop::BopSolverOptimizerSet & solver_optimizer_sets(int index) const
int solver_optimizer_sets_size() const
const ::std::string & default_solver_optimizer_sets() const
double GetScaledCost() const
bool Value(VariableIndex var) const
double GetScaledBestBound() const
BopSolveStatus SolveWithTimeLimit(TimeLimit *time_limit)
double GetScaledGap() const
BopSolver(const sat::LinearBooleanProblem &problem)
void set_assignment_preference(const std::vector< bool > &a)
const BopSolution & solution() const
void SetParameters(const BopParameters ¶meters)
bool MergeLearnedInfo(const LearnedInfo &learned_info, BopOptimizerBase::Status optimization_status)
const sat::LinearBooleanProblem & original_problem() const
@ FEASIBLE_SOLUTION_FOUND
StrictITIVector< ColIndex, Fractional > DenseRow
double AddOffsetAndScaleObjectiveValue(const LinearBooleanProblem &problem, Coefficient v)
absl::Status ValidateBooleanProblem(const LinearBooleanProblem &problem)
#define IF_STATS_ENABLED(instructions)
#define SCOPED_TIME_STAT(stats)