21#include "absl/base/attributes.h"
22#include "absl/status/status.h"
23#include "absl/status/statusor.h"
26#include "ortools/linear_solver/linear_solver.pb.h"
30#include "ortools/sat/cp_model.pb.h"
50 std::atomic<bool>* interrupt)
override {
55 void Reset()
override;
63 double new_value,
double old_value)
override;
74 int64_t
nodes()
const override;
80 bool IsLP()
const override;
81 bool IsMIP()
const override;
102 void NonIncrementalChange();
104 std::atomic<bool> interrupt_solve_;
105 sat::SatParameters parameters_;
106 int num_threads_ = 0;
115 interrupt_solve_ =
false;
123 solver_->solver_specific_parameter_string_);
128 parameters_.set_max_time_in_seconds(
133 for (
int i = 0; i <
solver_->variables_.size(); ++i) {
136 for (
int i = 0; i <
solver_->constraints_.size(); ++i) {
140 MPModelRequest request;
143 request.set_enable_internal_solver_output(!
quiet_);
145 const MPSolutionResponse response =
152 if (response.status() == MPSOLVER_FEASIBLE ||
153 response.status() == MPSOLVER_OPTIMAL) {
156 LOG(ERROR) <<
"LoadSolutionFromProto failed: " << result;
164 interrupt_solve_ =
true;
171 NonIncrementalChange();
175 NonIncrementalChange();
179 NonIncrementalChange();
183 NonIncrementalChange();
187 NonIncrementalChange();
191 NonIncrementalChange();
196 double new_value,
double old_value) {
197 NonIncrementalChange();
201 NonIncrementalChange();
206 NonIncrementalChange();
245 parameters_.set_num_workers(num_threads_);
250 num_threads_ = num_threads;
251 return absl::OkStatus();
269void SatInterface::NonIncrementalChange() {
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.
void ExtractModel()
Extracts model stored in MPSolver.
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.
int64_t time_limit() const
bool SetSolverSpecificParametersAsString(const std::string ¶meters)
void ExportModelToProto(MPModelProto *output_model) const
Exports model to protocol buffer.
absl::Status LoadSolutionFromProto(const MPSolutionResponse &response, double tolerance=std::numeric_limits< double >::infinity())
The class for variables of a Mathematical Programming (MP) model.
void SetRelativeMipGap(double value) override
Sets each parameter in the underlying solver.
void AddVariable(MPVariable *var) override
Add a variable.
void SetObjectiveOffset(double value) override
Changes the constant term in the linear objective.
void SetCoefficient(MPConstraint *constraint, const MPVariable *variable, double new_value, double old_value) override
Changes a coefficient in a constraint.
void SetVariableBounds(int index, double lb, double ub) override
Modifies bounds of an extracted variable.
bool SupportsDirectlySolveProto(std::atomic< bool > *interrupt) const override
--— Directly solve proto is supported —
absl::Status SetNumThreads(int num_threads) override
Sets the number of threads to be used by the solver.
void * underlying_solver() override
Returns the underlying solver.
void ExtractObjective() override
Extracts the objective.
void SetObjectiveCoefficient(const MPVariable *variable, double coefficient) override
Changes a coefficient in the linear objective.
void AddRowConstraint(MPConstraint *ct) override
Adds a linear constraint.
void Reset() override
--— Model modifications and extraction --—
MPSolver::ResultStatus Solve(const MPSolverParameters ¶m) override
--— Solve --—
void SetScalingMode(int value) override
Sets the scaling mode.
void SetVariableInteger(int index, bool integer) override
Modifies integrality of an extracted variable.
void ClearConstraint(MPConstraint *constraint) override
Clears a constraint from all its terms.
int64_t nodes() const override
void ExtractNewConstraints() override
Extracts the constraints that have not been extracted yet.
bool IsContinuous() const override
--— Misc --—
bool IsMIP() const override
Returns true if the problem is discrete and linear.
bool InterruptSolve() override
void SetPresolveMode(int value) override
std::string SolverVersion() const override
Returns a string describing the underlying solver and its version.
void SetDualTolerance(double value) override
void SetOptimizationDirection(bool maximize) override
Sets the optimization direction (min/max).
void ExtractNewVariables() override
Extracts the variables that have not been extracted yet.
bool IsLP() const override
Returns true if the problem is continuous and linear.
int64_t iterations() const override
---— Query statistics on the solution and the solve ---—
bool SetSolverSpecificParametersAsString(const std::string ¶meters) override
bool AddIndicatorConstraint(MPConstraint *const ct) override
MPSolutionResponse DirectlySolveProto(LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt) override
void SetConstraintBounds(int index, double lb, double ub) override
Modify bounds of an extracted variable.
void ClearObjective() override
Clears the objective from all its terms.
MPSolver::BasisStatus column_status(int variable_index) const override
Returns the basis status of a constraint.
void SetPrimalTolerance(double value) override
All these have no effect.
MPSolver::BasisStatus row_status(int constraint_index) const override
Returns the basis status of a row.
void SetLpAlgorithm(int value) override
void SetParameters(const MPSolverParameters ¶m) override
Sets all parameters in the underlying solver.
SatInterface(MPSolver *solver)
std::string CpSatSolverVersion()
Returns a string that describes the version of the solver.
In SWIG mode, we don't want anything besides these top-level includes.
MPSolutionResponse SatSolveProto(LazyMutableCopy< MPModelRequest > request, std::atomic< bool > *interrupt_solve, std::function< void(const std::string &)> logging_callback, std::function< void(const MPSolution &)> solution_callback)
std::string EncodeParametersAsString(const P ¶meters)
MPSolverInterface * BuildSatInterface(MPSolver *const solver)
Register Sat in the global linear solver factory.
bool ProtobufTextFormatMergeFromString(absl::string_view proto_text_string, ProtoType *proto)