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"
303 const std::string& solver_id);
308 const std::string&
Name()
const {
314 return problem_type_;
331 const std::vector<MPVariable*>&
variables()
const {
return variables_; }
353 const std::string& name);
378 void MakeVarArray(
int nb,
double lb,
double ub,
bool integer,
379 const std::string& name_prefix,
380 std::vector<MPVariable*>* vars);
383 void MakeNumVarArray(
int nb,
double lb,
double ub,
const std::string& name,
384 std::vector<MPVariable*>* vars);
387 void MakeIntVarArray(
int nb,
double lb,
double ub,
const std::string& name,
388 std::vector<MPVariable*>* vars);
392 std::vector<MPVariable*>* vars);
402 const std::vector<MPConstraint*>&
constraints()
const {
return constraints_; }
415 const std::string& constraint_name)
const;
432 const std::string& name);
445 const std::string& name);
491 void Write(
const std::string& file_name);
552 std::string* error_message,
553 bool clear_names =
true);
562 const MPModelProto& input_model, std::string* error_message);
588 std::atomic<
bool>* interrupt =
nullptr);
602 std::atomic<
bool>* interrupt =
nullptr);
605 "Prefer SolverTypeSupportsInterruption() from solve_mp_model.h.")
656 double tolerance = std::numeric_limits<double>::infinity());
672 std::string* model_str)
const;
697 return solver_specific_parameter_string_;
715 void SetHint(std::vector<std::pair<const MPVariable*, double> > hint);
719 ABSL_DEPRECATED(
"Prefer MPModelRequestLoggingInfo() from solve_mp_model.h.")
747 const std::vector<MPSolver::BasisStatus>& variable_statuses,
748 const std::vector<MPSolver::BasisStatus>& constraint_statuses);
755 static double infinity() {
return std::numeric_limits<double>::infinity(); }
774 absl::Duration
TimeLimit()
const {
return time_limit_; }
781 return absl::Now() - construction_time_;
792 int64_t
nodes()
const;
870 return time_limit_ == absl::InfiniteDuration()
872 : absl::ToInt64Milliseconds(time_limit_);
876 ? absl::InfiniteDuration()
877 : absl::Milliseconds(time_limit_milliseconds));
880 return static_cast<double>(
time_limit()) / 1000.0;
911 int ComputeMaxConstraintSize(
int min_constraint_index,
912 int max_constraint_index)
const;
915 bool HasInfeasibleConstraints()
const;
918 bool HasIntegerVariables()
const;
921 void GenerateVariableNameIndex()
const;
924 void GenerateConstraintNameIndex()
const;
927 const std::string name_;
933 std::unique_ptr<MPSolverInterface> interface_;
936 std::vector<MPVariable*> variables_;
938 mutable std::optional<absl::flat_hash_map<std::string, int> >
939 variable_name_to_index_;
941 std::vector<bool> variable_is_extracted_;
944 std::vector<MPConstraint*> constraints_;
946 mutable std::optional<absl::flat_hash_map<std::string, int> >
947 constraint_name_to_index_;
949 std::vector<bool> constraint_is_extracted_;
952 std::unique_ptr<MPObjective> objective_;
961 std::vector<std::pair<const MPVariable*, double> > solution_hint_;
963 absl::Duration time_limit_ = absl::InfiniteDuration();
965 const absl::Time construction_time_;
968 int num_threads_ = 1;
971 std::string solver_specific_parameter_string_;
973 static absl::Mutex global_count_mutex_;
975 static int64_t global_num_variables_ ABSL_GUARDED_BY(global_count_mutex_);
976 static int64_t global_num_constraints_ ABSL_GUARDED_BY(global_count_mutex_);
979 enum ModelProtoNamesPolicy {
980 DEFAULT_CLEAR_NAMES = 0,
981 INVALID_MODEL_ON_DUPLICATE_NONEMPTY_NAMES = 1,
982 DIE_ON_DUPLICATE_NONEMPTY_NAMES = 2,
985 const MPModelProto& input_model, ModelProtoNamesPolicy name_policy,
986 bool check_model_validity, std::string* error_message);
999 return os <<
ToString(optimization_problem_type);
1002inline std::ostream&
operator<<(std::ostream& os,
1004 return os << ProtoEnumToString<MPSolverResponseStatus>(
1010 std::string* error);
1052 const absl::flat_hash_map<const MPVariable*, double>&
terms()
const {
1053 return coefficients_;
1060 double offset()
const {
return offset_; }
1106 double Value()
const;
1140 : interface_(interface_in), coefficients_(1), offset_(0.0) {}
1145 absl::flat_hash_map<const MPVariable*, double> coefficients_;
1160 const std::string&
name()
const {
return name_; }
1166 bool integer()
const {
return integer_; }
1178 int index()
const {
return index_; }
1181 double lb()
const {
return lb_; }
1184 double ub()
const {
return ub_; }
1259 solution_value_(0.0),
1261 interface_(interface_in) {}
1271 const std::string name_;
1272 double solution_value_;
1273 double reduced_cost_;
1274 int branching_priority_ = 0;
1292 const std::string&
name()
const {
return name_; }
1316 const absl::flat_hash_map<const MPVariable*, double>&
terms()
const {
1317 return coefficients_;
1321 double lb()
const {
return lb_; }
1324 double ub()
const {
return ub_; }
1336 bool is_lazy()
const {
return is_lazy_; }
1351 void set_is_lazy(
bool laziness) { is_lazy_ = laziness; }
1357 int index()
const {
return index_; }
1408 indicator_variable_(nullptr),
1410 interface_(interface_in) {}
1417 bool ContainsNewVariables();
1420 absl::flat_hash_map<const MPVariable*, double> coefficients_;
1431 const std::string name_;
1441 bool indicator_value_;
1603 double relative_mip_gap_value_;
1604 double primal_tolerance_value_;
1605 double dual_tolerance_value_;
1606 int presolve_value_;
1608 int lp_algorithm_value_;
1609 int incrementality_value_;
1614 bool lp_algorithm_is_default_;
1672 std::atomic<bool>* )
const {
1679 std::atomic<bool>* ) {
1680 LOG(DFATAL) <<
"Default implementation should never be called.";
1686 virtual void Write(
const std::string& filename);
1690 virtual void Reset() = 0;
1710 LOG(ERROR) <<
"Solver doesn't support indicator constraints.";
1719 const MPVariable* variable,
double new_value,
1720 double old_value) = 0;
1727 double coefficient) = 0;
1742 virtual int64_t
nodes()
const = 0;
1783 return solver_->variable_is_extracted_[var_index];
1786 solver_->variable_is_extracted_[var_index] = extracted;
1789 return solver_->constraint_is_extracted_[ct_index];
1792 solver_->constraint_is_extracted_[ct_index] = extracted;
1818 const std::vector<MPSolver::BasisStatus>& ,
1819 const std::vector<MPSolver::BasisStatus>& ) {
1820 LOG(FATAL) <<
"Not supported by this solver.";
1823 virtual double infinity() {
return std::numeric_limits<double>::infinity(); }
1832 LOG(FATAL) <<
"Callbacks not supported for this solver.";
1918 const std::string& parameters);
bool is_lazy() const
Advanced usage: returns true if the constraint is "lazy" (see below).
friend class SCIPInterface
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
friend class CLPInterface
const absl::flat_hash_map< const MPVariable *, double > & terms() const
friend class GLOPInterface
friend class BopInterface
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.
friend class PdlpInterface
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.
friend class XpressInterface
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.
friend class MPSolverInterface
friend class GurobiInterface
friend class SatInterface
bool indicator_value() const
double dual_value() const
friend class GLPKInterface
friend class CplexInterface
friend class HighsInterface
friend class KnapsackInterface
friend class CBCInterface
MPModelRequest_SolverType SolverType
nested types -------------------------------------------------—
static constexpr SolverType SAT_INTEGER_PROGRAMMING
static constexpr SolverType GUROBI_MIXED_INTEGER_PROGRAMMING
static constexpr SolverType PDLP_LINEAR_PROGRAMMING
static constexpr SolverType GUROBI_LINEAR_PROGRAMMING
static constexpr SolverType GLOP_LINEAR_PROGRAMMING
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 --—
friend class SCIPInterface
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
friend class CLPInterface
void MaximizeLinearExpr(const LinearExpr &linear_expr)
Resets the current objective to maximize linear_expr.
friend class GLOPInterface
bool minimization() const
Is the optimization direction set to minimize?
friend class BopInterface
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.
friend class PdlpInterface
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 XpressInterface
friend class MPSolverInterface
friend class GurobiInterface
friend class SatInterface
void SetOptimizationDirection(bool maximize)
Sets the optimization direction (maximize: true or minimize: false).
friend class GLPKInterface
friend class CplexInterface
friend class HighsInterface
MPObjective & operator=(const MPObjective &)=delete
friend class KnapsackInterface
friend class CBCInterface
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.
friend class MPConstraint
To access the maximize_ bool and the MPSolver.
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 --—
friend class SCIPInterface
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
friend class GLOPInterface
absl::Status SetNumThreads(int num_threads)
-— Solver-specific parameters -—
MPVariable * variable(int index) const
friend class BopInterface
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
friend class PdlpInterface
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.
friend class XpressInterface
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.
friend class MPSolverInterface
friend class GurobiInterface
void * underlying_solver()
MPVariable * LookupVariableOrNull(const std::string &var_name) const
friend class SatInterface
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
friend class CplexInterface
friend class HighsInterface
static void SolveWithProto(const MPModelRequest &model_request, MPSolutionResponse *response, std::atomic< bool > *interrupt=nullptr)
static
friend class KnapsackInterface
std::string SolverVersion() const
Returns a string describing the underlying solver and its version.
friend class CBCInterface
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.
friend class SCIPInterface
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
friend class CLPInterface
MPVariable & operator=(const MPVariable &)=delete
friend class GLOPInterface
int branching_priority() const
friend class BopInterface
void set_reduced_cost(double reduced_cost)
friend class MPVariableSolutionValueTest
void set_solution_value(double value)
friend class PdlpInterface
double solution_value() const
--— MPVariable --—
MPSolver::BasisStatus basis_status() const
friend class XpressInterface
friend class MPSolverInterface
friend class GurobiInterface
int index() const
Returns the index of the variable in the MPSolver::variables_.
friend class SatInterface
friend class GLPKInterface
friend class CplexInterface
friend class HighsInterface
friend class KnapsackInterface
double unrounded_solution_value() const
friend class CBCInterface
OR_DLL ABSL_DECLARE_FLAG(bool, linear_solver_enable_verbose_output)
In SWIG mode, we don't want anything besides these top-level includes.
constexpr double kDefaultPrimalTolerance
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)