18#include "google/protobuf/text_format.h"
24#include "ortools/bop/bop_parameters.pb.h"
44 LOG(DFATAL) <<
"Invalid bop::BopSolveStatus";
59 void Reset()
override;
67 const MPVariable*
const variable,
double new_value,
68 double old_value)
override;
83 bool IsLP()
const override;
84 bool IsMIP()
const override;
105 void NonIncrementalChange();
109 std::vector<MPSolver::BasisStatus> column_status_;
110 std::vector<MPSolver::BasisStatus> row_status_;
111 bop::BopParameters parameters_;
112 std::atomic<bool> interrupt_solver_;
122 interrupt_solver_(false) {}
128 if (interrupt_solver_) {
147 parameters_.set_max_time_in_seconds(
150 parameters_.set_log_search_progress(!
quiet());
153 if (!
solver_->solution_hint_.empty()) {
154 const int num_vars =
solver_->variables_.size();
155 if (
solver_->solution_hint_.size() != num_vars) {
156 LOG(
WARNING) <<
"Bop currently doesn't handle partial solution hints. "
157 <<
"Filling the missing positions with zeros...";
160 for (
const std::pair<const MPVariable*, double>& p :
162 initial_solution[glop::ColIndex(p.first->index())] =
168 solver_->solver_specific_parameter_string_);
172 time_limit->RegisterExternalBooleanAsLimit(&interrupt_solver_);
174 initial_solution.
empty()
189 const size_t num_vars =
solver_->variables_.size();
191 for (
int var_id = 0; var_id < num_vars; ++var_id) {
193 const glop::ColIndex lp_solver_var_id(
var->index());
196 var->set_solution_value(
static_cast<double>(solution_value));
200 const size_t num_constraints =
solver_->constraints_.size();
209 linear_program_.
Clear();
210 interrupt_solver_ =
false;
214 NonIncrementalChange();
218 NonIncrementalChange();
222 NonIncrementalChange();
226 NonIncrementalChange();
230 NonIncrementalChange();
234 NonIncrementalChange();
239 double new_value,
double old_value) {
240 NonIncrementalChange();
244 NonIncrementalChange();
249 NonIncrementalChange();
257 LOG(DFATAL) <<
"Number of iterations not available";
262 LOG(DFATAL) <<
"Number of nodes not available";
267 return row_status_[constraint_index];
271 return column_status_[variable_index];
284 interrupt_solver_ =
true;
295 const glop::ColIndex num_cols(
solver_->variables_.size());
302 if (
var->integer()) {
313 const glop::RowIndex num_rows(
solver_->constraints_.size());
314 for (glop::RowIndex
row(0);
row < num_rows; ++
row) {
318 const double lb =
ct->lb();
319 const double ub =
ct->ub();
324 for (
const auto& entry :
ct->coefficients_) {
325 const int var_index = entry.first->index();
327 const glop::ColIndex
col(var_index);
328 const double coeff = entry.second;
337 for (
const auto& entry :
solver_->objective_->coefficients_) {
338 const int var_index = entry.first->index();
339 const glop::ColIndex
col(var_index);
340 const double coeff = entry.second;
375 google::protobuf::TextFormat::MergeFromString(
parameters, ¶meters_);
380void BopInterface::NonIncrementalChange() {
#define DCHECK(condition)
#define DCHECK_EQ(val1, val2)
#define VLOG(verboselevel)
void SetScalingMode(int value) override
void SetDualTolerance(double value) override
void AddRowConstraint(MPConstraint *const ct) override
void SetLpAlgorithm(int value) override
int64 nodes() const override
void ExtractObjective() override
void * underlying_solver() override
bool IsContinuous() const override
bool InterruptSolve() override
MPSolver::ResultStatus Solve(const MPSolverParameters ¶m) override
void SetPrimalTolerance(double value) override
void ClearConstraint(MPConstraint *const constraint) override
bool SetSolverSpecificParametersAsString(const std::string ¶meters) override
void SetObjectiveCoefficient(const MPVariable *const variable, double coefficient) override
void SetCoefficient(MPConstraint *const constraint, const MPVariable *const variable, double new_value, double old_value) override
MPSolver::BasisStatus row_status(int constraint_index) const override
void SetObjectiveOffset(double value) override
void SetVariableInteger(int index, bool integer) override
void SetParameters(const MPSolverParameters ¶m) override
void ExtractNewConstraints() override
BopInterface(MPSolver *const solver)
std::string SolverVersion() const override
void SetRelativeMipGap(double value) override
void SetConstraintBounds(int index, double lb, double ub) override
void SetPresolveMode(int value) override
void SetVariableBounds(int index, double lb, double ub) override
void AddVariable(MPVariable *const var) override
void ExtractNewVariables() override
bool IsLP() const override
bool IsMIP() const override
void SetOptimizationDirection(bool maximize) override
MPSolver::BasisStatus column_status(int variable_index) const override
int64 iterations() const override
void ClearObjective() override
The class for constraints of a Mathematical Programming (MP) model.
double offset() const
Gets the constant term in the objective.
This mathematical programming (MP) solver class is the main class though which users build and solve ...
ResultStatus
The status of solving the problem.
@ FEASIBLE
feasible, or stopped by limit.
@ NOT_SOLVED
not been solved yet.
@ INFEASIBLE
proven infeasible.
@ ABNORMAL
abnormal, i.e., error of some kind.
bool SetSolverSpecificParametersAsString(const std::string ¶meters)
Advanced usage: pass solver specific parameters in text format.
const MPObjective & Objective() const
Returns the objective object.
BasisStatus
Advanced usage: possible basis status values for a variable and the slack variable of a linear constr...
static constexpr int64 kUnknownNumberOfNodes
virtual void SetIntegerParamToUnsupportedValue(MPSolverParameters::IntegerParam param, int value)
static constexpr int64 kUnknownNumberOfIterations
void set_constraint_as_extracted(int ct_index, bool extracted)
MPSolver::ResultStatus result_status_
int last_constraint_index_
double best_objective_bound_
void ResetExtractionInformation()
bool variable_is_extracted(int var_index) const
void set_variable_as_extracted(int var_index, bool extracted)
void SetCommonParameters(const MPSolverParameters ¶m)
SynchronizationStatus sync_status_
This class stores parameter settings for LP and MIP solvers.
@ PRESOLVE
Advanced usage: presolve mode.
@ PRESOLVE_ON
Presolve is on.
@ PRESOLVE_OFF
Presolve is off.
static const int kDefaultIntegerParamValue
The class for variables of a Mathematical Programming (MP) model.
static std::unique_ptr< TimeLimit > FromParameters(const Parameters ¶meters)
Creates a time limit object initialized from an object that provides methods max_time_in_seconds() an...
ABSL_MUST_USE_RESULT BopSolveStatus SolveWithTimeLimit(const glop::LinearProgram &linear_problem, TimeLimit *time_limit)
glop::Fractional best_bound() const
glop::Fractional objective_value() const
const glop::DenseRow & variable_values() const
void SetParameters(const BopParameters ¶meters)
void SetVariableBounds(ColIndex col, Fractional lower_bound, Fractional upper_bound)
void SetObjectiveOffset(Fractional objective_offset)
void SetCoefficient(RowIndex row, ColIndex col, Fractional value)
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
ColIndex CreateNewVariable()
void SetVariableType(ColIndex col, VariableType type)
void SetObjectiveCoefficient(ColIndex col, Fractional value)
RowIndex CreateNewConstraint()
void SetMaximizationProblem(bool maximize)
void assign(IntType size, const T &v)
SharedTimeLimit * time_limit
A C++ wrapper that provides a simple and unified interface to several linear programming and mixed in...
@ FEASIBLE_SOLUTION_FOUND
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
MPSolverInterface * BuildBopInterface(MPSolver *const solver)