23#include "absl/base/attributes.h"
24#include "absl/log/check.h"
27#include "ortools/glop/parameters.pb.h"
54 std::atomic<bool>* interrupt)
override {
59 void Reset()
override;
67 double new_value,
double old_value)
override;
76 int64_t
nodes()
const override;
82 bool IsLP()
const override;
83 bool IsMIP()
const override;
93 const std::vector<MPSolver::BasisStatus>& variable_statuses,
94 const std::vector<MPSolver::BasisStatus>& constraint_statuses)
override;
107 void NonIncrementalChange();
111 std::vector<MPSolver::BasisStatus> column_status_;
112 std::vector<MPSolver::BasisStatus> row_status_;
113 glop::GlopParameters parameters_;
114 std::atomic<bool> interrupt_solver_;
124 interrupt_solver_(false) {}
132 linear_program_.
Clear();
133 interrupt_solver_ =
false;
143 parameters_.set_max_time_in_seconds(
148 solver_->solver_specific_parameter_string_);
152 time_limit->RegisterExternalBooleanAsLimit(&interrupt_solver_);
161 const int num_vars =
solver_->variables_.size();
163 for (
int var_id = 0; var_id < num_vars; ++var_id) {
165 const glop::ColIndex lp_solver_var_id(
var->index());
169 var->set_solution_value(
static_cast<double>(solution_value));
173 var->set_reduced_cost(
static_cast<double>(reduced_cost));
180 const int num_constraints =
solver_->constraints_.size();
182 for (
int ct_id = 0; ct_id < num_constraints; ++ct_id) {
184 const glop::RowIndex lp_solver_ct_id(
ct->index());
188 ct->set_dual_value(
static_cast<double>(dual_value));
199 interrupt_solver_ =
true;
210 NonIncrementalChange();
214 NonIncrementalChange();
218 LOG(WARNING) <<
"Glop doesn't deal with integer variables.";
222 NonIncrementalChange();
226 NonIncrementalChange();
230 NonIncrementalChange();
235 double new_value,
double old_value) {
236 NonIncrementalChange();
240 NonIncrementalChange();
245 NonIncrementalChange();
257 LOG(DFATAL) <<
"Number of nodes only available for discrete problems";
266 return column_status_[variable_index];
285 const glop::ColIndex num_cols(
solver_->variables_.size());
289 DCHECK_EQ(new_col,
col);
298 const glop::RowIndex num_rows(
solver_->constraints_.size());
299 for (glop::RowIndex
row(0);
row < num_rows; ++
row) {
303 const double lb =
ct->lb();
304 const double ub =
ct->ub();
306 DCHECK_EQ(new_row,
row);
309 for (
const auto& entry :
ct->coefficients_) {
310 const int var_index = entry.first->index();
313 const double coeff = entry.second;
321 for (
const auto& entry :
solver_->objective_->coefficients_) {
322 const int var_index = entry.first->index();
324 const double coeff = entry.second;
330 const std::vector<MPSolver::BasisStatus>& variable_statuses,
331 const std::vector<MPSolver::BasisStatus>& constraint_statuses) {
340 lp_solver_.
SetInitialBasis(glop_variable_statuses, glop_constraint_statuses);
345 parameters_.set_log_search_progress(!
quiet_);
379 parameters_.set_use_preprocessing(
false);
382 parameters_.set_use_preprocessing(
true);
394 parameters_.set_use_scaling(
false);
397 parameters_.set_use_scaling(
true);
409 parameters_.set_use_dual_simplex(
true);
412 parameters_.set_use_dual_simplex(
false);
435void GLOPInterface::NonIncrementalChange() {
int64_t nodes() const override
void SetParameters(const MPSolverParameters ¶m) override
Sets all parameters in the underlying solver.
void SetRelativeMipGap(double value) override
Sets each parameter in the underlying solver.
void ExtractNewConstraints() override
Extracts the constraints that have not been extracted yet.
void SetCoefficient(MPConstraint *constraint, const MPVariable *variable, double new_value, double old_value) override
Changes a coefficient in a constraint.
bool IsMIP() const override
Returns true if the problem is discrete and linear.
void ExtractNewVariables() override
Extracts the variables that have not been extracted yet.
bool InterruptSolve() override
bool IsContinuous() const override
--— Misc --—
void SetVariableInteger(int index, bool integer) override
Modifies integrality of an extracted variable.
GLOPInterface(MPSolver *solver)
bool SetSolverSpecificParametersAsString(const std::string ¶meters) override
MPSolutionResponse DirectlySolveProto(LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt) override
void SetObjectiveOffset(double value) override
Changes the constant term in the linear objective.
void Reset() override
--— Model modifications and extraction --—
void ClearConstraint(MPConstraint *constraint) override
Clears a constraint from all its terms.
void SetPrimalTolerance(double value) override
void * underlying_solver() override
Returns the underlying solver.
void AddRowConstraint(MPConstraint *ct) override
Adds a linear constraint.
void ExtractObjective() override
Extracts the objective.
void SetObjectiveCoefficient(const MPVariable *variable, double coefficient) override
Changes a coefficient in the linear objective.
MPSolver::ResultStatus Solve(const MPSolverParameters ¶m) override
--— Solve --—
void ClearObjective() override
Clears the objective from all its terms.
~GLOPInterface() override
MPSolver::BasisStatus row_status(int constraint_index) const override
Returns the basis status of a row.
int64_t iterations() const override
---— Query statistics on the solution and the solve ---—
MPSolver::BasisStatus column_status(int variable_index) const override
Returns the basis status of a constraint.
void SetConstraintBounds(int index, double lb, double ub) override
Modify bounds of an extracted variable.
bool IsLP() const override
Returns true if the problem is continuous and linear.
void SetOptimizationDirection(bool maximize) override
Sets the optimization direction (min/max).
void SetDualTolerance(double value) override
void SetStartingLpBasis(const std::vector< MPSolver::BasisStatus > &variable_statuses, const std::vector< MPSolver::BasisStatus > &constraint_statuses) override
See MPSolver::SetStartingLpBasis().
void SetVariableBounds(int index, double lb, double ub) override
Modifies bounds of an extracted variable.
std::string SolverVersion() const override
Returns a string describing the underlying solver and its version.
void SetPresolveMode(int value) override
void AddVariable(MPVariable *var) override
Add a variable.
void SetScalingMode(int value) override
Sets the scaling mode.
void SetLpAlgorithm(int value) override
bool SupportsDirectlySolveProto(std::atomic< bool > *interrupt) const override
--— Directly solve proto is supported —
double offset() const
Gets the constant term in the objective.
void set_variable_as_extracted(int var_index, bool extracted)
void set_constraint_as_extracted(int ct_index, bool extracted)
void ResetExtractionInformation()
Resets the extraction information.
int last_variable_index_
Index in MPSolver::constraints_ of last variable extracted.
virtual void SetIntegerParamToUnsupportedValue(MPSolverParameters::IntegerParam param, int value)
Sets a supported integer parameter to an unsupported value.
int last_constraint_index_
Index in MPSolver::variables_ of last constraint extracted.
bool variable_is_extracted(int var_index) const
static constexpr int64_t kUnknownNumberOfNodes
void ExtractModel()
Extracts model stored in MPSolver.
double objective_value_
The value of the objective function.
void SetDoubleParamToUnsupportedValue(MPSolverParameters::DoubleParam param, double value)
Sets a supported double parameter to an unsupported value.
bool maximize_
Optimization direction.
bool quiet_
Boolean indicator for the verbosity of the solver output.
void SetCommonParameters(const MPSolverParameters ¶m)
Sets parameters common to LP and MIP in the underlying solver.
MPSolver::ResultStatus result_status_
SynchronizationStatus sync_status_
Indicates whether the model and the solution are synchronized.
@ DUAL_TOLERANCE
Advanced usage: tolerance for dual feasibility of basic solutions.
@ RELATIVE_MIP_GAP
Limit for relative MIP gap.
@ PRESOLVE_OFF
Presolve is off.
@ PRESOLVE_ON
Presolve is on.
static const int kDefaultIntegerParamValue
@ PRESOLVE
Advanced usage: presolve mode.
@ LP_ALGORITHM
Algorithm to solve linear programs.
@ SCALING
Advanced usage: enable or disable matrix scaling.
@ SCALING_ON
Scaling is on.
@ SCALING_OFF
Scaling is off.
int GetIntegerParam(MPSolverParameters::IntegerParam param) const
Returns the value of an integer parameter.
static const double kDefaultDoubleParamValue
int64_t time_limit() const
const MPObjective & Objective() const
bool SetSolverSpecificParametersAsString(const std::string ¶meters)
The class for variables of a Mathematical Programming (MP) model.
static std::unique_ptr< TimeLimit > FromParameters(const Parameters ¶meters)
A full-fledged linear programming solver.
const GlopParameters & GetParameters() const
static std::string GlopVersion()
Returns a string that describes the version of the solver.
const DenseRow & reduced_costs() const
void SetInitialBasis(const VariableStatusRow &variable_statuses, const ConstraintStatusColumn &constraint_statuses)
int GetNumberOfSimplexIterations() const
Returns the number of simplex iterations used by the last Solve().
Fractional GetObjectiveValue() const
Returns the objective value of the solution with its offset and scaling.
const ConstraintStatusColumn & constraint_statuses() const
const VariableStatusRow & variable_statuses() const
const DenseRow & variable_values() const
Accessors to information related to variables.
ABSL_MUST_USE_RESULT ProblemStatus SolveWithTimeLimit(const LinearProgram &lp, TimeLimit *time_limit)
const DenseColumn & dual_values() const
void SetParameters(const GlopParameters ¶meters)
void Clear()
Clears, i.e. reset the object to its initial value.
void SetObjectiveOffset(Fractional objective_offset)
void SetObjectiveCoefficient(ColIndex col, Fractional value)
void SetVariableBounds(ColIndex col, Fractional lower_bound, Fractional upper_bound)
void SetConstraintBounds(RowIndex row, Fractional lower_bound, Fractional upper_bound)
void SetCoefficient(RowIndex row, ColIndex col, Fractional value)
Defines the coefficient for col / row.
RowIndex CreateNewConstraint()
ColIndex CreateNewVariable()
void SetMaximizationProblem(bool maximize)
void push_back(const value_type &val)
ProblemStatus
Different statuses for a given problem.
In SWIG mode, we don't want anything besides these top-level includes.
MPSolver::ResultStatus GlopToMPSolverResultStatus(glop::ProblemStatus s)
glop::VariableStatus MPSolverToGlopVariableStatus(MPSolver::BasisStatus s)
glop::ConstraintStatus MPSolverToGlopConstraintStatus(MPSolver::BasisStatus s)
MPSolutionResponse GlopSolveProto(LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt_solve, std::function< void(const std::string &)> logging_callback)
bool ProtobufTextFormatMergeFromString(absl::string_view proto_text_string, ProtoType *proto)
MPSolver::BasisStatus GlopToMPSolverConstraintStatus(glop::ConstraintStatus s)
MPSolver::BasisStatus GlopToMPSolverVariableStatus(glop::VariableStatus s)
MPSolverInterface * BuildGLOPInterface(MPSolver *const solver)
Register GLOP in the global linear solver factory.