Google OR-Tools: ortools/linear_solver/highs_interface.cc Source File
21#include "absl/base/attributes.h"
23#include "absl/status/status.h"
24#include "absl/status/statusor.h"
25#include "absl/strings/str_cat.h"
48 std::atomic<bool>* interrupt) override {
49 DCHECK_EQ(interrupt, nullptr);
50 const bool log_error = request->enable_internal_solver_output();
56 void Reset() override;
64 double new_value, double old_value) override;
67 double coefficient) override;
73 int64_t nodes() const override;
79 bool IsLP() const override;
80 bool IsMIP() const override;
97 const std::string& parameters) override;
98 absl::Status SetNumThreads(int num_threads) override;
101 void NonIncrementalChange();
103 const bool solve_as_a_mip_;
118 for (int i = 0; i < solver_->variables_.size(); ++i) {
121 for (int i = 0; i < solver_->constraints_.size(); ++i) {
126 solver_->ExportModelToProto(&model_proto);
128 *request.mutable_model() = std::move(model_proto);
136 solver_->solver_specific_parameter_string_);
137 if (solver_->time_limit()) {
139 static_cast<double>(solver_->time_limit()) / 1000.0);
144 absl::StatusOr<MPSolutionResponse> response =
148 LOG(ERROR) << "Unexpected error solving with Highs: " << response.status();
158 const absl::Status result = solver_->LoadSolutionFromProto(*response);
160 LOG(ERROR) << "LoadSolutionFromProto failed: " << result;
222 QCHECK(solve_info_.has_value())
223 << "Number of nodes only available after solve";
263 return absl::InvalidArgumentError(
264 absl::StrCat("Invalid number of threads: ", num_threads));
284void HighsInterface::NonIncrementalChange() {
292const void* const kRegisterHighsLp ABSL_ATTRIBUTE_UNUSED = [] {
294 [](MPSolver* solver) { return new HighsInterface(solver, false); },
300const void* const kRegisterHighsMip ABSL_ATTRIBUTE_UNUSED = [] {
Definition highs_interface.cc:35
MPSolver::BasisStatus row_status(int constraint_index) const override
Definition highs_interface.cc:227
void SetConstraintBounds(int index, double lb, double ub) override
Definition highs_interface.cc:184
absl::Status SetNumThreads(int num_threads) override
Definition highs_interface.cc:261
int64_t nodes() const override
Definition highs_interface.cc:221
bool IsContinuous() const override
Definition highs_interface.cc:239
void AddVariable(MPVariable *var) override
Definition highs_interface.cc:192
void SetObjectiveCoefficient(const MPVariable *variable, double coefficient) override
Definition highs_interface.cc:206
bool IsMIP() const override
Definition highs_interface.cc:243
bool SupportsDirectlySolveProto(std::atomic< bool > *interrupt) const override
Definition highs_interface.cc:44
bool IsLP() const override
Definition highs_interface.cc:241
MPSolver::ResultStatus Solve(const MPSolverParameters ¶m) override
Definition highs_interface.cc:112
void SetCoefficient(MPConstraint *constraint, const MPVariable *variable, double new_value, double old_value) override
Definition highs_interface.cc:196
MPSolutionResponse DirectlySolveProto(LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt) override
Definition highs_interface.cc:47
bool SetSolverSpecificParametersAsString(const std::string ¶meters) override
Definition highs_interface.cc:278
int64_t iterations() const override
Definition highs_interface.cc:217
void SetPresolveMode(int value) override
Definition highs_interface.cc:276
void SetVariableInteger(int index, bool integer) override
Definition highs_interface.cc:180
void SetScalingMode(int value) override
Definition highs_interface.cc:273
void SetVariableBounds(int index, double lb, double ub) override
Definition highs_interface.cc:176
void * underlying_solver() override
Definition highs_interface.cc:249
std::string SolverVersion() const override
Definition highs_interface.cc:245
MPSolver::BasisStatus column_status(int variable_index) const override
Definition highs_interface.cc:233
void SetDualTolerance(double value) override
Definition highs_interface.cc:272
void SetRelativeMipGap(double value) override
Definition highs_interface.cc:275
void ClearObjective() override
Definition highs_interface.cc:215
HighsInterface(MPSolver *solver, bool solve_as_a_mip)
Definition highs_interface.cc:107
void SetParameters(const MPSolverParameters ¶m) override
Definition highs_interface.cc:257
~HighsInterface() override
Definition highs_interface.cc:110
void Reset() override
Definition highs_interface.cc:167
void ExtractNewVariables() override
Definition highs_interface.cc:251
void AddRowConstraint(MPConstraint *ct) override
Definition highs_interface.cc:188
void SetOptimizationDirection(bool maximize) override
Definition highs_interface.cc:172
void SetPrimalTolerance(double value) override
Definition highs_interface.cc:271
void ClearConstraint(MPConstraint *constraint) override
Definition highs_interface.cc:202
void ExtractObjective() override
Definition highs_interface.cc:255
void ExtractNewConstraints() override
Definition highs_interface.cc:253
void SetLpAlgorithm(int value) override
Definition highs_interface.cc:274
void SetObjectiveOffset(double value) override
Definition highs_interface.cc:211
void set_enable_internal_solver_output(bool value)
void set_solver_specific_parameters(Arg_ &&arg, Args_... args)
static constexpr SolverType HIGHS_LINEAR_PROGRAMMING
static constexpr SolverType HIGHS_MIXED_INTEGER_PROGRAMMING
::operations_research::MPModelProto *PROTOBUF_NONNULL mutable_model()
void set_solver_type(::operations_research::MPModelRequest_SolverType value)
void set_solver_time_limit_seconds(double value)
static MPSolverInterfaceFactoryRepository * GetInstance()
void Register(MPSolverInterfaceFactory factory, MPSolver::OptimizationProblemType problem_type, std::function< bool()> is_runtime_ready={})
void set_variable_as_extracted(int var_index, bool extracted)
friend class MPConstraint
void set_constraint_as_extracted(int ct_index, bool extracted)
void ResetExtractionInformation()
MPSolverInterface(MPSolver *solver)
void SetCommonParameters(const MPSolverParameters ¶m)
MPSolver::ResultStatus result_status_
SynchronizationStatus sync_status_
@ ABNORMAL
abnormal, i.e., error of some kind.
@ HIGHS_MIXED_INTEGER_PROGRAMMING
@ HIGHS_LINEAR_PROGRAMMING
The class for variables of a Mathematical Programming (MP) model.
absl::StatusOr< MPSolutionResponse > HighsSolveProto(LazyMutableCopy< MPModelRequest > request, HighsSolveInfo *solve_info)
MPSolutionResponse ConvertStatusOrMPSolutionResponse(bool log_error, absl::StatusOr< MPSolutionResponse > response)