21#include "absl/log/check.h"
22#include "absl/status/status.h"
23#include "absl/strings/str_format.h"
24#include "google/protobuf/text_format.h"
28#include "ortools/bop/bop_parameters.pb.h"
34#include "ortools/sat/boolean_problem.pb.h"
42using ::operations_research::sat::LinearBooleanProblem;
46using ::operations_research::glop::ColIndex;
47using ::operations_research::glop::DenseRow;
53 ProblemState* problem_state) {
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();
101 return parameters_.number_of_solvers() > 1
109 PortfolioOptimizer optimizer(problem_state_, parameters_,
110 parameters_.solver_optimizer_sets(0),
114 parameters_, problem_state_, &learned_info,
time_limit);
120 <<
" New solution! ";
133 learned_info.Clear();
158 VLOG(1) <<
"First solution is feasible.";
160 learned_info.solution = first_solution;
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)));
190void BopSolver::UpdateParameters() {
191 if (parameters_.solver_optimizer_sets_size() == 0) {
194 CHECK(::google::protobuf::TextFormat::ParseFromString(
195 parameters_.default_solver_optimizer_sets(),
196 parameters_.add_solver_optimizer_sets()));
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.
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...
int64_t lower_bound() const
bool MergeLearnedInfo(const LearnedInfo &learned_info, BopOptimizerBase::Status optimization_status)
bool IsInfeasible() const
Returns true when the problem is proved to be infeasible.
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
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)