C++ Reference

C++ Reference: Linear solver

operations_research Namespace Reference

Classes

class  LinearExpr
 LinearExpr models a quantity that is linear in the decision variables (MPVariable) of an optimization problem, i.e. More...
 
class  LinearRange
 An expression of the form: More...
 
class  MPConstraint
 The class for constraints of a Mathematical Programming (MP) model. More...
 
struct  MPModelExportOptions
 Export options. More...
 
class  MPObjective
 A class to express a linear objective. More...
 
class  MPSolver
 This mathematical programming (MP) solver class is the main class though which users build and solve problems. More...
 
class  MPSolverInterface
 
class  MPSolverParameters
 This class stores parameter settings for LP and MIP solvers. More...
 
class  MPVariable
 The class for variables of a Mathematical Programming (MP) model. More...
 

Functions

std::ostream & operator<< (std::ostream &stream, const LinearExpr &linear_expr)
 
LinearExpr operator+ (LinearExpr lhs, const LinearExpr &rhs)
 
LinearExpr operator- (LinearExpr lhs, const LinearExpr &rhs)
 
LinearExpr operator* (LinearExpr lhs, double rhs)
 
LinearExpr operator/ (LinearExpr lhs, double rhs)
 
LinearExpr operator* (double lhs, LinearExpr rhs)
 
LinearRange operator<= (const LinearExpr &lhs, const LinearExpr &rhs)
 
LinearRange operator== (const LinearExpr &lhs, const LinearExpr &rhs)
 
LinearRange operator>= (const LinearExpr &lhs, const LinearExpr &rhs)
 
bool SolverTypeIsMip (MPModelRequest::SolverType solver_type)
 
bool SolverTypeIsMip (MPSolver::OptimizationProblemType solver_type)
 
const absl::string_view ToString (MPSolver::OptimizationProblemType optimization_problem_type)
 
std::ostream & operator<< (std::ostream &os, MPSolver::OptimizationProblemType optimization_problem_type)
 
std::ostream & operator<< (std::ostream &os, MPSolver::ResultStatus status)
 
bool AbslParseFlag (absl::string_view text, MPSolver::OptimizationProblemType *solver_type, std::string *error)
 
std::string AbslUnparseFlag (MPSolver::OptimizationProblemType solver_type)
 
bool MPSolverResponseStatusIsRpcError (MPSolverResponseStatus status)
 
absl::StatusOr< std::string > ExportModelAsLpFormat (const MPModelProto &model, const MPModelExportOptions &options=MPModelExportOptions())
 Outputs the current model (variables, constraints, objective) as a string encoded in the so-called "CPLEX LP file format" as generated by SCIP. More...
 
absl::StatusOr< std::string > ExportModelAsMpsFormat (const MPModelProto &model, const MPModelExportOptions &options=MPModelExportOptions())
 Outputs the current model (variables, constraints, objective) as a string encoded in MPS file format, using the "free" MPS format. More...
 
std::string ExportModelAsLpFormatReturnString (const MPModelProto &input_model, const MPModelExportOptions &options=MPModelExportOptions())
 
std::string ExportModelAsMpsFormatReturnString (const MPModelProto &input_model, const MPModelExportOptions &options=MPModelExportOptions())
 
std::string FindErrorInMPModelProto (const MPModelProto &model, double abs_value_threshold=0.0)
 Returns an empty string iff the model is valid and not trivially infeasible. More...
 
std::string FindErrorInMPModelDeltaProto (const MPModelDeltaProto &delta, const MPModelProto &model)
 Like FindErrorInMPModelProto, but for a MPModelDeltaProto applied to a given baseline model (assumed valid, eg. More...
 
absl::optional< LazyMutableCopy< MPModelProto > > ExtractValidMPModelOrPopulateResponseStatus (const MPModelRequest &request, MPSolutionResponse *response)
 If the model is valid and non-empty, returns it (possibly after extracting the model_delta). More...
 
bool ExtractValidMPModelInPlaceOrPopulateResponseStatus (MPModelRequest *request, MPSolutionResponse *response)
 Like ExtractValidMPModelOrPopulateResponseStatus(), but works in-place: if the MPModel needed extraction, it will be populated in the request, and it returns the success boolean. More...
 
std::string FindFeasibilityErrorInSolutionHint (const MPModelProto &model, double tolerance)
 Returns an empty string if the solution hint given in the model is a feasible solution. More...
 
void MergeMPConstraintProtoExceptTerms (const MPConstraintProto &from, MPConstraintProto *to)
 
void ApplyVerifiedMPModelDelta (const MPModelDeltaProto &delta, MPModelProto *model)
 

Variables

constexpr double kDefaultPrimalTolerance = 1e-07
 

Function Documentation

◆ AbslParseFlag()

bool AbslParseFlag ( absl::string_view  text,
MPSolver::OptimizationProblemType solver_type,
std::string *  error 
)

◆ AbslUnparseFlag()

std::string AbslUnparseFlag ( MPSolver::OptimizationProblemType  solver_type)
inline

Definition at line 920 of file linear_solver.h.

◆ ApplyVerifiedMPModelDelta()

void ApplyVerifiedMPModelDelta ( const MPModelDeltaProto &  delta,
MPModelProto *  model 
)

◆ ExportModelAsLpFormat()

absl::StatusOr< std::string > ExportModelAsLpFormat ( const MPModelProto &  model,
const MPModelExportOptions options = MPModelExportOptions() 
)

Outputs the current model (variables, constraints, objective) as a string encoded in the so-called "CPLEX LP file format" as generated by SCIP.

The LP file format is easily readable by a human.

Returns false if some error has occurred during execution. The validity of names is automatically checked. If a variable name or a constraint name is invalid or non-existent, a new valid name is automatically generated.

If 'obfuscated' is true, the variable and constraint names of proto_ are not used. Variable and constraint names of the form "V12345" and "C12345" are used instead.

For more information about the different LP file formats: http://lpsolve.sourceforge.net/5.5/lp-format.htm The following give a reasonable idea of the CPLEX LP file format: http://lpsolve.sourceforge.net/5.5/CPLEX-format.htm http://tinyurl.com/cplex-lp-format http://www.gurobi.com/documentation/5.1/reference-manual/node871

◆ ExportModelAsLpFormatReturnString()

std::string ExportModelAsLpFormatReturnString ( const MPModelProto &  input_model,
const MPModelExportOptions options = MPModelExportOptions() 
)
inline

Definition at line 24 of file model_exporter_swig_helper.h.

◆ ExportModelAsMpsFormat()

absl::StatusOr< std::string > ExportModelAsMpsFormat ( const MPModelProto &  model,
const MPModelExportOptions options = MPModelExportOptions() 
)

Outputs the current model (variables, constraints, objective) as a string encoded in MPS file format, using the "free" MPS format.

Returns false if some error has occurred during execution. Models with maximization objectives trigger an error, because MPS can encode only minimization problems.

The validity of names is automatically checked. If a variable name or a constraint name is invalid or non-existent, a new valid name is automatically generated.

Name validity and obfuscation works exactly as in ExportModelAsLpFormat().

For more information about the MPS format: http://en.wikipedia.org/wiki/MPS_(format) A close-to-original description coming from OSL: http://tinyurl.com/mps-format-by-osl A recent description from CPLEX: http://tinyurl.com/mps-format-by-cplex CPLEX extensions: http://tinyurl.com/mps-extensions-by-cplex Gurobi's description: http://www.gurobi.com/documentation/5.1/reference-manual/node869

◆ ExportModelAsMpsFormatReturnString()

std::string ExportModelAsMpsFormatReturnString ( const MPModelProto &  input_model,
const MPModelExportOptions options = MPModelExportOptions() 
)
inline

Definition at line 31 of file model_exporter_swig_helper.h.

◆ ExtractValidMPModelInPlaceOrPopulateResponseStatus()

bool ExtractValidMPModelInPlaceOrPopulateResponseStatus ( MPModelRequest *  request,
MPSolutionResponse *  response 
)

Like ExtractValidMPModelOrPopulateResponseStatus(), but works in-place: if the MPModel needed extraction, it will be populated in the request, and it returns the success boolean.

◆ ExtractValidMPModelOrPopulateResponseStatus()

absl::optional< LazyMutableCopy< MPModelProto > > ExtractValidMPModelOrPopulateResponseStatus ( const MPModelRequest &  request,
MPSolutionResponse *  response 
)

If the model is valid and non-empty, returns it (possibly after extracting the model_delta).

If invalid or empty, updates response and returns null.

◆ FindErrorInMPModelDeltaProto()

std::string FindErrorInMPModelDeltaProto ( const MPModelDeltaProto &  delta,
const MPModelProto &  model 
)

Like FindErrorInMPModelProto, but for a MPModelDeltaProto applied to a given baseline model (assumed valid, eg.

FindErrorInMPModelProto(model)=""). Works in O(|model_delta|) + O(num_vars in model), but the latter term has a very small constant factor.

◆ FindErrorInMPModelProto()

std::string FindErrorInMPModelProto ( const MPModelProto &  model,
double  abs_value_threshold = 0.0 
)

Returns an empty string iff the model is valid and not trivially infeasible.

Otherwise, returns a description of the first error or trivial infeasibility encountered.

abs_value_threshold is the (exclusive) limit for the abs value of constraint coefficients, objective coefficients, etc. If unspecified, or 0, it defaults to FLAGS_model_validator_infinity.

NOTE(user): the code of this method (and the client code too!) is considerably simplified by this string-based, simple API. If clients require it, we could add a formal error status enum.

◆ FindFeasibilityErrorInSolutionHint()

std::string FindFeasibilityErrorInSolutionHint ( const MPModelProto &  model,
double  tolerance 
)

Returns an empty string if the solution hint given in the model is a feasible solution.

Otherwise, returns a description of the first reason for infeasibility.

This function can be useful for debugging/checking that the given solution hint is feasible when it is expected to be the case. The feasibility is checked up to the given tolerance using the ::operations_research::IsLowerWithinTolerance() function.

◆ MergeMPConstraintProtoExceptTerms()

void MergeMPConstraintProtoExceptTerms ( const MPConstraintProto &  from,
MPConstraintProto *  to 
)

◆ MPSolverResponseStatusIsRpcError()

bool MPSolverResponseStatusIsRpcError ( MPSolverResponseStatus  status)

◆ operator*() [1/2]

LinearExpr operator* ( double  lhs,
LinearExpr  rhs 
)

◆ operator*() [2/2]

LinearExpr operator* ( LinearExpr  lhs,
double  rhs 
)

◆ operator+()

LinearExpr operator+ ( LinearExpr  lhs,
const LinearExpr rhs 
)

◆ operator-()

LinearExpr operator- ( LinearExpr  lhs,
const LinearExpr rhs 
)

◆ operator/()

LinearExpr operator/ ( LinearExpr  lhs,
double  rhs 
)

◆ operator<<() [1/3]

std::ostream & operator<< ( std::ostream &  os,
MPSolver::OptimizationProblemType  optimization_problem_type 
)
inline

Definition at line 904 of file linear_solver.h.

◆ operator<<() [2/3]

std::ostream & operator<< ( std::ostream &  os,
MPSolver::ResultStatus  status 
)
inline

Definition at line 910 of file linear_solver.h.

◆ operator<<() [3/3]

std::ostream & operator<< ( std::ostream &  stream,
const LinearExpr linear_expr 
)

◆ operator<=()

LinearRange operator<= ( const LinearExpr lhs,
const LinearExpr rhs 
)

◆ operator==()

LinearRange operator== ( const LinearExpr lhs,
const LinearExpr rhs 
)

◆ operator>=()

LinearRange operator>= ( const LinearExpr lhs,
const LinearExpr rhs 
)

◆ SolverTypeIsMip() [1/2]

bool SolverTypeIsMip ( MPModelRequest::SolverType  solver_type)

◆ SolverTypeIsMip() [2/2]

bool SolverTypeIsMip ( MPSolver::OptimizationProblemType  solver_type)
inline

Definition at line 897 of file linear_solver.h.

◆ ToString()

const absl::string_view ToString ( MPSolver::OptimizationProblemType  optimization_problem_type)

Variable Documentation

◆ kDefaultPrimalTolerance

constexpr double kDefaultPrimalTolerance = 1e-07
constexpr

Definition at line 165 of file linear_solver.h.