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;
54 CHECK(
nullptr != problem_state);
57 problem_state->MarkAsOptimal();
62 problem_state->MarkAsInfeasible();
75 problem_state_(problem),
95 LOG(ERROR) <<
"Invalid Boolean problem: " << valid.message();
109 PortfolioOptimizer optimizer(problem_state_, parameters_,
114 parameters_, problem_state_, &learned_info,
time_limit);
120 <<
" New solution! ";
126 }
else if (problem_state_.IsInfeasible()) {
133 learned_info.Clear();
136 return problem_state_.solution().IsFeasible()
158 VLOG(1) <<
"First solution is feasible.";
160 learned_info.solution = first_solution;
161 if (problem_state_.MergeLearnedInfo(learned_info,
163 problem_state_.IsOptimal()) {
168 <<
"First solution is infeasible. Using it as assignment preference.";
169 std::vector<bool> assignment_preference;
170 for (
int i = 0; i < first_solution.
Size(); ++i) {
171 assignment_preference.push_back(first_solution.
Value(VariableIndex(i)));
180 problem_, sat::Coefficient(problem_state_.lower_bound()));
185 std::abs(problem_state_.solution().GetScaledCost() -
187 std::abs(problem_state_.solution().GetScaledCost());
190void BopSolver::UpdateParameters() {
194 CHECK(::google::protobuf::TextFormat::ParseFromString(
std::string StatString() const
static std::unique_ptr< TimeLimit > FromParameters(const Parameters ¶meters)
@ ABORT
There is no need to call this optimizer again on the same problem state.
::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
repeated .operations_research.bop.BopSolverOptimizerSet solver_optimizer_sets = 26;
const ::std::string & default_solver_optimizer_sets() const
double GetScaledCost() const
bool Value(VariableIndex var) const
BopSolveStatus Solve()
Returns the status of the optimization.
double GetScaledBestBound() const
BopSolveStatus SolveWithTimeLimit(TimeLimit *time_limit)
Runs the solver with an external 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)
Sets parameters, used for instance to get the tolerance, the gap limit...
bool MergeLearnedInfo(const LearnedInfo &learned_info, BopOptimizerBase::Status optimization_status)
const sat::LinearBooleanProblem & original_problem() const
BopSolveStatus
Status of the solve of Bop.
@ NO_SOLUTION_FOUND
The solver didn't find any solution.
@ OPTIMAL_SOLUTION_FOUND
The solver found the proven optimal solution.
@ INFEASIBLE_PROBLEM
The problem is infeasible.
@ INVALID_PROBLEM
The problem is invalid.
@ FEASIBLE_SOLUTION_FOUND
StrictITIVector< ColIndex, Fractional > DenseRow
Row-vector types. Row-vector types are indexed by a column index.
double AddOffsetAndScaleObjectiveValue(const LinearBooleanProblem &problem, Coefficient v)
Adds the offset and returns the scaled version of the given objective value.
absl::Status ValidateBooleanProblem(const LinearBooleanProblem &problem)
In SWIG mode, we don't want anything besides these top-level includes.
#define IF_STATS_ENABLED(instructions)
#define SCOPED_TIME_STAT(stats)