134#ifndef OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_
135#define OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_
149#include "absl/base/attributes.h"
150#include "absl/base/port.h"
151#include "absl/base/thread_annotations.h"
152#include "absl/container/flat_hash_map.h"
153#include "absl/flags/declare.h"
154#include "absl/log/check.h"
155#include "absl/status/status.h"
156#include "absl/strings/str_format.h"
157#include "absl/strings/string_view.h"
158#include "absl/time/clock.h"
159#include "absl/time/time.h"
160#include "absl/types/optional.h"
163#include "ortools/linear_solver/linear_solver.pb.h"
302 const std::string& solver_id);
307 const std::string&
Name()
const {
313 return problem_type_;
330 const std::vector<MPVariable*>&
variables()
const {
return variables_; }
351 MPVariable*
MakeVar(
double lb,
double ub,
bool integer,
352 const std::string&
name);
355 MPVariable*
MakeNumVar(
double lb,
double ub,
const std::string&
name);
358 MPVariable*
MakeIntVar(
double lb,
double ub,
const std::string&
name);
377 void MakeVarArray(
int nb,
double lb,
double ub,
bool integer,
378 const std::string& name_prefix,
379 std::vector<MPVariable*>* vars);
383 std::vector<MPVariable*>* vars);
387 std::vector<MPVariable*>* vars);
391 std::vector<MPVariable*>* vars);
401 const std::vector<MPConstraint*>&
constraints()
const {
return constraints_; }
414 const std::string& constraint_name)
const;
431 const std::string&
name);
444 const std::string&
name);
452 const MPObjective&
Objective()
const {
return *objective_; }
490 void Write(
const std::string& file_name);
551 std::string* error_message,
552 bool clear_names =
true);
561 const MPModelProto& input_model, std::string* error_message);
586 MPSolutionResponse* response,
587 std::atomic<
bool>* interrupt =
nullptr);
600 MPSolutionResponse* response,
601 std::atomic<
bool>* interrupt =
nullptr);
606 const MPModelRequest::SolverType solver) {
610 return solver == MPModelRequest::GLOP_LINEAR_PROGRAMMING ||
611 solver == MPModelRequest::GUROBI_LINEAR_PROGRAMMING ||
612 solver == MPModelRequest::GUROBI_MIXED_INTEGER_PROGRAMMING ||
613 solver == MPModelRequest::SAT_INTEGER_PROGRAMMING ||
614 solver == MPModelRequest::PDLP_LINEAR_PROGRAMMING;
654 const MPSolutionResponse& response,
655 double tolerance = std::numeric_limits<double>::infinity());
671 std::string* model_str)
const;
696 return solver_specific_parameter_string_;
714 void SetHint(std::vector<std::pair<const MPVariable*, double> >
hint);
718 ABSL_DEPRECATED(
"Prefer MPModelRequestLoggingInfo() from solve_mp_model.h.")
720 const MPModelRequest& request);
746 const std::vector<MPSolver::BasisStatus>& variable_statuses,
747 const std::vector<MPSolver::BasisStatus>& constraint_statuses);
754 static double infinity() {
return std::numeric_limits<double>::infinity(); }
773 absl::Duration
TimeLimit()
const {
return time_limit_; }
780 return absl::Now() - construction_time_;
791 int64_t
nodes()
const;
869 return time_limit_ == absl::InfiniteDuration()
871 : absl::ToInt64Milliseconds(time_limit_);
875 ? absl::InfiniteDuration()
876 : absl::Milliseconds(time_limit_milliseconds));
879 return static_cast<double>(
time_limit()) / 1000.0;
910 int ComputeMaxConstraintSize(
int min_constraint_index,
911 int max_constraint_index)
const;
914 bool HasInfeasibleConstraints()
const;
917 bool HasIntegerVariables()
const;
920 void GenerateVariableNameIndex()
const;
923 void GenerateConstraintNameIndex()
const;
926 const std::string name_;
932 std::unique_ptr<MPSolverInterface> interface_;
935 std::vector<MPVariable*> variables_;
937 mutable std::optional<absl::flat_hash_map<std::string, int> >
938 variable_name_to_index_;
940 std::vector<bool> variable_is_extracted_;
943 std::vector<MPConstraint*> constraints_;
945 mutable std::optional<absl::flat_hash_map<std::string, int> >
946 constraint_name_to_index_;
948 std::vector<bool> constraint_is_extracted_;
951 std::unique_ptr<MPObjective> objective_;
960 std::vector<std::pair<const MPVariable*, double> > solution_hint_;
962 absl::Duration time_limit_ = absl::InfiniteDuration();
964 const absl::Time construction_time_;
967 int num_threads_ = 1;
970 std::string solver_specific_parameter_string_;
972 static absl::Mutex global_count_mutex_;
974 static int64_t global_num_variables_ ABSL_GUARDED_BY(global_count_mutex_);
975 static int64_t global_num_constraints_ ABSL_GUARDED_BY(global_count_mutex_);
978 enum ModelProtoNamesPolicy {
979 DEFAULT_CLEAR_NAMES = 0,
980 INVALID_MODEL_ON_DUPLICATE_NONEMPTY_NAMES = 1,
981 DIE_ON_DUPLICATE_NONEMPTY_NAMES = 2,
983 MPSolverResponseStatus LoadModelFromProtoInternal(
984 const MPModelProto& input_model, ModelProtoNamesPolicy name_policy,
985 bool check_model_validity, std::string* error_message);
989 return SolverTypeIsMip(
static_cast<MPModelRequest::SolverType
>(solver_type));
998 return os <<
ToString(optimization_problem_type);
1001inline std::ostream&
operator<<(std::ostream& os,
1003 return os << ProtoEnumToString<MPSolverResponseStatus>(
1004 static_cast<MPSolverResponseStatus
>(
status));
1009 std::string* error);
1051 const absl::flat_hash_map<const MPVariable*, double>&
terms()
const {
1052 return coefficients_;
1059 double offset()
const {
return offset_; }
1105 double Value()
const;
1139 : interface_(interface_in), coefficients_(1), offset_(0.0) {}
1144 absl::flat_hash_map<const MPVariable*, double> coefficients_;
1159 const std::string&
name()
const {
return name_; }
1165 bool integer()
const {
return integer_; }
1177 int index()
const {
return index_; }
1180 double lb()
const {
return lb_; }
1183 double ub()
const {
return ub_; }
1258 solution_value_(0.0),
1260 interface_(interface_in) {}
1270 const std::string name_;
1271 double solution_value_;
1272 double reduced_cost_;
1273 int branching_priority_ = 0;
1291 const std::string&
name()
const {
return name_; }
1315 const absl::flat_hash_map<const MPVariable*, double>&
terms()
const {
1316 return coefficients_;
1320 double lb()
const {
return lb_; }
1323 double ub()
const {
return ub_; }
1335 bool is_lazy()
const {
return is_lazy_; }
1350 void set_is_lazy(
bool laziness) { is_lazy_ = laziness; }
1356 int index()
const {
return index_; }
1407 indicator_variable_(nullptr),
1409 interface_(interface_in) {}
1416 bool ContainsNewVariables();
1419 absl::flat_hash_map<const MPVariable*, double> coefficients_;
1430 const std::string name_;
1440 bool indicator_value_;
1602 double relative_mip_gap_value_;
1603 double primal_tolerance_value_;
1604 double dual_tolerance_value_;
1605 int presolve_value_;
1607 int lp_algorithm_value_;
1608 int incrementality_value_;
1613 bool lp_algorithm_is_default_;
1671 std::atomic<bool>* )
const {
1678 std::atomic<bool>* ) {
1679 LOG(DFATAL) <<
"Default implementation should never be called.";
1680 return MPSolutionResponse();
1685 virtual void Write(
const std::string& filename);
1689 virtual void Reset() = 0;
1709 LOG(ERROR) <<
"Solver doesn't support indicator constraints.";
1718 const MPVariable* variable,
double new_value,
1719 double old_value) = 0;
1741 virtual int64_t
nodes()
const = 0;
1817 const std::vector<MPSolver::BasisStatus>& ,
1818 const std::vector<MPSolver::BasisStatus>& ) {
1819 LOG(FATAL) <<
"Not supported by this solver.";
1822 virtual double infinity() {
return std::numeric_limits<double>::infinity(); }
1831 LOG(FATAL) <<
"Callbacks not supported for this solver.";
bool is_lazy() const
Advanced usage: returns true if the constraint is "lazy" (see below).
void set_dual_value(double dual_value)
void Clear()
Clears all variables and coefficients. Does not clear the bounds.
void SetCoefficient(const MPVariable *var, double coeff)
double lb() const
Returns the lower bound.
friend class SLMInterface
const absl::flat_hash_map< const MPVariable *, double > & terms() const
double ub() const
Returns the upper bound.
void SetUB(double ub)
Sets the upper bound.
void SetLB(double lb)
Sets the lower bound.
MPSolver::BasisStatus basis_status() const
MPConstraint(const MPConstraint &)=delete
This type is neither copyable nor movable.
const MPVariable * indicator_variable() const
void set_is_lazy(bool laziness)
MPConstraint & operator=(const MPConstraint &)=delete
double GetCoefficient(const MPVariable *var) const
const std::string & name() const
Returns the name of the constraint.
int index() const
Returns the index of the constraint in the MPSolver::constraints_.
void SetBounds(double lb, double ub)
Sets both the lower and upper bounds.
bool indicator_value() const
double dual_value() const
A class to express a linear objective.
void MinimizeLinearExpr(const LinearExpr &linear_expr)
Resets the current objective to minimize linear_expr.
void SetCoefficient(const MPVariable *var, double coeff)
double GetCoefficient(const MPVariable *var) const
--— MPObjective --—
void SetOffset(double value)
Sets the constant term in the objective.
MPObjective(const MPObjective &)=delete
This type is neither copyable nor movable.
const absl::flat_hash_map< const MPVariable *, double > & terms() const
friend class SLMInterface
void MaximizeLinearExpr(const LinearExpr &linear_expr)
Resets the current objective to maximize linear_expr.
bool minimization() const
Is the optimization direction set to minimize?
void SetMaximization()
Sets the optimization direction to maximize.
bool maximization() const
Is the optimization direction set to maximize?
double offset() const
Gets the constant term in the objective.
void AddLinearExpr(const LinearExpr &linear_expr)
Adds linear_expr to the current objective, does not change the direction.
void OptimizeLinearExpr(const LinearExpr &linear_expr, bool is_maximization)
friend class MPSolverInterface
void SetOptimizationDirection(bool maximize)
Sets the optimization direction (maximize: true or minimize: false).
MPObjective & operator=(const MPObjective &)=delete
void SetMinimization()
Sets the optimization direction to minimize.
void set_variable_as_extracted(int var_index, bool extracted)
virtual void AddVariable(MPVariable *var)=0
Add a variable.
MPSolver::ResultStatus result_status() const
Returns the result status of the last solve.
double best_objective_bound() const
virtual void SetCallback(MPCallback *)
See MPSolver::SetCallback() for details.
bool CheckSolutionIsSynchronized() const
virtual void SetPrimalTolerance(double value)=0
virtual void ExtractNewConstraints()=0
Extracts the constraints that have not been extracted yet.
virtual bool SupportsCallbacks() const
virtual void ClearObjective()=0
Clears the objective from all its terms.
static constexpr int64_t kUnknownNumberOfIterations
virtual void ExtractObjective()=0
Extracts the objective.
void InvalidateSolutionSynchronization()
virtual void SetRelativeMipGap(double value)=0
Sets each parameter in the underlying solver.
virtual void SetObjectiveCoefficient(const MPVariable *variable, double coefficient)=0
Changes a coefficient in the linear objective.
virtual void SetStartingLpBasis(const std::vector< MPSolver::BasisStatus > &, const std::vector< MPSolver::BasisStatus > &)
See MPSolver::SetStartingLpBasis().
void set_constraint_as_extracted(int ct_index, bool extracted)
virtual bool IsMIP() const =0
Returns true if the problem is discrete and linear.
virtual int64_t nodes() const =0
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_variable_index() const
Returns the index of the last variable extracted.
virtual void SetPresolveMode(int value)=0
int last_constraint_index_
Index in MPSolver::variables_ of last constraint extracted.
virtual MPSolver::BasisStatus column_status(int variable_index) const =0
Returns the basis status of a constraint.
virtual void SetCoefficient(MPConstraint *constraint, const MPVariable *variable, double new_value, double old_value)=0
Changes a coefficient in a constraint.
virtual std::string SolverVersion() const =0
Returns a string describing the underlying solver and its version.
virtual void SetVariableInteger(int index, bool integer)=0
Modifies integrality of an extracted variable.
virtual absl::Status SetNumThreads(int num_threads)
Sets the number of threads to be used by the solver.
virtual int64_t iterations() const =0
virtual bool InterruptSolve()
virtual void BranchingPriorityChangedForVariable(int)
virtual bool SetSolverSpecificParametersAsString(const std::string ¶meters)
static const int kDummyVariableIndex
-------— MPSolverInterface -------—
virtual void SetObjectiveOffset(double value)=0
Changes the constant term in the linear objective.
virtual void SetParameters(const MPSolverParameters ¶m)=0
Sets all parameters in the underlying solver.
virtual bool CheckSolutionExists() const
virtual bool IsContinuous() const =0
virtual void SetLpAlgorithm(int value)=0
virtual void SetUnsupportedIntegerParam(MPSolverParameters::IntegerParam param)
Sets an unsupported integer parameter.
virtual bool NextSolution()
See MPSolver::NextSolution() for contract.
bool variable_is_extracted(int var_index) const
virtual bool IsLP() const =0
Returns true if the problem is continuous and linear.
void SetUnsupportedDoubleParam(MPSolverParameters::DoubleParam param)
Sets an unsupported double parameter.
bool quiet() const
Returns the boolean indicating the verbosity of the solver output.
virtual void * underlying_solver()=0
Returns the underlying solver.
virtual bool SupportsDirectlySolveProto(std::atomic< bool > *) const
bool constraint_is_extracted(int ct_index) const
static constexpr int64_t kUnknownNumberOfNodes
virtual void ExtractNewVariables()=0
Extracts the variables that have not been extracted yet.
virtual MPSolver::ResultStatus Solve(const MPSolverParameters ¶m)=0
double objective_value() const
Returns the objective value of the best solution found so far.
void ExtractModel()
Extracts model stored in MPSolver.
double objective_value_
The value of the objective function.
double best_objective_bound_
The value of the best objective bound. Used only for MIP solvers.
void SetDoubleParamToUnsupportedValue(MPSolverParameters::DoubleParam param, double value)
Sets a supported double parameter to an unsupported value.
virtual void SetScalingMode(int value)=0
Sets the scaling mode.
bool maximize_
Optimization direction.
virtual double ComputeExactConditionNumber() const
virtual MPSolver::BasisStatus row_status(int constraint_index) const =0
Returns the basis status of a row.
virtual void AddRowConstraint(MPConstraint *ct)=0
Adds a linear constraint.
virtual MPSolutionResponse DirectlySolveProto(LazyMutableCopy< MPModelRequest >, std::atomic< bool > *)
virtual void Write(const std::string &filename)
void SetMIPParameters(const MPSolverParameters ¶m)
Sets MIP specific parameters in the underlying solver.
virtual ~MPSolverInterface()
virtual void SetDualTolerance(double value)=0
MPSolverInterface(MPSolver *solver)
virtual bool AddIndicatorConstraint(MPConstraint *const)
virtual void SetOptimizationDirection(bool maximize)=0
Sets the optimization direction (min/max).
virtual double infinity()
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.
virtual void ClearConstraint(MPConstraint *constraint)=0
Clears a constraint from all its terms.
bool CheckSolutionIsSynchronizedAndExists() const
Handy shortcut to do both checks above (it is often used).
void set_quiet(bool quiet_value)
Sets the boolean indicating the verbosity of the solver output.
MPSolver::ResultStatus result_status_
virtual void SetConstraintBounds(int index, double lb, double ub)=0
Modify bounds of an extracted variable.
SynchronizationStatus sync_status_
Indicates whether the model and the solution are synchronized.
virtual void SetVariableBounds(int index, double lb, double ub)=0
Modifies bounds of an extracted variable.
static const PresolveValues kDefaultPresolve
void ResetIntegerParam(MPSolverParameters::IntegerParam param)
static const double kDefaultDualTolerance
MPSolverParameters & operator=(const MPSolverParameters &)=delete
static const double kDefaultPrimalTolerance
For the primal and dual tolerances, choose the same default as CLP and GLPK.
DoubleParam
Enumeration of parameters that take continuous values.
@ DUAL_TOLERANCE
Advanced usage: tolerance for dual feasibility of basic solutions.
@ RELATIVE_MIP_GAP
Limit for relative MIP gap.
double GetDoubleParam(MPSolverParameters::DoubleParam param) const
Returns the value of a double parameter.
PresolveValues
For each categorical parameter, enumeration of possible values.
@ PRESOLVE_OFF
Presolve is off.
@ PRESOLVE_ON
Presolve is on.
static const double kUnknownDoubleParamValue
Placeholder value to indicate that a parameter is unknown.
static const int kUnknownIntegerParamValue
void ResetDoubleParam(MPSolverParameters::DoubleParam param)
static const int kDefaultIntegerParamValue
LpAlgorithmValues
LP algorithm to use.
@ BARRIER
Barrier algorithm.
void SetDoubleParam(MPSolverParameters::DoubleParam param, double value)
Sets a double parameter to a specific value.
IntegerParam
Enumeration of parameters that take integer or categorical values.
@ INCREMENTALITY
Advanced usage: incrementality from one solve to the next.
@ PRESOLVE
Advanced usage: presolve mode.
@ LP_ALGORITHM
Algorithm to solve linear programs.
@ SCALING
Advanced usage: enable or disable matrix scaling.
MPSolverParameters()
The constructor sets all parameters to their default value.
static const IncrementalityValues kDefaultIncrementality
IncrementalityValues
Advanced usage: Incrementality options.
@ INCREMENTALITY_OFF
Start solve from scratch.
static const double kDefaultRelativeMipGap
-------— MPSolverParameters -------—
void Reset()
Sets all parameters to their default value.
ScalingValues
Advanced usage: Scaling options.
@ 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
void SetIntegerParam(MPSolverParameters::IntegerParam param, int value)
Sets a integer parameter to a specific value.
int64_t time_limit() const
static void SolveLazyMutableRequest(LazyMutableCopy< MPModelRequest > request, MPSolutionResponse *response, std::atomic< bool > *interrupt=nullptr)
static
double time_limit_in_secs() const
int64_t iterations() const
Returns the number of simplex iterations.
int NumVariables() const
Returns the number of variables.
static MPSolver * CreateSolver(const std::string &solver_id)
void SetStartingLpBasis(const std::vector< MPSolver::BasisStatus > &variable_statuses, const std::vector< MPSolver::BasisStatus > &constraint_statuses)
MPVariable * MakeVar(double lb, double ub, bool integer, const std::string &name)
const std::vector< MPVariable * > & variables() const
MPVariable * MakeIntVar(double lb, double ub, const std::string &name)
Creates an integer variable.
int NumConstraints() const
Returns the number of constraints.
@ MODEL_INVALID
the model is trivially invalid (NaN coefficients, etc).
@ FEASIBLE
feasible, or stopped by limit.
@ NOT_SOLVED
not been solved yet.
@ INFEASIBLE
proven infeasible.
@ UNBOUNDED
proven unbounded.
@ ABNORMAL
abnormal, i.e., error of some kind.
ABSL_DEPRECATED("Prefer SolverTypeSupportsInterruption() from solve_mp_model.h.") static bool SolverTypeSupportsInterruption(const MPModelRequest
ResultStatus Solve()
Solves the problem using the default parameter values.
MPSolverResponseStatus LoadModelFromProto(const MPModelProto &input_model, std::string *error_message, bool clear_names=true)
--— Methods using protocol buffers --—
bool IsMIP() const
--— Interface shortcuts --—
bool VerifySolution(double tolerance, bool log_errors) const
void MakeVarArray(int nb, double lb, double ub, bool integer, const std::string &name_prefix, std::vector< MPVariable * > *vars)
bool ExportModelAsLpFormat(bool obfuscate, std::string *model_str) const
const MPObjective & Objective() const
void SetCallback(MPCallback *mp_callback)
@ GLPK_MIXED_INTEGER_PROGRAMMING
@ GLOP_LINEAR_PROGRAMMING
@ SCIP_MIXED_INTEGER_PROGRAMMING
Recommended default value for MIP problems.
@ CPLEX_LINEAR_PROGRAMMING
@ SAT_INTEGER_PROGRAMMING
@ XPRESS_MIXED_INTEGER_PROGRAMMING
@ CBC_MIXED_INTEGER_PROGRAMMING
@ HIGHS_MIXED_INTEGER_PROGRAMMING
@ GUROBI_MIXED_INTEGER_PROGRAMMING
@ COPT_LINEAR_PROGRAMMING
@ XPRESS_LINEAR_PROGRAMMING
@ PDLP_LINEAR_PROGRAMMING
@ COPT_MIXED_INTEGER_PROGRAMMING
@ HIGHS_LINEAR_PROGRAMMING
@ BOP_INTEGER_PROGRAMMING
@ GLPK_LINEAR_PROGRAMMING
@ CPLEX_MIXED_INTEGER_PROGRAMMING
@ KNAPSACK_MIXED_INTEGER_PROGRAMMING
Dedicated knapsack solvers.
@ GUROBI_LINEAR_PROGRAMMING
Commercial software (need license).
void SetTimeLimit(absl::Duration time_limit)
MPSolverResponseStatus LoadModelFromProtoWithUniqueNamesOrDie(const MPModelProto &input_model, std::string *error_message)
bool SetSolverSpecificParametersAsString(const std::string ¶meters)
MPVariable * MakeBoolVar(const std::string &name)
Creates a boolean variable.
virtual OptimizationProblemType ProblemType() const
Returns the optimization problem type set at construction.
ABSL_MUST_USE_RESULT bool NextSolution()
static bool SupportsProblemType(OptimizationProblemType problem_type)
static
friend class SLMInterface
void MakeIntVarArray(int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of integer variables.
double ComputeExactConditionNumber() const
std::string GetSolverSpecificParametersAsString() const
absl::Duration DurationSinceConstruction() const
absl::Status SetNumThreads(int num_threads)
-— Solver-specific parameters -—
MPVariable * variable(int index) const
absl::Status ClampSolutionWithinBounds()
bool OwnsVariable(const MPVariable *var) const
Debugging: verify that the given MPVariable* belongs to this solver.
void MakeNumVarArray(int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of continuous variables.
std::vector< double > ComputeConstraintActivities() const
int GetNumThreads() const
Returns the number of threads to be used during solve.
bool SupportsCallbacks() const
void FillSolutionResponseProto(MPSolutionResponse *response) const
Encodes the current solution in a solution response protocol buffer.
int64_t wall_time() const
void ExportModelToProto(MPModelProto *output_model) const
Exports model to protocol buffer.
static std::string GetMPModelRequestLoggingInfo(const MPModelRequest &request)
static
MPConstraint * MakeRowConstraint()
Creates a constraint with -infinity and +infinity bounds.
const std::vector< MPConstraint * > & constraints() const
MPObjective * MutableObjective()
Returns the mutable objective object.
bool OutputIsEnabled() const
static OptimizationProblemType ParseSolverTypeOrDie(const std::string &solver_id)
absl::Status LoadSolutionFromProto(const MPSolutionResponse &response, double tolerance=std::numeric_limits< double >::infinity())
absl::Duration TimeLimit() const
MPVariable * MakeNumVar(double lb, double ub, const std::string &name)
Creates a continuous variable.
MPSolver(const std::string &name, OptimizationProblemType problem_type)
Create a solver with the given name and underlying solver backend.
MPConstraint * LookupConstraintOrNull(const std::string &constraint_name) const
MPConstraint * constraint(int index) const
void EnableOutput()
Enables solver logging.
static int64_t global_num_variables()
static
MPSolver & operator=(const MPSolver &)=delete
void SetHint(std::vector< std::pair< const MPVariable *, double > > hint)
void SuppressOutput()
Suppresses solver logging.
void * underlying_solver()
MPVariable * LookupVariableOrNull(const std::string &var_name) const
void Write(const std::string &file_name)
static int64_t global_num_constraints()
static
const std::string & Name() const
Returns the name of the model set at construction.
bool ExportModelAsMpsFormat(bool fixed_format, bool obfuscate, std::string *model_str) const
static bool ParseSolverType(absl::string_view solver_id, OptimizationProblemType *type)
static
static void SolveWithProto(const MPModelRequest &model_request, MPSolutionResponse *response, std::atomic< bool > *interrupt=nullptr)
static
std::string SolverVersion() const
Returns a string describing the underlying solver and its version.
void MakeBoolVarArray(int nb, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of boolean variables.
void set_time_limit(int64_t time_limit_milliseconds)
The class for variables of a Mathematical Programming (MP) model.
double reduced_cost() const
void SetInteger(bool integer)
Sets the integrality requirement of the variable.
bool integer() const
Returns the integrality requirement of the variable.
void SetBranchingPriority(int priority)
void SetLB(double lb)
Sets the lower bound.
double lb() const
Returns the lower bound.
double ub() const
Returns the upper bound.
MPVariable(const MPVariable &)=delete
This type is neither copyable nor movable.
void SetUB(double ub)
Sets the upper bound.
void SetBounds(double lb, double ub)
Sets both the lower and upper bounds.
const std::string & name() const
Returns the name of the variable.
friend class SLMInterface
MPVariable & operator=(const MPVariable &)=delete
int branching_priority() const
void set_reduced_cost(double reduced_cost)
friend class MPVariableSolutionValueTest
void set_solution_value(double value)
double solution_value() const
--— MPVariable --—
MPSolver::BasisStatus basis_status() const
int index() const
Returns the index of the variable in the MPSolver::variables_.
double unrounded_solution_value() const
const std::string name
A name for logging purposes.
MPSolver::OptimizationProblemType problem_type
ABSL_DECLARE_FLAG(bool, linear_solver_enable_verbose_output)
std::optional< ModelSolveParameters::SolutionHint > hint
In SWIG mode, we don't want anything besides these top-level includes.
constexpr double kDefaultPrimalTolerance
MPSolutionResponse SolveMPModel(LazyMutableCopy< MPModelRequest > request, const SolveInterrupter *interrupter)
bool SolverTypeSupportsInterruption(const MPModelRequest::SolverType solver)
bool MPSolverResponseStatusIsRpcError(MPSolverResponseStatus status)
bool SolverTypeIsMip(MPModelRequest::SolverType solver_type)
There is a homonymous version taking a MPSolver::OptimizationProblemType.
std::ostream & operator<<(std::ostream &out, const Assignment &assignment)
bool AbslParseFlag(const absl::string_view text, MPSolver::OptimizationProblemType *solver_type, std::string *error)
absl::string_view ToString(MPSolver::OptimizationProblemType optimization_problem_type)
std::string AbslUnparseFlag(MPSolver::OptimizationProblemType solver_type)
const std::optional< Range > & range