 |
OR-Tools
8.0
|
Go to the documentation of this file.
18 #include "google/protobuf/text_format.h"
35 case bop::BopSolveStatus::FEASIBLE_SOLUTION_FOUND:
37 case bop::BopSolveStatus::NO_SOLUTION_FOUND:
39 case bop::BopSolveStatus::INFEASIBLE_PROBLEM:
44 LOG(DFATAL) <<
"Invalid bop::BopSolveStatus";
59 void Reset()
override;
67 const MPVariable*
const variable,
double new_value,
68 double old_value)
override;
84 bool IsLP()
const override;
85 bool IsMIP()
const override;
106 void NonIncrementalChange();
110 std::vector<MPSolver::BasisStatus> column_status_;
111 std::vector<MPSolver::BasisStatus> row_status_;
112 bop::BopParameters parameters_;
113 double best_objective_bound_;
114 std::atomic<bool> interrupt_solver_;
124 interrupt_solver_(false) {}
130 if (interrupt_solver_) {
146 parameters_.set_max_time_in_seconds(
149 parameters_.set_log_search_progress(!
quiet());
152 if (!
solver_->solution_hint_.empty()) {
153 const int num_vars =
solver_->variables_.size();
154 if (
solver_->solution_hint_.size() != num_vars) {
155 LOG(WARNING) <<
"Bop currently doesn't handle partial solution hints. "
156 <<
"Filling the missing positions with zeros...";
159 for (
const std::pair<const MPVariable*, double>& p :
161 initial_solution[glop::ColIndex(p.first->index())] =
167 solver_->solver_specific_parameter_string_);
171 time_limit->RegisterExternalBooleanAsLimit(&interrupt_solver_);
173 initial_solution.
empty()
185 best_objective_bound_ = bop_solver_.
best_bound();
188 const size_t num_vars =
solver_->variables_.size();
190 for (
int var_id = 0; var_id < num_vars; ++var_id) {
192 const glop::ColIndex lp_solver_var_id(
var->index());
195 var->set_solution_value(
static_cast<double>(solution_value));
199 const size_t num_constraints =
solver_->constraints_.size();
208 linear_program_.
Clear();
209 interrupt_solver_ =
false;
213 NonIncrementalChange();
217 NonIncrementalChange();
221 NonIncrementalChange();
225 NonIncrementalChange();
229 NonIncrementalChange();
233 NonIncrementalChange();
238 double new_value,
double old_value) {
239 NonIncrementalChange();
243 NonIncrementalChange();
248 NonIncrementalChange();
256 LOG(DFATAL) <<
"Number of iterations not available";
261 LOG(DFATAL) <<
"Number of nodes not available";
269 return best_objective_bound_;
273 return row_status_[constraint_index];
277 return column_status_[variable_index];
290 interrupt_solver_ =
true;
301 const glop::ColIndex num_cols(
solver_->variables_.size());
305 DCHECK_EQ(new_col,
col);
308 if (
var->integer()) {
319 const glop::RowIndex num_rows(
solver_->constraints_.size());
320 for (glop::RowIndex
row(0);
row < num_rows; ++
row) {
324 const double lb =
ct->lb();
325 const double ub =
ct->ub();
327 DCHECK_EQ(new_row,
row);
330 for (
const auto& entry :
ct->coefficients_) {
331 const int var_index = entry.first->index();
333 const glop::ColIndex
col(var_index);
334 const double coeff = entry.second;
343 for (
const auto& entry :
solver_->objective_->coefficients_) {
344 const int var_index = entry.first->index();
345 const glop::ColIndex
col(var_index);
346 const double coeff = entry.second;
381 google::protobuf::TextFormat::MergeFromString(
parameters, ¶meters_);
386 void BopInterface::NonIncrementalChange() {
void SetCoefficient(MPConstraint *const constraint, const MPVariable *const variable, double new_value, double old_value) override
void SetVariableInteger(int index, bool integer) override
void SetObjectiveOffset(double value) override
int64 iterations() const override
static const int kDefaultIntegerParamValue
void SetRelativeMipGap(double value) override
void SetParameters(const BopParameters ¶meters)
void ExtractNewVariables() override
void SetScalingMode(int value) override
void SetVariableType(ColIndex col, VariableType type)
double trivial_worst_objective_bound() const
const MPObjective & Objective() const
Returns the objective object.
void SetParameters(const MPSolverParameters ¶m) override
bool IsMIP() const override
int last_constraint_index_
This mathematical programming (MP) solver class is the main class though which users build and solve ...
void SetPrimalTolerance(double value) override
double best_objective_bound() const override
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
std::string SolverVersion() const override
glop::Fractional objective_value() const
void AddRowConstraint(MPConstraint *const ct) override
virtual bool CheckBestObjectiveBoundExists() const
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
double offset() const
Gets the constant term in the objective.
bool IsContinuous() const override
bool InterruptSolve() override
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...
@ ABNORMAL
abnormal, i.e., error of some kind.
void SetMaximizationProblem(bool maximize)
const glop::DenseRow & variable_values() const
This class stores parameter settings for LP and MIP solvers.
The class for constraints of a Mathematical Programming (MP) model.
MPSolverInterface * BuildBopInterface(MPSolver *const solver)
ColIndex CreateNewVariable()
RowIndex CreateNewConstraint()
@ PRESOLVE_ON
Presolve is on.
MPSolver::BasisStatus column_status(int variable_index) const override
void SetPresolveMode(int value) override
bool SetSolverSpecificParametersAsString(const std::string ¶meters) override
int64 nodes() const override
void assign(IntType size, const T &v)
void ResetExtractionInformation()
static constexpr int64 kUnknownNumberOfIterations
void * underlying_solver() override
SharedTimeLimit * time_limit
@ NOT_SOLVED
not been solved yet.
void SetVariableBounds(ColIndex col, Fractional lower_bound, Fractional upper_bound)
static constexpr int64 kUnknownNumberOfNodes
bool SetSolverSpecificParametersAsString(const std::string ¶meters)
Advanced usage: pass solver specific parameters in text format.
@ PRESOLVE
Advanced usage: presolve mode.
virtual void SetIntegerParamToUnsupportedValue(MPSolverParameters::IntegerParam param, int value)
BasisStatus
Advanced usage: possible basis status values for a variable and the slack variable of a linear constr...
void SetCoefficient(RowIndex row, ColIndex col, Fractional value)
ABSL_MUST_USE_RESULT BopSolveStatus SolveWithTimeLimit(const glop::LinearProgram &linear_problem, TimeLimit *time_limit)
SynchronizationStatus sync_status_
ResultStatus
The status of solving the problem.
bool variable_is_extracted(int var_index) const
MPSolver::BasisStatus row_status(int constraint_index) const override
BopInterface(MPSolver *const solver)
void SetObjectiveOffset(Fractional objective_offset)
void ExtractObjective() override
void SetLpAlgorithm(int value) override
void set_variable_as_extracted(int var_index, bool extracted)
void SetObjectiveCoefficient(const MPVariable *const variable, double coefficient) override
bool IsLP() const override
void SetObjectiveCoefficient(ColIndex col, Fractional value)
The class for variables of a Mathematical Programming (MP) model.
void SetVariableBounds(int index, double lb, double ub) override
A C++ wrapper that provides a simple and unified interface to several linear programming and mixed in...
void SetCommonParameters(const MPSolverParameters ¶m)
void SetConstraintBounds(int index, double lb, double ub) override
@ INFEASIBLE
proven infeasible.
void SetOptimizationDirection(bool maximize) override
void ClearConstraint(MPConstraint *const constraint) override
@ PRESOLVE_OFF
Presolve is off.
void AddVariable(MPVariable *const var) override
void SetDualTolerance(double value) override
bool CheckSolutionIsSynchronized() const
void ClearObjective() override
MPSolver::ResultStatus result_status_
void set_constraint_as_extracted(int ct_index, bool extracted)
void ExtractNewConstraints() override
MPSolver::ResultStatus Solve(const MPSolverParameters ¶m) override
@ FEASIBLE
feasible, or stopped by limit.
glop::Fractional best_bound() const