 |
OR-Tools
8.0
|
Go to the documentation of this file.
18 #include "google/protobuf/text_format.h"
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() {
bool variable_is_extracted(int var_index) const
MPSolver::BasisStatus row_status(int constraint_index) const override
void SetPresolveMode(int value) override
void SetOptimizationDirection(bool maximize) override
MPSolver::ResultStatus Solve(const MPSolverParameters ¶m) override
The class for variables of a Mathematical Programming (MP) model.
This mathematical programming (MP) solver class is the main class though which users build and solve ...
@ PRESOLVE_OFF
Presolve is off.
void SetVariableInteger(int index, bool integer) override
MPSolver::ResultStatus result_status_
bool IsContinuous() const override
void SetLpAlgorithm(int value) override
const glop::DenseRow & variable_values() const
The class for constraints of a Mathematical Programming (MP) model.
RowIndex CreateNewConstraint()
double best_objective_bound() const override
@ FEASIBLE
feasible, or stopped by limit.
void SetObjectiveCoefficient(ColIndex col, Fractional value)
void assign(IntType size, const T &v)
double offset() const
Gets the constant term in the objective.
void set_variable_as_extracted(int var_index, bool extracted)
void SetParameters(const BopParameters ¶meters)
BopInterface(MPSolver *const solver)
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
void SetRelativeMipGap(double value) override
glop::Fractional best_bound() const
This class stores parameter settings for LP and MIP solvers.
bool CheckSolutionIsSynchronized() const
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
void SetScalingMode(int value) override
MPSolverInterface * BuildBopInterface(MPSolver *const solver)
void SetMaximizationProblem(bool maximize)
void SetPrimalTolerance(double value) override
virtual void SetIntegerParamToUnsupportedValue(MPSolverParameters::IntegerParam param, int value)
int64 nodes() const override
bool InterruptSolve() override
void SetCommonParameters(const MPSolverParameters ¶m)
void ClearObjective() override
void SetCoefficient(RowIndex row, ColIndex col, Fractional value)
int64 iterations() const override
SharedTimeLimit * time_limit
static const int kDefaultIntegerParamValue
void set_constraint_as_extracted(int ct_index, bool extracted)
@ ABNORMAL
abnormal, i.e., error of some kind.
void ResetExtractionInformation()
static constexpr int64 kUnknownNumberOfNodes
bool SetSolverSpecificParametersAsString(const std::string ¶meters) override
void SetVariableBounds(ColIndex col, Fractional lower_bound, Fractional upper_bound)
glop::Fractional objective_value() const
void AddVariable(MPVariable *const var) override
void SetParameters(const MPSolverParameters ¶m) override
bool IsMIP() const override
void ExtractNewVariables() override
void AddRowConstraint(MPConstraint *const ct) override
@ FEASIBLE_SOLUTION_FOUND
virtual bool CheckBestObjectiveBoundExists() const
void SetObjectiveCoefficient(const MPVariable *const variable, double coefficient) override
@ PRESOLVE
Advanced usage: presolve mode.
void SetDualTolerance(double value) override
bool SetSolverSpecificParametersAsString(const std::string ¶meters)
Advanced usage: pass solver specific parameters in text format.
void * underlying_solver() override
const MPObjective & Objective() const
Returns the objective object.
ResultStatus
The status of solving the problem.
void ClearConstraint(MPConstraint *const constraint) override
void ExtractObjective() override
MPSolver::BasisStatus column_status(int variable_index) const override
void SetObjectiveOffset(double value) override
std::string SolverVersion() const override
void ExtractNewConstraints() override
BasisStatus
Advanced usage: possible basis status values for a variable and the slack variable of a linear constr...
void SetObjectiveOffset(Fractional objective_offset)
void SetConstraintBounds(int index, double lb, double ub) override
ABSL_MUST_USE_RESULT BopSolveStatus SolveWithTimeLimit(const glop::LinearProgram &linear_problem, TimeLimit *time_limit)
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...
static constexpr int64 kUnknownNumberOfIterations
ColIndex CreateNewVariable()
int last_constraint_index_
@ PRESOLVE_ON
Presolve is on.
bool IsLP() const override
double trivial_worst_objective_bound() const
void SetVariableType(ColIndex col, VariableType type)
void SetCoefficient(MPConstraint *const constraint, const MPVariable *const variable, double new_value, double old_value) override
void SetVariableBounds(int index, double lb, double ub) override
@ INFEASIBLE
proven infeasible.
SynchronizationStatus sync_status_
@ NOT_SOLVED
not been solved yet.