C++ Reference

C++ Reference: Linear solver

MPSolver

Detailed Description

This mathematical programming (MP) solver class is the main class though which users build and solve problems.

Definition at line 177 of file linear_solver.h.

Public Types

enum  OptimizationProblemType {
  GLOP_LINEAR_PROGRAMMING = 2, SCIP_MIXED_INTEGER_PROGRAMMING = 3, CBC_MIXED_INTEGER_PROGRAMMING = 5, BOP_INTEGER_PROGRAMMING = 12,
  SAT_INTEGER_PROGRAMMING = 14
}
 The type of problems (LP or MIP) that will be solved and the underlying solver (GLOP, GLPK, CLP, CBC or SCIP) that will solve them. More...
 
enum  ResultStatus {
  OPTIMAL, FEASIBLE, INFEASIBLE, UNBOUNDED,
  ABNORMAL, MODEL_INVALID, NOT_SOLVED = 6
}
 The status of solving the problem. More...
 
enum  BasisStatus {
  FREE = 0, AT_LOWER_BOUND, AT_UPPER_BOUND, FIXED_VALUE,
  BASIC
}
 Advanced usage: possible basis status values for a variable and the slack variable of a linear constraint. More...
 

Public Member Functions

 MPSolver (const std::string &name, OptimizationProblemType problem_type)
 Create a solver with the given name and underlying solver backend. More...
 
virtual ~MPSolver ()
 
bool IsMIP () const
 
const std::string & Name () const
 Returns the name of the model set at construction. More...
 
virtual OptimizationProblemType ProblemType () const
 Returns the optimization problem type set at construction. More...
 
void Clear ()
 Clears the objective (including the optimization direction), all variables and constraints. More...
 
int NumVariables () const
 Returns the number of variables. More...
 
const std::vector< MPVariable * > & variables () const
 Returns the array of variables handled by the MPSolver. More...
 
MPVariableLookupVariableOrNull (const std::string &var_name) const
 Looks up a variable by name, and returns nullptr if it does not exist. More...
 
MPVariableMakeVar (double lb, double ub, bool integer, const std::string &name)
 Creates a variable with the given bounds, integrality requirement and name. More...
 
MPVariableMakeNumVar (double lb, double ub, const std::string &name)
 Creates a continuous variable. More...
 
MPVariableMakeIntVar (double lb, double ub, const std::string &name)
 Creates an integer variable. More...
 
MPVariableMakeBoolVar (const std::string &name)
 Creates a boolean variable. More...
 
void MakeVarArray (int nb, double lb, double ub, bool integer, const std::string &name_prefix, std::vector< MPVariable * > *vars)
 Creates an array of variables. More...
 
void MakeNumVarArray (int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
 Creates an array of continuous variables. More...
 
void MakeIntVarArray (int nb, double lb, double ub, const std::string &name, std::vector< MPVariable * > *vars)
 Creates an array of integer variables. More...
 
void MakeBoolVarArray (int nb, const std::string &name, std::vector< MPVariable * > *vars)
 Creates an array of boolean variables. More...
 
int NumConstraints () const
 Returns the number of constraints. More...
 
const std::vector< MPConstraint * > & constraints () const
 Returns the array of constraints handled by the MPSolver. More...
 
MPConstraintLookupConstraintOrNull (const std::string &constraint_name) const
 Looks up a constraint by name, and returns nullptr if it does not exist. More...
 
MPConstraintMakeRowConstraint (double lb, double ub)
 Creates a linear constraint with given bounds. More...
 
MPConstraintMakeRowConstraint ()
 Creates a constraint with -infinity and +infinity bounds. More...
 
MPConstraintMakeRowConstraint (double lb, double ub, const std::string &name)
 Creates a named constraint with given bounds. More...
 
MPConstraintMakeRowConstraint (const std::string &name)
 Creates a named constraint with -infinity and +infinity bounds. More...
 
MPConstraintMakeRowConstraint (const LinearRange &range)
 Creates a constraint owned by MPSolver enforcing: range.lower_bound() <= range.linear_expr() <= range.upper_bound() More...
 
MPConstraintMakeRowConstraint (const LinearRange &range, const std::string &name)
 As above, but also names the constraint. More...
 
const MPObjectiveObjective () const
 Returns the objective object. More...
 
MPObjectiveMutableObjective ()
 Returns the mutable objective object. More...
 
ResultStatus Solve ()
 Solves the problem using the default parameter values. More...
 
ResultStatus Solve (const MPSolverParameters &param)
 Solves the problem using the specified parameter values. More...
 
void Write (const std::string &file_name)
 Writes the model using the solver internal write function. More...
 
std::vector< double > ComputeConstraintActivities () const
 Advanced usage: compute the "activities" of all constraints, which are the sums of their linear terms. More...
 
bool VerifySolution (double tolerance, bool log_errors) const
 Advanced usage: Verifies the correctness of the solution. More...
 
void Reset ()
 Advanced usage: resets extracted model to solve from scratch. More...
 
bool InterruptSolve ()
 Interrupts the Solve() execution to terminate processing if possible. More...
 
MPSolverResponseStatus LoadModelFromProto (const MPModelProto &input_model, std::string *error_message)
 Loads model from protocol buffer. More...
 
MPSolverResponseStatus LoadModelFromProtoWithUniqueNamesOrDie (const MPModelProto &input_model, std::string *error_message)
 Loads model from protocol buffer. More...
 
void FillSolutionResponseProto (MPSolutionResponse *response) const
 Encodes the current solution in a solution response protocol buffer. More...
 
void ExportModelToProto (MPModelProto *output_model) const
 Exports model to protocol buffer. More...
 
absl::Status LoadSolutionFromProto (const MPSolutionResponse &response, double tolerance=kDefaultPrimalTolerance)
 Load a solution encoded in a protocol buffer onto this solver for easy access via the MPSolver interface. More...
 
absl::Status ClampSolutionWithinBounds ()
 Resets values of out of bound variables to the corresponding bound and returns an error if any of the variables have NaN value. More...
 
bool ExportModelAsLpFormat (bool obfuscate, std::string *model_str) const
 Shortcuts to the homonymous MPModelProtoExporter methods, via exporting to a MPModelProto with ExportModelToProto() (see above). More...
 
bool ExportModelAsMpsFormat (bool fixed_format, bool obfuscate, std::string *model_str) const
 
absl::Status SetNumThreads (int num_threads)
 Sets the number of threads to use by the underlying solver. More...
 
int GetNumThreads () const
 Returns the number of threads to be used during solve. More...
 
bool SetSolverSpecificParametersAsString (const std::string &parameters)
 Advanced usage: pass solver specific parameters in text format. More...
 
std::string GetSolverSpecificParametersAsString () const
 
void SetHint (std::vector< std::pair< const MPVariable *, double > > hint)
 Sets a hint for solution. More...
 
void SetStartingLpBasis (const std::vector< MPSolver::BasisStatus > &variable_statuses, const std::vector< MPSolver::BasisStatus > &constraint_statuses)
 Advanced usage: Incrementality. More...
 
bool OutputIsEnabled () const
 Controls (or queries) the amount of output produced by the underlying solver. More...
 
void EnableOutput ()
 Enables solver logging. More...
 
void SuppressOutput ()
 Suppresses solver logging. More...
 
absl::Duration TimeLimit () const
 
void SetTimeLimit (absl::Duration time_limit)
 
absl::Duration DurationSinceConstruction () const
 
int64 iterations () const
 Returns the number of simplex iterations. More...
 
int64 nodes () const
 Returns the number of branch-and-bound nodes evaluated during the solve. More...
 
std::string SolverVersion () const
 Returns a string describing the underlying solver and its version. More...
 
void * underlying_solver ()
 Advanced usage: returns the underlying solver. More...
 
double ComputeExactConditionNumber () const
 Advanced usage: computes the exact condition number of the current scaled basis: L1norm(B) * L1norm(inverse(B)), where B is the scaled basis. More...
 
ABSL_MUST_USE_RESULT bool NextSolution ()
 Some solvers (MIP only, not LP) can produce multiple solutions to the problem. More...
 
void SetCallback (MPCallback *mp_callback)
 
bool SupportsCallbacks () const
 
int64 time_limit () const
 
void set_time_limit (int64 time_limit_milliseconds)
 
double time_limit_in_secs () const
 
int64 wall_time () const
 
bool OwnsVariable (const MPVariable *var) const
 

Static Public Member Functions

static bool SupportsProblemType (OptimizationProblemType problem_type)
 Whether the given problem type is supported (this will depend on the targets that you linked). More...
 
static bool ParseSolverType (absl::string_view solver, OptimizationProblemType *type)
 Parses the name of the solver. More...
 
static void SolveWithProto (const MPModelRequest &model_request, MPSolutionResponse *response)
 Solves the model encoded by a MPModelRequest protocol buffer and fills the solution encoded as a MPSolutionResponse. More...
 
static double infinity ()
 Infinity. More...
 

Member Enumeration Documentation

◆ BasisStatus

Advanced usage: possible basis status values for a variable and the slack variable of a linear constraint.

Enumerator
FREE 
AT_LOWER_BOUND 
AT_UPPER_BOUND 
FIXED_VALUE 
BASIC 

Definition at line 615 of file linear_solver.h.

◆ OptimizationProblemType

The type of problems (LP or MIP) that will be solved and the underlying solver (GLOP, GLPK, CLP, CBC or SCIP) that will solve them.

This must remain consistent with MPModelRequest::OptimizationProblemType (take particular care of the open-source version).

Enumerator
GLOP_LINEAR_PROGRAMMING 

Linear Programming solver using GLOP (Recommended solver).

SCIP_MIXED_INTEGER_PROGRAMMING 

Mixed integer Programming Solver using SCIP.

CBC_MIXED_INTEGER_PROGRAMMING 

Mixed integer Programming Solver using Coin CBC.

BOP_INTEGER_PROGRAMMING 

Linear Boolean Programming Solver.

SAT_INTEGER_PROGRAMMING 

SAT based solver (requires only integer and Boolean variables).

If you pass it mixed integer problems, it will scale coefficients to integer values, and solve continuous variables as integral variables.

Definition at line 185 of file linear_solver.h.

◆ ResultStatus

The status of solving the problem.

The straightforward translation to homonymous enum values of MPSolverResponseStatus (see ./linear_solver.proto) is guaranteed by ./enum_consistency_test.cc, you may rely on it.

Enumerator
OPTIMAL 

optimal.

FEASIBLE 

feasible, or stopped by limit.

INFEASIBLE 

proven infeasible.

UNBOUNDED 

proven unbounded.

ABNORMAL 

abnormal, i.e., error of some kind.

MODEL_INVALID 

the model is trivially invalid (NaN coefficients, etc).

NOT_SOLVED 

not been solved yet.

Definition at line 406 of file linear_solver.h.

Constructor & Destructor Documentation

◆ MPSolver()

MPSolver ( const std::string &  name,
OptimizationProblemType  problem_type 
)

Create a solver with the given name and underlying solver backend.

◆ ~MPSolver()

virtual ~MPSolver ( )
virtual

Member Function Documentation

◆ ClampSolutionWithinBounds()

absl::Status ClampSolutionWithinBounds ( )

Resets values of out of bound variables to the corresponding bound and returns an error if any of the variables have NaN value.

◆ Clear()

void Clear ( )

Clears the objective (including the optimization direction), all variables and constraints.

All the other properties of the MPSolver (like the time limit) are kept untouched.

◆ ComputeConstraintActivities()

std::vector<double> ComputeConstraintActivities ( ) const

Advanced usage: compute the "activities" of all constraints, which are the sums of their linear terms.

The activities are returned in the same order as constraints(), which is the order in which constraints were added; but you can also use MPConstraint::index() to get a constraint's index.

◆ ComputeExactConditionNumber()

double ComputeExactConditionNumber ( ) const

Advanced usage: computes the exact condition number of the current scaled basis: L1norm(B) * L1norm(inverse(B)), where B is the scaled basis.

This method requires that a basis exists: it should be called after Solve. It is only available for continuous problems. It is implemented for GLPK but not CLP because CLP does not provide the API for doing it.

The condition number measures how well the constraint matrix is conditioned and can be used to predict whether numerical issues will arise during the solve: the model is declared infeasible whereas it is feasible (or vice-versa), the solution obtained is not optimal or violates some constraints, the resolution is slow because of repeated singularities.

The rule of thumb to interpret the condition number kappa is:

  • o kappa <= 1e7: virtually no chance of numerical issues
  • o 1e7 < kappa <= 1e10: small chance of numerical issues
  • o 1e10 < kappa <= 1e13: medium chance of numerical issues
  • o kappa > 1e13: high chance of numerical issues

The computation of the condition number depends on the quality of the LU decomposition, so it is not very accurate when the matrix is ill conditioned.

◆ constraints()

const std::vector<MPConstraint*>& constraints ( ) const
inline

Returns the array of constraints handled by the MPSolver.

They are listed in the order in which they were created.

Definition at line 347 of file linear_solver.h.

◆ DurationSinceConstruction()

absl::Duration DurationSinceConstruction ( ) const
inline

Definition at line 667 of file linear_solver.h.

◆ EnableOutput()

void EnableOutput ( )

Enables solver logging.

◆ ExportModelAsLpFormat()

bool ExportModelAsLpFormat ( bool  obfuscate,
std::string *  model_str 
) const

Shortcuts to the homonymous MPModelProtoExporter methods, via exporting to a MPModelProto with ExportModelToProto() (see above).

Produces empty std::string on portable platforms (e.g. android, ios).

◆ ExportModelAsMpsFormat()

bool ExportModelAsMpsFormat ( bool  fixed_format,
bool  obfuscate,
std::string *  model_str 
) const

◆ ExportModelToProto()

void ExportModelToProto ( MPModelProto *  output_model) const

Exports model to protocol buffer.

◆ FillSolutionResponseProto()

void FillSolutionResponseProto ( MPSolutionResponse *  response) const

Encodes the current solution in a solution response protocol buffer.

◆ GetNumThreads()

int GetNumThreads ( ) const
inline

Returns the number of threads to be used during solve.

Definition at line 583 of file linear_solver.h.

◆ GetSolverSpecificParametersAsString()

std::string GetSolverSpecificParametersAsString ( ) const
inline

Definition at line 592 of file linear_solver.h.

◆ infinity()

static double infinity ( )
inlinestatic

Infinity.

You can use -MPSolver::infinity() for negative infinity.

Definition at line 643 of file linear_solver.h.

◆ InterruptSolve()

bool InterruptSolve ( )

Interrupts the Solve() execution to terminate processing if possible.

If the underlying interface supports interruption; it does that and returns true regardless of whether there's an ongoing Solve() or not. The Solve() call may still linger for a while depending on the conditions. If interruption is not supported; returns false and does nothing.

◆ IsMIP()

bool IsMIP ( ) const

◆ iterations()

int64 iterations ( ) const

Returns the number of simplex iterations.

◆ LoadModelFromProto()

MPSolverResponseStatus LoadModelFromProto ( const MPModelProto &  input_model,
std::string *  error_message 
)

Loads model from protocol buffer.

Returns MPSOLVER_MODEL_IS_VALID if the model is valid, and another status otherwise (currently only MPSOLVER_MODEL_INVALID and MPSOLVER_INFEASIBLE). If the model isn't valid, populates "error_message".

◆ LoadModelFromProtoWithUniqueNamesOrDie()

MPSolverResponseStatus LoadModelFromProtoWithUniqueNamesOrDie ( const MPModelProto &  input_model,
std::string *  error_message 
)

Loads model from protocol buffer.

The same as above, except that the loading keeps original variable and constraint names. Caller should make sure that all variable names and constraint names are unique, respectively.

◆ LoadSolutionFromProto()

absl::Status LoadSolutionFromProto ( const MPSolutionResponse &  response,
double  tolerance = kDefaultPrimalTolerance 
)

Load a solution encoded in a protocol buffer onto this solver for easy access via the MPSolver interface.

IMPORTANT: This may only be used in conjunction with ExportModel(), following this example:

MPSolver my_solver;
... add variables and constraints ...
MPModelProto model_proto;
my_solver.ExportModelToProto(&model_proto);
MPSolutionResponse solver_response;
MPSolver::SolveWithProto(model_proto, &solver_response);
if (solver_response.result_status() == MPSolutionResponse::OPTIMAL) {
CHECK_OK(my_solver.LoadSolutionFromProto(solver_response));
... inspect the solution using the usual API: solution_value(), etc...
}

The response must be in OPTIMAL or FEASIBLE status.

Returns a non-OK status if a problem arised (typically, if it wasn't used like it should be):

  • loading a solution whose variables don't correspond to the solver's current variables
  • loading a solution with a status other than OPTIMAL / FEASIBLE.

Note: the objective value isn't checked. You can use VerifySolution() for that.

◆ LookupConstraintOrNull()

MPConstraint* LookupConstraintOrNull ( const std::string &  constraint_name) const

Looks up a constraint by name, and returns nullptr if it does not exist.

The first call has a O(n) complexity, as the constraint name index is lazily created upon first use. Will crash if constraint names are not unique.

◆ LookupVariableOrNull()

MPVariable* LookupVariableOrNull ( const std::string &  var_name) const

Looks up a variable by name, and returns nullptr if it does not exist.

The first call has a O(n) complexity, as the variable name index is lazily created upon first use. Will crash if variable names are not unique.

◆ MakeBoolVar()

MPVariable* MakeBoolVar ( const std::string &  name)

Creates a boolean variable.

◆ MakeBoolVarArray()

void MakeBoolVarArray ( int  nb,
const std::string &  name,
std::vector< MPVariable * > *  vars 
)

Creates an array of boolean variables.

◆ MakeIntVar()

MPVariable* MakeIntVar ( double  lb,
double  ub,
const std::string &  name 
)

Creates an integer variable.

◆ MakeIntVarArray()

void MakeIntVarArray ( int  nb,
double  lb,
double  ub,
const std::string &  name,
std::vector< MPVariable * > *  vars 
)

Creates an array of integer variables.

◆ MakeNumVar()

MPVariable* MakeNumVar ( double  lb,
double  ub,
const std::string &  name 
)

Creates a continuous variable.

◆ MakeNumVarArray()

void MakeNumVarArray ( int  nb,
double  lb,
double  ub,
const std::string &  name,
std::vector< MPVariable * > *  vars 
)

Creates an array of continuous variables.

◆ MakeRowConstraint() [1/6]

MPConstraint* MakeRowConstraint ( )

Creates a constraint with -infinity and +infinity bounds.

◆ MakeRowConstraint() [2/6]

MPConstraint* MakeRowConstraint ( const LinearRange range)

Creates a constraint owned by MPSolver enforcing: range.lower_bound() <= range.linear_expr() <= range.upper_bound()

◆ MakeRowConstraint() [3/6]

MPConstraint* MakeRowConstraint ( const LinearRange range,
const std::string &  name 
)

As above, but also names the constraint.

◆ MakeRowConstraint() [4/6]

MPConstraint* MakeRowConstraint ( const std::string &  name)

Creates a named constraint with -infinity and +infinity bounds.

◆ MakeRowConstraint() [5/6]

MPConstraint* MakeRowConstraint ( double  lb,
double  ub 
)

Creates a linear constraint with given bounds.

Bounds can be finite or +/- MPSolver::infinity(). The MPSolver class assumes ownership of the constraint.

Returns
a pointer to the newly created constraint.

◆ MakeRowConstraint() [6/6]

MPConstraint* MakeRowConstraint ( double  lb,
double  ub,
const std::string &  name 
)

Creates a named constraint with given bounds.

◆ MakeVar()

MPVariable* MakeVar ( double  lb,
double  ub,
bool  integer,
const std::string &  name 
)

Creates a variable with the given bounds, integrality requirement and name.

Bounds can be finite or +/- MPSolver::infinity(). The MPSolver owns the variable (i.e. the returned pointer is borrowed). Variable names are optional. If you give an empty name, name() will auto-generate one for you upon request.

◆ MakeVarArray()

void MakeVarArray ( int  nb,
double  lb,
double  ub,
bool  integer,
const std::string &  name_prefix,
std::vector< MPVariable * > *  vars 
)

Creates an array of variables.

All variables created have the same bounds and integrality requirement. If nb <= 0, no variables are created, the function crashes in non-opt mode.

Parameters
nbthe number of variables to create.
lbthe lower bound of created variables
ubthe upper bound of created variables
integercontrols whether the created variables are continuous or integral.
name_prefixthe prefix of the variable names. Variables are named name_prefix0, name_prefix1, ...
[out]varsthe vector of variables to fill with variables.

◆ MutableObjective()

MPObjective* MutableObjective ( )
inline

Returns the mutable objective object.

Definition at line 398 of file linear_solver.h.

◆ Name()

const std::string& Name ( ) const
inline

Returns the name of the model set at construction.

Definition at line 258 of file linear_solver.h.

◆ NextSolution()

ABSL_MUST_USE_RESULT bool NextSolution ( )

Some solvers (MIP only, not LP) can produce multiple solutions to the problem.

Returns true when another solution is available, and updates the MPVariable* objects to make the new solution queryable. Call only after calling solve.

The optimality properties of the additional solutions found, and whether or not the solver computes them ahead of time or when NextSolution() is called is solver specific.

As of 2020-02-10, only Gurobi and SCIP support NextSolution(), see linear_solver_interfaces_test for an example of how to configure these solvers for multiple solutions. Other solvers return false unconditionally.

◆ nodes()

int64 nodes ( ) const

Returns the number of branch-and-bound nodes evaluated during the solve.

Only available for discrete problems.

◆ NumConstraints()

int NumConstraints ( ) const
inline

Returns the number of constraints.

Definition at line 340 of file linear_solver.h.

◆ NumVariables()

int NumVariables ( ) const
inline

Returns the number of variables.

Definition at line 275 of file linear_solver.h.

◆ Objective()

const MPObjective& Objective ( ) const
inline

Returns the objective object.

Note that the objective is owned by the solver, and is initialized to its default value (see the MPObjective class below) at construction.

Definition at line 395 of file linear_solver.h.

◆ OutputIsEnabled()

bool OutputIsEnabled ( ) const

Controls (or queries) the amount of output produced by the underlying solver.

The output can surface to LOGs, or to stdout or stderr, depending on the implementation. The amount of output will greatly vary with each implementation and each problem.

Output is suppressed by default.

◆ OwnsVariable()

bool OwnsVariable ( const MPVariable var) const

◆ ParseSolverType()

static bool ParseSolverType ( absl::string_view  solver,
OptimizationProblemType type 
)
static

Parses the name of the solver.

Returns true if the solver type is successfully parsed as one of the OptimizationProblemType.

◆ ProblemType()

virtual OptimizationProblemType ProblemType ( ) const
inlinevirtual

Returns the optimization problem type set at construction.

Definition at line 263 of file linear_solver.h.

◆ Reset()

void Reset ( )

Advanced usage: resets extracted model to solve from scratch.

This won't reset the parameters that were set with SetSolverSpecificParametersAsString() or set_time_limit() or even clear the linear program. It will just make sure that next Solve() will be as if everything was reconstructed from scratch.

◆ set_time_limit()

void set_time_limit ( int64  time_limit_milliseconds)
inline

Definition at line 757 of file linear_solver.h.

◆ SetCallback()

void SetCallback ( MPCallback *  mp_callback)

◆ SetHint()

void SetHint ( std::vector< std::pair< const MPVariable *, double > >  hint)

Sets a hint for solution.

If a feasible or almost-feasible solution to the problem is already known, it may be helpful to pass it to the solver so that it can be used. A solver that supports this feature will try to use this information to create its initial feasible solution.

Note: It may not always be faster to give a hint like this to the solver. There is also no guarantee that the solver will use this hint or try to return a solution "close" to this assignment in case of multiple optimal solutions.

◆ SetNumThreads()

absl::Status SetNumThreads ( int  num_threads)

Sets the number of threads to use by the underlying solver.

Returns OkStatus if the operation was successful. num_threads must be equal to or greater than 1. Note that the behaviour of this call depends on the underlying solver. E.g., it may set the exact number of threads or the max number of threads (check the solver's interface implementation for details). Also, some solvers may not (yet) support this function, but still enable multi-threading via SetSolverSpecificParametersAsString().

◆ SetSolverSpecificParametersAsString()

bool SetSolverSpecificParametersAsString ( const std::string &  parameters)

Advanced usage: pass solver specific parameters in text format.

The format is solver-specific and is the same as the corresponding solver configuration file format. Returns true if the operation was successful.

◆ SetStartingLpBasis()

void SetStartingLpBasis ( const std::vector< MPSolver::BasisStatus > &  variable_statuses,
const std::vector< MPSolver::BasisStatus > &  constraint_statuses 
)

Advanced usage: Incrementality.

This function takes a starting basis to be used in the next LP Solve() call. The statuses of a current solution can be retrieved via the basis_status() function of a MPVariable or a MPConstraint.

WARNING: With Glop, you should disable presolve when using this because this information will not be modified in sync with the presolve and will likely not mean much on the presolved problem.

◆ SetTimeLimit()

void SetTimeLimit ( absl::Duration  time_limit)
inline

Definition at line 662 of file linear_solver.h.

◆ Solve() [1/2]

ResultStatus Solve ( )

Solves the problem using the default parameter values.

◆ Solve() [2/2]

ResultStatus Solve ( const MPSolverParameters param)

Solves the problem using the specified parameter values.

◆ SolverVersion()

std::string SolverVersion ( ) const

Returns a string describing the underlying solver and its version.

◆ SolveWithProto()

static void SolveWithProto ( const MPModelRequest &  model_request,
MPSolutionResponse *  response 
)
static

Solves the model encoded by a MPModelRequest protocol buffer and fills the solution encoded as a MPSolutionResponse.

Note(user): This creates a temporary MPSolver and destroys it at the end. If you want to keep the MPSolver alive (for debugging, or for incremental solving), you should write another version of this function that creates the MPSolver object on the heap and returns it.

◆ SupportsCallbacks()

bool SupportsCallbacks ( ) const

◆ SupportsProblemType()

static bool SupportsProblemType ( OptimizationProblemType  problem_type)
static

Whether the given problem type is supported (this will depend on the targets that you linked).

◆ SuppressOutput()

void SuppressOutput ( )

Suppresses solver logging.

◆ time_limit()

int64 time_limit ( ) const
inline

Definition at line 752 of file linear_solver.h.

◆ time_limit_in_secs()

double time_limit_in_secs ( ) const
inline

Definition at line 762 of file linear_solver.h.

◆ TimeLimit()

absl::Duration TimeLimit ( ) const
inline

Definition at line 661 of file linear_solver.h.

◆ underlying_solver()

void* underlying_solver ( )

Advanced usage: returns the underlying solver.

Returns the underlying solver so that the user can use solver-specific features or features that are not exposed in the simple API of MPSolver. This method is for advanced users, use at your own risk! In particular, if you modify the model or the solution by accessing the underlying solver directly, then the underlying solver will be out of sync with the information kept in the wrapper (MPSolver, MPVariable, MPConstraint, MPObjective). You need to cast the void* returned back to its original type that depends on the interface (CBC: OsiClpSolverInterface*, CLP: ClpSimplex*, GLPK: glp_prob*, SCIP: SCIP*).

◆ variables()

const std::vector<MPVariable*>& variables ( ) const
inline

Returns the array of variables handled by the MPSolver.

(They are listed in the order in which they were created.)

Definition at line 281 of file linear_solver.h.

◆ VerifySolution()

bool VerifySolution ( double  tolerance,
bool  log_errors 
) const

Advanced usage: Verifies the correctness of the solution.

It verifies that all variables must be within their domains, all constraints must be satisfied, and the reported objective value must be accurate.

Usage:

  • This can only be called after Solve() was called.
  • "tolerance" is interpreted as an absolute error threshold.
  • For the objective value only, if the absolute error is too large, the tolerance is interpreted as a relative error threshold instead.
  • If "log_errors" is true, every single violation will be logged.
  • If "tolerance" is negative, it will be set to infinity().

Most users should just set the –verify_solution flag and not bother using this method directly.

◆ wall_time()

int64 wall_time ( ) const
inline

Definition at line 767 of file linear_solver.h.

◆ Write()

void Write ( const std::string &  file_name)

Writes the model using the solver internal write function.

Currently only available for Gurobi.


The documentation for this class was generated from the following file:
const std::vector< MPConstraint * > & constraints() const
Returns the array of constraints handled by the MPSolver.
MPSolver(const std::string &name, OptimizationProblemType problem_type)
Create a solver with the given name and underlying solver backend.
const std::vector< MPVariable * > & variables() const
Returns the array of variables handled by the MPSolver.
static void SolveWithProto(const MPModelRequest &model_request, MPSolutionResponse *response)
Solves the model encoded by a MPModelRequest protocol buffer and fills the solution encoded as a MPSo...