134 #ifndef OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_
135 #define OR_TOOLS_LINEAR_SOLVER_LINEAR_SOLVER_H_
139 #include <functional>
149 #include "absl/base/port.h"
150 #include "absl/flags/parse.h"
151 #include "absl/flags/usage.h"
152 #include "absl/status/status.h"
153 #include "absl/strings/match.h"
154 #include "absl/strings/str_format.h"
155 #include "absl/types/optional.h"
161 #include "ortools/linear_solver/linear_solver.pb.h"
288 const std::string& solver_id);
293 const std::string&
Name()
const {
299 return problem_type_;
316 const std::vector<MPVariable*>&
variables()
const {
return variables_; }
338 const std::string&
name);
363 void MakeVarArray(
int nb,
double lb,
double ub,
bool integer,
364 const std::string& name_prefix,
365 std::vector<MPVariable*>* vars);
369 std::vector<MPVariable*>* vars);
373 std::vector<MPVariable*>* vars);
377 std::vector<MPVariable*>* vars);
387 const std::vector<MPConstraint*>&
constraints()
const {
return constraints_; }
400 const std::string& constraint_name)
const;
417 const std::string&
name);
430 const std::string&
name);
476 void Write(
const std::string& file_name);
535 std::string* error_message);
544 const MPModelProto& input_model, std::string* error_message);
568 std::atomic<bool>* interrupt =
nullptr);
576 return solver == MPModelRequest::GLOP_LINEAR_PROGRAMMING ||
577 solver == MPModelRequest::GUROBI_LINEAR_PROGRAMMING ||
578 solver == MPModelRequest::GUROBI_MIXED_INTEGER_PROGRAMMING ||
579 solver == MPModelRequest::SAT_INTEGER_PROGRAMMING ||
580 solver == MPModelRequest::PDLP_LINEAR_PROGRAMMING;
621 double tolerance = std::numeric_limits<double>::infinity());
637 std::string* model_str)
const;
662 return solver_specific_parameter_string_;
680 void SetHint(std::vector<std::pair<const MPVariable*, double> > hint);
706 const std::vector<MPSolver::BasisStatus>& variable_statuses,
707 const std::vector<MPSolver::BasisStatus>& constraint_statuses);
714 static double infinity() {
return std::numeric_limits<double>::infinity(); }
732 absl::Duration
TimeLimit()
const {
return time_limit_; }
739 return absl::Now() - construction_time_;
750 int64_t
nodes()
const;
830 return time_limit_ == absl::InfiniteDuration()
832 : absl::ToInt64Milliseconds(time_limit_);
836 ? absl::InfiniteDuration()
837 : absl::Milliseconds(time_limit_milliseconds));
840 return static_cast<double>(
time_limit()) / 1000.0;
871 int ComputeMaxConstraintSize(
int min_constraint_index,
872 int max_constraint_index)
const;
875 bool HasInfeasibleConstraints()
const;
878 bool HasIntegerVariables()
const;
881 void GenerateVariableNameIndex()
const;
884 void GenerateConstraintNameIndex()
const;
887 const std::string name_;
893 std::unique_ptr<MPSolverInterface> interface_;
896 std::vector<MPVariable*> variables_;
898 mutable std::optional<absl::flat_hash_map<std::string, int> >
899 variable_name_to_index_;
901 std::vector<bool> variable_is_extracted_;
904 std::vector<MPConstraint*> constraints_;
906 mutable std::optional<absl::flat_hash_map<std::string, int> >
907 constraint_name_to_index_;
909 std::vector<bool> constraint_is_extracted_;
921 std::vector<std::pair<const MPVariable*, double> > solution_hint_;
923 absl::Duration time_limit_ = absl::InfiniteDuration();
925 const absl::Time construction_time_;
928 int num_threads_ = 1;
931 std::string solver_specific_parameter_string_;
933 static absl::Mutex global_count_mutex_;
935 static int64_t global_num_variables_ ABSL_GUARDED_BY(global_count_mutex_);
936 static int64_t global_num_constraints_ ABSL_GUARDED_BY(global_count_mutex_);
939 MPSolverResponseStatus LoadModelFromProtoInternal(
940 const MPModelProto& input_model,
bool clear_names,
941 bool check_model_validity, std::string* error_message);
956 return os <<
ToString(optimization_problem_type);
961 return os << ProtoEnumToString<MPSolverResponseStatus>(
962 static_cast<MPSolverResponseStatus
>(
status));
971 return std::string(
ToString(solver_type));
1003 const absl::flat_hash_map<const MPVariable*, double>&
terms()
const {
1004 return coefficients_;
1057 double Value()
const;
1091 : interface_(interface_in), coefficients_(1),
offset_(0.0) {}
1096 absl::flat_hash_map<const MPVariable*, double> coefficients_;
1107 const std::string&
name()
const {
return name_; }
1128 double lb()
const {
return lb_; }
1131 double ub()
const {
return ub_; }
1206 solution_value_(0.0),
1208 interface_(interface_in) {}
1218 const std::string name_;
1219 double solution_value_;
1220 double reduced_cost_;
1221 int branching_priority_ = 0;
1234 const std::string&
name()
const {
return name_; }
1258 const absl::flat_hash_map<const MPVariable*, double>&
terms()
const {
1259 return coefficients_;
1263 double lb()
const {
return lb_; }
1266 double ub()
const {
return ub_; }
1350 indicator_variable_(nullptr),
1352 interface_(interface_in) {}
1359 bool ContainsNewVariables();
1362 absl::flat_hash_map<const MPVariable*, double> coefficients_;
1373 const std::string name_;
1383 bool indicator_value_;
1540 double relative_mip_gap_value_;
1541 double primal_tolerance_value_;
1542 double dual_tolerance_value_;
1543 int presolve_value_;
1545 int lp_algorithm_value_;
1546 int incrementality_value_;
1551 bool lp_algorithm_is_default_;
1611 const MPModelRequest& request,
1614 std::atomic<bool>* interrupt) {
1615 return std::nullopt;
1620 virtual void Write(
const std::string& filename);
1644 LOG(ERROR) <<
"Solver doesn't support indicator constraints.";
1654 double new_value,
double old_value) = 0;
1717 return solver_->variable_is_extracted_[var_index];
1720 solver_->variable_is_extracted_[var_index] = extracted;
1723 return solver_->constraint_is_extracted_[ct_index];
1726 solver_->constraint_is_extracted_[ct_index] = extracted;
1752 const std::vector<MPSolver::BasisStatus>& variable_statuses,
1753 const std::vector<MPSolver::BasisStatus>& constraint_statuses) {
1754 LOG(FATAL) <<
"Not supported by this solver.";
1764 LOG(FATAL) <<
"Callbacks not supported for this solver.";
LinearExpr models a quantity that is linear in the decision variables (MPVariable) of an optimization...
An expression of the form:
The class for constraints of a Mathematical Programming (MP) model.
void SetBounds(double lb, double ub)
Sets both the lower and upper bounds.
void SetCoefficient(const MPVariable *const var, double coeff)
Sets the coefficient of the variable on the constraint.
double GetCoefficient(const MPVariable *const var) const
Gets the coefficient of a given variable on the constraint (which is 0 if the variable does not appea...
void SetUB(double ub)
Sets the upper bound.
double ub() const
Returns the upper bound.
const MPVariable * indicator_variable() const
friend class SLMInterface
const absl::flat_hash_map< const MPVariable *, double > & terms() const
Returns a map from variables to their coefficients in the constraint.
MPConstraint(int index, double lb, double ub, const std::string &name, MPSolverInterface *const interface_in)
bool indicator_value() const
void Clear()
Clears all variables and coefficients. Does not clear the bounds.
bool is_lazy() const
Advanced usage: returns true if the constraint is "lazy" (see below).
friend class XpressInterface
void set_is_lazy(bool laziness)
Advanced usage: sets the constraint "laziness".
int index() const
Returns the index of the constraint in the MPSolver::constraints_.
double lb() const
Returns the lower bound.
void set_dual_value(double dual_value)
const std::string & name() const
Returns the name of the constraint.
void SetLB(double lb)
Sets the lower bound.
friend class GLPKInterface
friend class CplexInterface
friend class HighsInterface
MPSolver::BasisStatus basis_status() const
Advanced usage: returns the basis status of the constraint.
double dual_value() const
Advanced usage: returns the dual value of the constraint in the current solution (only available for ...
A class to express a linear objective.
void SetMaximization()
Sets the optimization direction to maximize.
void SetCoefficient(const MPVariable *const var, double coeff)
Sets the coefficient of the variable in the objective.
double GetCoefficient(const MPVariable *const var) const
Gets the coefficient of a given variable in the objective.
void SetOffset(double value)
Sets the constant term in the objective.
bool maximization() const
Is the optimization direction set to maximize?
void OptimizeLinearExpr(const LinearExpr &linear_expr, bool is_maximization)
Resets the current objective to take the value of linear_expr, and sets the objective direction to ma...
friend class SLMInterface
void AddLinearExpr(const LinearExpr &linear_expr)
Adds linear_expr to the current objective, does not change the direction.
const absl::flat_hash_map< const MPVariable *, double > & terms() const
Returns a map from variables to their coefficients in the objective.
void MinimizeLinearExpr(const LinearExpr &linear_expr)
Resets the current objective to minimize linear_expr.
double Value() const
Returns the objective value of the best solution found so far.
double offset() const
Gets the constant term in the objective.
double BestBound() const
Returns the best objective bound.
bool minimization() const
Is the optimization direction set to minimize?
void Clear()
Clears the offset, all variables and coefficients, and the optimization direction.
friend class XpressInterface
void SetMinimization()
Sets the optimization direction to minimize.
void MaximizeLinearExpr(const LinearExpr &linear_expr)
Resets the current objective to maximize linear_expr.
void SetOptimizationDirection(bool maximize)
Sets the optimization direction (maximize: true or minimize: false).
friend class GLPKInterface
friend class CplexInterface
friend class HighsInterface
This mathematical programming (MP) solver class is the main class though which users build and solve ...
void FillSolutionResponseProto(MPSolutionResponse *response) const
Encodes the current solution in a solution response protocol buffer.
int NumConstraints() const
Returns the number of constraints.
static int64_t global_num_constraints()
static OptimizationProblemType ParseSolverTypeOrDie(const std::string &solver_id)
Parses the name of the solver and returns the correct optimization type or dies.
const std::string & Name() const
Returns the name of the model set at construction.
MPConstraint * constraint(int index) const
Returns the constraint at the given index.
void MakeBoolVarArray(int nb, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of boolean variables.
MPObjective * MutableObjective()
Returns the mutable objective object.
bool VerifySolution(double tolerance, bool log_errors) const
Advanced usage: Verifies the correctness of the solution.
const std::vector< MPVariable * > & variables() const
Returns the array of variables handled by the MPSolver.
absl::Duration DurationSinceConstruction() const
void Reset()
Advanced usage: resets extracted model to solve from scratch.
MPVariable * LookupVariableOrNull(const std::string &var_name) const
Looks up a variable by name, and returns nullptr if it does not exist.
int64_t iterations() const
Returns the number of simplex iterations.
void SetStartingLpBasis(const std::vector< MPSolver::BasisStatus > &variable_statuses, const std::vector< MPSolver::BasisStatus > &constraint_statuses)
Advanced usage: Incrementality.
static bool SupportsProblemType(OptimizationProblemType problem_type)
Whether the given problem type is supported (this will depend on the targets that you linked).
static MPSolver * CreateSolver(const std::string &solver_id)
Recommended factory method to create a MPSolver instance, especially in non C++ languages.
MPVariable * MakeBoolVar(const std::string &name)
Creates a boolean variable.
void SetHint(std::vector< std::pair< const MPVariable *, double > > hint)
Sets a hint for solution.
double ComputeExactConditionNumber() const
Advanced usage: computes the exact condition number of the current scaled basis: L1norm(B) * L1norm(i...
const MPObjective & Objective() const
Returns the objective object.
ResultStatus
The status of solving the problem.
@ 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.
@ MODEL_INVALID
the model is trivially invalid (NaN coefficients, etc).
friend class SLMInterface
static int64_t global_num_variables()
const std::vector< MPConstraint * > & constraints() const
Returns the array of constraints handled by the MPSolver.
int64_t wall_time() const
void MakeNumVarArray(int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of continuous variables.
void MakeVarArray(int nb, double lb, double ub, bool integer, const std::string &name_prefix, std::vector< MPVariable * > *vars)
Creates an array of variables.
void * underlying_solver()
Advanced usage: returns the underlying solver.
void set_time_limit(int64_t time_limit_milliseconds)
OptimizationProblemType
The type of problems (LP or MIP) that will be solved and the underlying solver (GLOP,...
@ GLOP_LINEAR_PROGRAMMING
@ CPLEX_MIXED_INTEGER_PROGRAMMING
@ KNAPSACK_MIXED_INTEGER_PROGRAMMING
@ XPRESS_LINEAR_PROGRAMMING
@ GLPK_LINEAR_PROGRAMMING
@ CPLEX_LINEAR_PROGRAMMING
@ GUROBI_LINEAR_PROGRAMMING
@ XPRESS_MIXED_INTEGER_PROGRAMMING
@ GUROBI_MIXED_INTEGER_PROGRAMMING
@ BOP_INTEGER_PROGRAMMING
@ SCIP_MIXED_INTEGER_PROGRAMMING
@ HIGHS_LINEAR_PROGRAMMING
@ PDLP_LINEAR_PROGRAMMING
@ SAT_INTEGER_PROGRAMMING
@ GLPK_MIXED_INTEGER_PROGRAMMING
@ CBC_MIXED_INTEGER_PROGRAMMING
@ HIGHS_MIXED_INTEGER_PROGRAMMING
bool SetSolverSpecificParametersAsString(const std::string ¶meters)
Advanced usage: pass solver specific parameters in text format.
absl::Status LoadSolutionFromProto(const MPSolutionResponse &response, double tolerance=std::numeric_limits< double >::infinity())
Load a solution encoded in a protocol buffer onto this solver for easy access via the MPSolver interf...
absl::Status SetNumThreads(int num_threads)
Sets the number of threads to use by the underlying solver.
std::string SolverVersion() const
Returns a string describing the underlying solver and its version.
bool SupportsCallbacks() const
void ExportModelToProto(MPModelProto *output_model) const
Exports model to protocol buffer.
int GetNumThreads() const
Returns the number of threads to be used during solve.
void MakeIntVarArray(int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
Creates an array of integer variables.
std::vector< double > ComputeConstraintActivities() const
Advanced usage: compute the "activities" of all constraints, which are the sums of their linear terms...
static double infinity()
Infinity.
std::string GetSolverSpecificParametersAsString() const
static bool ParseSolverType(absl::string_view solver_id, OptimizationProblemType *type)
Parses the name of the solver.
int NumVariables() const
Returns the number of variables.
absl::Status ClampSolutionWithinBounds()
Resets values of out of bound variables to the corresponding bound and returns an error if any of the...
bool OwnsVariable(const MPVariable *var) const
int64_t nodes() const
Returns the number of branch-and-bound nodes evaluated during the solve.
void Clear()
Clears the objective (including the optimization direction), all variables and constraints.
bool ExportModelAsLpFormat(bool obfuscate, std::string *model_str) const
Shortcuts to the homonymous MPModelProtoExporter methods, via exporting to a MPModelProto with Export...
void Write(const std::string &file_name)
Writes the model using the solver internal write function.
static void SolveWithProto(const MPModelRequest &model_request, MPSolutionResponse *response, std::atomic< bool > *interrupt=nullptr)
Solves the model encoded by a MPModelRequest protocol buffer and fills the solution encoded as a MPSo...
MPConstraint * MakeRowConstraint()
Creates a constraint with -infinity and +infinity bounds.
void SetCallback(MPCallback *mp_callback)
MPSolverResponseStatus LoadModelFromProto(const MPModelProto &input_model, std::string *error_message)
Loads model from protocol buffer.
bool OutputIsEnabled() const
Controls (or queries) the amount of output produced by the underlying solver.
bool ExportModelAsMpsFormat(bool fixed_format, bool obfuscate, std::string *model_str) const
ABSL_MUST_USE_RESULT bool NextSolution()
Some solvers (MIP only, not LP) can produce multiple solutions to the problem.
MPVariable * MakeVar(double lb, double ub, bool integer, const std::string &name)
Creates a variable with the given bounds, integrality requirement and name.
friend class XpressInterface
MPConstraint * LookupConstraintOrNull(const std::string &constraint_name) const
Looks up a constraint by name, and returns nullptr if it does not exist.
MPVariable * MakeNumVar(double lb, double ub, const std::string &name)
Creates a continuous variable.
int64_t time_limit() const
bool InterruptSolve()
Interrupts the Solve() execution to terminate processing if possible.
MPVariable * MakeIntVar(double lb, double ub, const std::string &name)
Creates an integer variable.
MPVariable * variable(int index) const
Returns the variable at position index.
MPSolver(const std::string &name, OptimizationProblemType problem_type)
Create a solver with the given name and underlying solver backend.
ResultStatus Solve()
Solves the problem using the default parameter values.
double time_limit_in_secs() const
void EnableOutput()
Enables solver logging.
friend class GLPKInterface
void SuppressOutput()
Suppresses solver logging.
static bool SolverTypeSupportsInterruption(const MPModelRequest::SolverType solver)
MPSolverResponseStatus LoadModelFromProtoWithUniqueNamesOrDie(const MPModelProto &input_model, std::string *error_message)
Loads model from protocol buffer.
friend class CplexInterface
friend class HighsInterface
virtual OptimizationProblemType ProblemType() const
Returns the optimization problem type set at construction.
absl::Duration TimeLimit() const
BasisStatus
Advanced usage: possible basis status values for a variable and the slack variable of a linear constr...
void SetTimeLimit(absl::Duration time_limit)
virtual ~MPSolverInterface()
double best_objective_bound() const
virtual void SetLpAlgorithm(int value)=0
virtual void SetIntegerParamToUnsupportedValue(MPSolverParameters::IntegerParam param, int value)
virtual void ExtractObjective()=0
void set_quiet(bool quiet_value)
virtual bool SupportsCallbacks() const
virtual void * underlying_solver()=0
void SetUnsupportedDoubleParam(MPSolverParameters::DoubleParam param)
virtual void ExtractNewVariables()=0
void set_constraint_as_extracted(int ct_index, bool extracted)
MPSolver::ResultStatus result_status_
virtual bool AddIndicatorConstraint(MPConstraint *const ct)
static const int kDummyVariableIndex
virtual void AddVariable(MPVariable *const var)=0
void InvalidateSolutionSynchronization()
void SetMIPParameters(const MPSolverParameters ¶m)
int last_constraint_index_
virtual bool IsContinuous() const =0
virtual double ComputeExactConditionNumber() const
virtual int64_t iterations() const =0
virtual void Write(const std::string &filename)
virtual int64_t nodes() const =0
MPSolverInterface(MPSolver *const solver)
bool constraint_is_extracted(int ct_index) const
virtual void SetVariableBounds(int index, double lb, double ub)=0
virtual void SetPrimalTolerance(double value)=0
static constexpr int64_t kUnknownNumberOfNodes
virtual void BranchingPriorityChangedForVariable(int var_index)
virtual void SetParameters(const MPSolverParameters ¶m)=0
virtual void SetRelativeMipGap(double value)=0
double best_objective_bound_
virtual void SetOptimizationDirection(bool maximize)=0
virtual bool SetSolverSpecificParametersAsString(const std::string ¶meters)
virtual MPSolver::BasisStatus column_status(int variable_index) const =0
virtual void SetScalingMode(int value)=0
virtual void ExtractNewConstraints()=0
virtual MPSolver::BasisStatus row_status(int constraint_index) const =0
virtual std::string SolverVersion() const =0
virtual absl::Status SetNumThreads(int num_threads)
double objective_value() const
int last_variable_index() const
virtual void ClearConstraint(MPConstraint *const constraint)=0
bool CheckSolutionIsSynchronizedAndExists() const
bool CheckSolutionIsSynchronized() const
virtual bool CheckSolutionExists() const
virtual void SetObjectiveOffset(double value)=0
virtual bool NextSolution()
virtual void SetStartingLpBasis(const std::vector< MPSolver::BasisStatus > &variable_statuses, const std::vector< MPSolver::BasisStatus > &constraint_statuses)
virtual void SetVariableInteger(int index, bool integer)=0
virtual void SetCallback(MPCallback *mp_callback)
void ResetExtractionInformation()
virtual void ClearObjective()=0
bool variable_is_extracted(int var_index) const
virtual bool IsMIP() const =0
virtual void SetDualTolerance(double value)=0
virtual std::optional< MPSolutionResponse > DirectlySolveProto(const MPModelRequest &request, std::atomic< bool > *interrupt)
virtual void SetPresolveMode(int value)=0
static constexpr int64_t kUnknownNumberOfIterations
virtual MPSolver::ResultStatus Solve(const MPSolverParameters ¶m)=0
MPSolver::ResultStatus result_status() const
virtual void SetUnsupportedIntegerParam(MPSolverParameters::IntegerParam param)
virtual bool InterruptSolve()
virtual void SetCoefficient(MPConstraint *const constraint, const MPVariable *const variable, double new_value, double old_value)=0
virtual void SetObjectiveCoefficient(const MPVariable *const variable, double coefficient)=0
void SetDoubleParamToUnsupportedValue(MPSolverParameters::DoubleParam param, double value)
void set_variable_as_extracted(int var_index, bool extracted)
virtual void SetConstraintBounds(int index, double lb, double ub)=0
virtual bool IsLP() const =0
void SetCommonParameters(const MPSolverParameters ¶m)
virtual void AddRowConstraint(MPConstraint *const ct)=0
SynchronizationStatus sync_status_
This class stores parameter settings for LP and MIP solvers.
static const double kDefaultRelativeMipGap
static const int kUnknownIntegerParamValue
void ResetIntegerParam(MPSolverParameters::IntegerParam param)
Sets an integer parameter to its default value (default value defined in MPSolverParameters if it exi...
void SetDoubleParam(MPSolverParameters::DoubleParam param, double value)
Sets a double parameter to a specific value.
IncrementalityValues
Advanced usage: Incrementality options.
@ INCREMENTALITY_OFF
Start solve from scratch.
@ INCREMENTALITY_ON
Reuse results from previous solve as much as the underlying solver allows.
ScalingValues
Advanced usage: Scaling options.
@ SCALING_ON
Scaling is on.
@ SCALING_OFF
Scaling is off.
static const IncrementalityValues kDefaultIncrementality
void Reset()
Sets all parameters to their default value.
DoubleParam
Enumeration of parameters that take continuous values.
@ DUAL_TOLERANCE
Advanced usage: tolerance for dual feasibility of basic solutions.
@ PRIMAL_TOLERANCE
Advanced usage: tolerance for primal feasibility of basic solutions.
@ RELATIVE_MIP_GAP
Limit for relative MIP gap.
static const PresolveValues kDefaultPresolve
double GetDoubleParam(MPSolverParameters::DoubleParam param) const
Returns the value of a double parameter.
static const double kDefaultDualTolerance
static const double kUnknownDoubleParamValue
IntegerParam
Enumeration of parameters that take integer or categorical values.
@ LP_ALGORITHM
Algorithm to solve linear programs.
@ SCALING
Advanced usage: enable or disable matrix scaling.
@ PRESOLVE
Advanced usage: presolve mode.
@ INCREMENTALITY
Advanced usage: incrementality from one solve to the next.
LpAlgorithmValues
LP algorithm to use.
@ BARRIER
Barrier algorithm.
PresolveValues
For each categorical parameter, enumeration of possible values.
@ PRESOLVE_ON
Presolve is on.
@ PRESOLVE_OFF
Presolve is off.
static const int kDefaultIntegerParamValue
static const double kDefaultPrimalTolerance
void SetIntegerParam(MPSolverParameters::IntegerParam param, int value)
Sets a integer parameter to a specific value.
static const double kDefaultDoubleParamValue
int GetIntegerParam(MPSolverParameters::IntegerParam param) const
Returns the value of an integer parameter.
MPSolverParameters()
The constructor sets all parameters to their default value.
void ResetDoubleParam(MPSolverParameters::DoubleParam param)
Sets a double parameter to its default value (default value defined in MPSolverParameters if it exist...
The class for variables of a Mathematical Programming (MP) model.
void SetBounds(double lb, double ub)
Sets both the lower and upper bounds.
double unrounded_solution_value() const
Advanced usage: unrounded solution value.
int branching_priority() const
Advanced usage: Certain MIP solvers (e.g.
void set_solution_value(double value)
void SetBranchingPriority(int priority)
void SetUB(double ub)
Sets the upper bound.
double ub() const
Returns the upper bound.
friend class SLMInterface
double reduced_cost() const
Advanced usage: returns the reduced cost of the variable in the current solution (only available for ...
friend class MPVariableSolutionValueTest
void SetInteger(bool integer)
Sets the integrality requirement of the variable.
MPVariable(int index, double lb, double ub, bool integer, const std::string &name, MPSolverInterface *const interface_in)
void set_reduced_cost(double reduced_cost)
bool integer() const
Returns the integrality requirement of the variable.
friend class XpressInterface
int index() const
Returns the index of the variable in the MPSolver::variables_.
double lb() const
Returns the lower bound.
const std::string & name() const
Returns the name of the variable.
void SetLB(double lb)
Sets the lower bound.
double solution_value() const
Returns the value of the variable in the current solution.
friend class GLPKInterface
friend class CplexInterface
friend class HighsInterface
MPSolver::BasisStatus basis_status() const
Advanced usage: returns the basis status of the variable in the current solution (only available for ...
SharedResponseManager * response
This file allows you to write natural code (like a mathematical equation) to model optimization probl...
MPSolver::OptimizationProblemType problem_type
ABSL_DECLARE_FLAG(bool, linear_solver_enable_verbose_output)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Collection of objects used to extend the Constraint Solver library.
constexpr double kDefaultPrimalTolerance
const absl::string_view ToString(MPSolver::OptimizationProblemType optimization_problem_type)
bool SolverTypeIsMip(MPModelRequest::SolverType solver_type)
std::ostream & operator<<(std::ostream &out, const Assignment &assignment)
bool AbslParseFlag(const absl::string_view text, MPSolver::OptimizationProblemType *solver_type, std::string *error)
std::string AbslUnparseFlag(MPSolver::OptimizationProblemType solver_type)
bool MPSolverResponseStatusIsRpcError(MPSolverResponseStatus status)
const std::optional< Range > & range