Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::math_opt Namespace Reference

An object oriented wrapper for quadratic constraints in ModelStorage. More...

Namespaces

namespace  internal
 

Classes

class  AllSolversRegistry
 
class  AtomicConstraintStorage
 
struct  AtomicConstraintTraits
 
struct  AtomicConstraintTraits< IndicatorConstraintId >
 
struct  AtomicConstraintTraits< QuadraticConstraintId >
 
struct  AtomicConstraintTraits< SecondOrderConeConstraintId >
 
struct  AtomicConstraintTraits< Sos1ConstraintId >
 
struct  AtomicConstraintTraits< Sos2ConstraintId >
 
class  BaseSolver
 
class  BaseSolverTest
 
struct  Basis
 
struct  BoundedLinearExpression
 A LinearExpression with upper and lower bounds. More...
 
struct  BoundedQuadraticExpression
 A QuadraticExpression with upper and lower bounds. More...
 
class  BranchPrioritiesTest
 
struct  BranchPrioritiesTestParams
 Parameters for the BranchPrioritiesTest suite below. More...
 
class  BufferedMessageCallback
 
struct  CallbackData
 
struct  CallbackRegistration
 
struct  CallbackResult
 The value returned by the Callback function. More...
 
class  CallbackTest
 
struct  CallbackTestParams
 Parameters for CallbackTest. More...
 
struct  ComputeInfeasibleSubsystemArguments
 Arguments passed to ComputeInfeasibleSubsystem() to control the solver. More...
 
struct  ComputeInfeasibleSubsystemResult
 
class  ConcurrentCallsGuard
 
struct  ConstantFormatter
 Streaming formatter for a constant in a linear/quadratic expression. More...
 
class  CpSatSolver
 
struct  DoubleOptions
 
struct  DualRay
 
struct  DualSolution
 
struct  Enum
 
struct  EnumProto
 
struct  FeasibilityCheckerOptions
 
class  GenericTest
 
struct  GenericTestParameters
 
class  GlopSolver
 
struct  GlpkParameters
 
struct  GlpkRay
 
class  GlpkSolver
 
class  GlpkSparseVector
 
class  GScipSolver
 
struct  GScipSolverConstraintData
 
class  GScipSolverConstraintHandler
 
class  Gurobi
 
struct  GurobiCallbackInput
 
struct  GurobiFreeEnv
 
struct  GurobiISVKey
 
struct  GurobiIsvKey
 
struct  GurobiParameters
 
class  GurobiSolver
 
class  HighsSolver
 
class  IdNameBiMap
 
class  IncrementalLogicalConstraintTest
 
class  IncrementalLpTest
 
class  IncrementalMipTest
 
class  IncrementalMultiObjectiveTest
 
class  IncrementalQcTest
 
class  IncrementalQpTest
 
class  IncrementalSecondOrderConeTest
 
class  IncrementalSolver
 
class  IndicatorConstraint
 
struct  IndicatorConstraintData
 
struct  InfeasibleSubsystemSupport
 
class  InfeasibleSubsystemTest
 
struct  InfeasibleSubsystemTestParameters
 
struct  InvalidIndicators
 
class  InvalidInputTest
 
struct  InvalidInputTestParameters
 
class  InvalidParameterTest
 
struct  InvalidParameterTestParams
 
struct  InvertedBounds
 
class  IpModelSolveParametersTest
 
class  IpMultipleSolutionsTest
 
struct  IpMultipleSolutionsTestParams
 
class  IpParameterTest
 
struct  IpParameterTestParameters
 
class  iterator_range
 
class  LargeInstanceIpParameterTest
 
struct  LargeInstanceTestParams
 
class  LazyConstraintsTest
 
struct  LazyConstraintsTestParams
 Parameters for the LazyConstraintsTest suite below. More...
 
struct  LeadingCoefficientFormatter
 
class  LinearConstraint
 
class  LinearConstraintStorage
 
class  LinearExpression
 
struct  LinearExpressionData
 
struct  LinearTerm
 A term in an sum of variables multiplied by coefficients. More...
 
struct  LogicalConstraintTestParameters
 
struct  LowerBoundedLinearExpression
 A LinearExpression with a lower bound. More...
 
struct  LowerBoundedQuadraticExpression
 A QuadraticExpression with a lower bound. More...
 
class  LpBasisStartTest
 
class  LpIncompleteSolveTest
 
struct  LpIncompleteSolveTestParams
 Parameters for the LpIncompleteSolveTest suite below. More...
 
class  LpModelSolveParametersTest
 
struct  LpModelSolveParametersTestParameters
 
class  LpParameterTest
 
struct  LpParameterTestParams
 Parameters for the LpParameterTest suite below. More...
 
struct  MapFilter
 
class  MessageCallbackData
 
class  MessageCallbackTest
 
struct  MessageCallbackTestParams
 Parameters for the MessageCallbackTest suite below. More...
 
class  MipSolutionHintTest
 
class  Model
 
struct  ModelRanges
 
struct  ModelSolveParameters
 
struct  ModelSubset
 
struct  ModelSummary
 
struct  MoveVariablesToTheirBestFeasibleValueOptions
 Options for MoveVariablesToTheirBestFeasibleValue. More...
 
struct  MultiObjectiveTestParameters
 
struct  NonStreamableGurobiInitArguments
 
struct  NonStreamableSolverInitArguments
 
struct  NonStreamableSolverInitArgumentsHelper
 
class  NonStreamableSolverInitArgumentsValue
 
struct  NontrivialInfeasibleIp
 
class  Objective
 
struct  ObjectiveBounds
 Bounds on the optimal objective value. More...
 
class  ObjectiveStorage
 In memory representation of the objective of an optimization model. More...
 
struct  ParameterSupport
 
struct  ParamName
 
class  PdlpBridge
 
class  PdlpSolver
 
struct  PrimalRay
 
struct  PrimalSolution
 
struct  ProblemStatus
 
class  QcDualsTest
 
struct  QcTestParameters
 
class  QpDualsTest
 
struct  QpTestParameters
 
class  QuadraticConstraint
 
struct  QuadraticConstraintData
 
class  QuadraticExpression
 
class  QuadraticTerm
 
class  QuadraticTermKey
 
class  SecondOrderConeConstraint
 
struct  SecondOrderConeConstraintData
 
struct  SecondOrderConeTestParameters
 
class  SimpleLogicalConstraintTest
 
class  SimpleLpTest
 
struct  SimpleLpTestParameters
 
class  SimpleMipTest
 
struct  SimpleMipTestParameters
 
class  SimpleMultiObjectiveTest
 
class  SimpleQcTest
 
class  SimpleQpTest
 
class  SimpleSecondOrderConeTest
 
struct  Solution
 
struct  SolutionHintTestParams
 Parameters for the MipSolutionHintTest suite below. More...
 
struct  SolutionMatcherOptions
 Options for IsNear(Solution). More...
 
struct  SolveArguments
 
struct  SolvedModel
 
struct  SolveParameters
 
class  Solver
 
struct  SolveResultMatcherOptions
 Configures SolveResult matcher IsConsistentWith() below. More...
 
struct  SolveResultSupport
 
struct  SolverInitArguments
 
class  SolverInterface
 
struct  SolverResources
 
struct  SolveStats
 
class  Sos1Constraint
 
class  Sos2Constraint
 
class  SparseCoefficientMap
 
class  SparseMatrix
 
class  SparseSymmetricMatrix
 
struct  SparseVector
 
class  SparseVectorFilterPredicate
 
class  SparseVectorView
 
class  StatusTest
 
struct  StatusTestParameters
 
struct  StreamableCpSatInitArguments
 Streamable CpSat specific parameters for solver instantiation. More...
 
struct  StreamableGlopInitArguments
 Streamable Glop specific parameters for solver instantiation. More...
 
struct  StreamableGlpkInitArguments
 Streamable Glpk specific parameters for solver instantiation. More...
 
struct  StreamableGScipInitArguments
 Streamable GScip specific parameters for solver instantiation. More...
 
struct  StreamableGurobiInitArguments
 Streamable Gurobi specific parameters for solver instantiation. More...
 
struct  StreamablePdlpInitArguments
 Streamable Pdlp specific parameters for solver instantiation. More...
 
struct  StreamableSolverInitArguments
 
struct  SupportedProblemStructures
 
struct  Termination
 All information regarding why a call to Solve() terminated. More...
 
class  TimeLimitTest
 
struct  TimeLimitTestParameters
 
class  UpdateDataFieldIterator
 
struct  UpdateResult
 Result of the Update() on an incremental solver. More...
 
class  UpdateTracker
 
class  UpdateTrackers
 
struct  UpperBoundedLinearExpression
 A LinearExpression with an upper bound. More...
 
struct  UpperBoundedQuadraticExpression
 A QuadraticExpression with an upper bound. More...
 
class  Variable
 
class  VariableStorage
 

Typedefs

using Sos1ConstraintData = internal::SosConstraintData<Sos1ConstraintId>
 
using Sos2ConstraintData = internal::SosConstraintData<Sos2ConstraintId>
 
using SparseSubmatrixRowsView
 
template<typename SparseVector >
using sparse_value_type
 
using Callback = std::function<CallbackResult(const CallbackData&)>
 
using ProtoEnumIsValid = bool (*)(int)
 
template<typename V >
using LinearConstraintMap = absl::flat_hash_map<LinearConstraint, V>
 
using MockSolveFunction
 
using MessageCallback = std::function<void(const std::vector<std::string>&)>
 
template<typename V >
using ObjectiveMap = absl::flat_hash_map<Objective, V>
 
using SolveFunction
 
using Range = std::pair<double, double>
 A range of values, first is the minimum, second is the maximum.
 
template<typename V >
using VariableMap = absl::flat_hash_map<Variable, V>
 
using QuadraticProductId = std::pair<VariableId, VariableId>
 Id type used for quadratic terms, i.e. products of two variables.
 
template<typename V >
using QuadraticTermMap = absl::flat_hash_map<QuadraticTermKey, V>
 
using GRBenvUniquePtr = std::unique_ptr<GRBenv, GurobiFreeEnv>
 
using ObjectiveId = std::optional<AuxiliaryObjectiveId>
 nullopt denotes the primary objective.
 

Enumerations

enum class  SupportType { kNotSupported = 1 , kSupported = 2 , kNotImplemented = 3 }
 
enum class  BasisStatus : int8_t {
  kFree = BASIS_STATUS_FREE , kAtLowerBound = BASIS_STATUS_AT_LOWER_BOUND , kAtUpperBound = BASIS_STATUS_AT_UPPER_BOUND , kFixedValue = BASIS_STATUS_FIXED_VALUE ,
  kBasic = BASIS_STATUS_BASIC
}
 Status of a variable/constraint in a LP basis. More...
 
enum class  CallbackEvent {
  kPresolve = CALLBACK_EVENT_PRESOLVE , kSimplex = CALLBACK_EVENT_SIMPLEX , kMip = CALLBACK_EVENT_MIP , kMipSolution = CALLBACK_EVENT_MIP_SOLUTION ,
  kMipNode = CALLBACK_EVENT_MIP_NODE , kBarrier = CALLBACK_EVENT_BARRIER
}
 The supported events during a solve for callbacks. More...
 
enum class  SolverType {
  kGscip = SOLVER_TYPE_GSCIP , kGurobi = SOLVER_TYPE_GUROBI , kGlop = SOLVER_TYPE_GLOP , kCpSat = SOLVER_TYPE_CP_SAT ,
  kPdlp = SOLVER_TYPE_PDLP , kGlpk = SOLVER_TYPE_GLPK , kEcos = SOLVER_TYPE_ECOS , kScs = SOLVER_TYPE_SCS ,
  kHighs = SOLVER_TYPE_HIGHS , kSantorini = SOLVER_TYPE_SANTORINI
}
 The solvers supported by MathOpt. More...
 
enum class  LPAlgorithm { kPrimalSimplex = LP_ALGORITHM_PRIMAL_SIMPLEX , kDualSimplex = LP_ALGORITHM_DUAL_SIMPLEX , kBarrier = LP_ALGORITHM_BARRIER , kFirstOrder = LP_ALGORITHM_FIRST_ORDER }
 Selects an algorithm for solving linear programs. More...
 
enum class  Emphasis {
  kOff = EMPHASIS_OFF , kLow = EMPHASIS_LOW , kMedium = EMPHASIS_MEDIUM , kHigh = EMPHASIS_HIGH ,
  kVeryHigh = EMPHASIS_VERY_HIGH
}
 never give an error, and will map onto their best match. More...
 
enum class  SolutionStatus { kUndetermined = SOLUTION_STATUS_UNDETERMINED , kFeasible = SOLUTION_STATUS_FEASIBLE , kInfeasible = SOLUTION_STATUS_INFEASIBLE }
 Feasibility of a primal or dual solution as claimed by the solver. More...
 
enum class  FeasibilityStatus { kUndetermined = FEASIBILITY_STATUS_UNDETERMINED , kFeasible = FEASIBILITY_STATUS_FEASIBLE , kInfeasible = FEASIBILITY_STATUS_INFEASIBLE }
 
enum class  TerminationReason {
  kOptimal = TERMINATION_REASON_OPTIMAL , kInfeasible = TERMINATION_REASON_INFEASIBLE , kUnbounded = TERMINATION_REASON_UNBOUNDED , kInfeasibleOrUnbounded = TERMINATION_REASON_INFEASIBLE_OR_UNBOUNDED ,
  kImprecise = TERMINATION_REASON_IMPRECISE , kFeasible = TERMINATION_REASON_FEASIBLE , kNoSolutionFound = TERMINATION_REASON_NO_SOLUTION_FOUND , kNumericalError = TERMINATION_REASON_NUMERICAL_ERROR ,
  kOtherError = TERMINATION_REASON_OTHER_ERROR
}
 The reason a call to Solve() terminates. More...
 
enum class  Limit {
  kUndetermined = LIMIT_UNDETERMINED , kIteration = LIMIT_ITERATION , kTime = LIMIT_TIME , kNode = LIMIT_NODE ,
  kSolution = LIMIT_SOLUTION , kMemory = LIMIT_MEMORY , kCutoff = LIMIT_CUTOFF , kObjective = LIMIT_OBJECTIVE ,
  kNorm = LIMIT_NORM , kInterrupted = LIMIT_INTERRUPTED , kSlowProgress = LIMIT_SLOW_PROGRESS , kOther = LIMIT_OTHER
}
 
enum class  QpSupportType { kNoQpSupport , kDiagonalQpOnly , kConvexQp }
 
enum  GlpkRayType { kPrimal , kDual }
 The type of the GlpkRay. More...
 

Functions

absl::StatusOr< GRBenv * > NewPrimaryEnvFromISVKey (const GurobiIsvKey &isv_key)
 
std::ostream & operator<< (std::ostream &ostr, const IndicatorConstraint &constraint)
 
bool operator== (const IndicatorConstraint &lhs, const IndicatorConstraint &rhs)
 
bool operator!= (const IndicatorConstraint &lhs, const IndicatorConstraint &rhs)
 
template<typename H >
AbslHashValue (H h, const IndicatorConstraint &constraint)
 
absl::Status ValidateConstraint (const IndicatorConstraintProto &constraint, const IdNameBiMap &variable_universe)
 
std::ostream & operator<< (std::ostream &ostr, const QuadraticConstraint &constraint)
 
bool operator== (const QuadraticConstraint &lhs, const QuadraticConstraint &rhs)
 
bool operator!= (const QuadraticConstraint &lhs, const QuadraticConstraint &rhs)
 
template<typename H >
AbslHashValue (H h, const QuadraticConstraint &quadratic_constraint)
 
absl::Status ValidateConstraint (const QuadraticConstraintProto &constraint, const IdNameBiMap &variable_universe)
 
std::ostream & operator<< (std::ostream &ostr, const SecondOrderConeConstraint &constraint)
 
bool operator== (const SecondOrderConeConstraint &lhs, const SecondOrderConeConstraint &rhs)
 
bool operator!= (const SecondOrderConeConstraint &lhs, const SecondOrderConeConstraint &rhs)
 
template<typename H >
AbslHashValue (H h, const SecondOrderConeConstraint &constraint)
 
absl::Status ValidateConstraint (const SecondOrderConeConstraintProto &constraint, const IdNameBiMap &variable_universe)
 
std::ostream & operator<< (std::ostream &ostr, const Sos1Constraint &constraint)
 
bool operator== (const Sos1Constraint &lhs, const Sos1Constraint &rhs)
 
bool operator!= (const Sos1Constraint &lhs, const Sos1Constraint &rhs)
 
template<typename H >
AbslHashValue (H h, const Sos1Constraint &constraint)
 
std::ostream & operator<< (std::ostream &ostr, const Sos2Constraint &constraint)
 
bool operator== (const Sos2Constraint &lhs, const Sos2Constraint &rhs)
 
bool operator!= (const Sos2Constraint &lhs, const Sos2Constraint &rhs)
 
template<typename H >
AbslHashValue (H h, const Sos2Constraint &constraint)
 
absl::Status ValidateConstraint (const SosConstraintProto &constraint, const IdNameBiMap &variable_universe)
 
LinearExpression ToLinearExpression (const ModelStorage &storage, const LinearExpressionData &expr_data)
 
LinearExpressionData FromLinearExpression (const LinearExpression &expression)
 Converts a LinearExpression to the associated "raw ID" format.
 
template<typename IdType >
std::vector< VariableAtomicConstraintNonzeroVariables (const ModelStorage &storage, const IdType id)
 
template<typename ConstraintType >
std::vector< ConstraintType > AtomicConstraints (const ModelStorage &storage)
 
template<typename ConstraintType >
std::vector< ConstraintType > SortedAtomicConstraints (const ModelStorage &storage)
 
std::ostream & operator<< (std::ostream &out, const BaseSolver::SolveArgs &args)
 
std::ostream & operator<< (std::ostream &out, const BaseSolver::ComputeInfeasibleSubsystemArgs &args)
 
SolveResultProto ResultForIntegerInfeasible (const bool is_maximize, const int64_t bad_variable_id, const double lb, const double ub)
 
ObjectiveBoundsProto GetObjectiveBounds (const SolveResultProto &solve_result)
 
ProblemStatusProto GetProblemStatus (const SolveResultProto &solve_result)
 
void RemoveSparseDoubleVectorZeros (SparseDoubleVectorProto &sparse_vector)
 
SparseDoubleVectorProto FilterSparseVector (const SparseDoubleVectorProto &input, const SparseVectorFilterProto &filter)
 
void ApplyAllFilters (const ModelSolveParametersProto &model_solve_params, SolutionProto &solution)
 
absl::flat_hash_set< CallbackEventProto > EventSet (const CallbackRegistrationProto &callback_registration)
 Returns the callback_registration.request_registration as a set of enums.
 
TerminationProto TerminateForLimit (const LimitProto limit, const bool feasible, const absl::string_view detail)
 
TerminationProto FeasibleTermination (const LimitProto limit, const absl::string_view detail)
 
TerminationProto NoSolutionFoundTermination (const LimitProto limit, const absl::string_view detail)
 
TerminationProto TerminateForReason (const TerminationReasonProto reason, const absl::string_view detail)
 
ObjectiveBoundsProto MakeTrivialBounds (const bool is_maximize)
 
TerminationProto TerminateForReason (const bool is_maximize, const TerminationReasonProto reason, const absl::string_view detail)
 
TerminationProto OptimalTerminationProto (const double finite_primal_objective, const double dual_objective, const absl::string_view detail)
 
TerminationProto UnboundedTerminationProto (const bool is_maximize, const absl::string_view detail)
 
TerminationProto InfeasibleTerminationProto (bool is_maximize, const FeasibilityStatusProto dual_feasibility_status, const absl::string_view detail)
 
TerminationProto LimitTerminationProto (const bool is_maximize, const LimitProto limit, const std::optional< double > optional_finite_primal_objective, const std::optional< double > optional_dual_objective, const absl::string_view detail)
 
TerminationProto LimitTerminationProto (LimitProto limit, const double primal_objective, const double dual_objective, const bool claim_dual_feasible_solution_exists, const absl::string_view detail)
 
TerminationProto CutoffTerminationProto (bool is_maximize, absl::string_view detail={})
 Calls NoSolutionFoundTerminationProto() with LIMIT_CUTOFF LIMIT.
 
TerminationProto NoSolutionFoundTerminationProto (const bool is_maximize, const LimitProto limit, const std::optional< double > optional_dual_objective, const absl::string_view detail)
 
TerminationProto FeasibleTerminationProto (const bool is_maximize, const LimitProto limit, const double primal_objective, const std::optional< double > optional_dual_objective, const absl::string_view detail)
 
TerminationProto InfeasibleOrUnboundedTerminationProto (bool is_maximize, const FeasibilityStatusProto dual_feasibility_status, const absl::string_view detail)
 
absl::Status ModelIsSupported (const ModelProto &model, const SupportedProblemStructures &support_menu, const absl::string_view solver_name)
 
bool UpdateIsSupported (const ModelUpdateProto &update, const SupportedProblemStructures &support_menu)
 
void UpgradeSolveResultProtoForStatsMigration (SolveResultProto &solve_result_proto)
 
int NumVariables (const VariablesProto &variables)
 
int NumConstraints (const LinearConstraintsProto &linear_constraints)
 
int NumMatrixNonzeros (const SparseDoubleMatrixProto &matrix)
 
std::optional< int64_t > FirstVariableId (const VariablesProto &variables)
 
std::optional< int64_t > FirstLinearConstraintId (const LinearConstraintsProto &linear_constraints)
 
 ABSL_DEPRECATED ("Use TerminateForReason(bool, TerminationReasonProto, absl::string_view) " "instead") TerminationProto TerminateForReason(TerminationReasonProto reason
 
template<typename T >
std::vector< T > SortedSetElements (const absl::flat_hash_set< T > &elements)
 
template<typename K , typename V >
std::vector< K > MapKeys (const absl::flat_hash_map< K, V > &in_map)
 
template<typename K , typename V >
std::vector< K > MapKeys (const google::protobuf::Map< K, V > &in_map)
 
template<typename K , typename V >
std::vector< K > SortedMapKeys (const absl::flat_hash_map< K, V > &in_map)
 
template<typename K , typename V >
std::vector< K > SortedMapKeys (const google::protobuf::Map< K, V > &in_map)
 
SparseSubmatrixRowsView SparseSubmatrixByRows (const SparseDoubleMatrixProto &matrix, const int64_t start_row_id, const std::optional< int64_t > end_row_id, const int64_t start_col_id, const std::optional< int64_t > end_col_id)
 
std::vector< std::pair< int64_t, SparseVector< double > > > TransposeSparseSubmatrix (const SparseSubmatrixRowsView &submatrix_by_rows)
 
template<typename Collection , typename T = typename Collection::value_type>
SparseVectorView< T > MakeView (absl::Span< const int64_t > ids, const Collection &values)
 
template<typename T >
SparseVectorView< const T * > MakeView (const google::protobuf::RepeatedField< int64_t > &ids, const google::protobuf::RepeatedPtrField< T > &values)
 
template<typename SparseVectorProto , typename T = sparse_value_type<SparseVectorProto>>
SparseVectorView< T > MakeView (const SparseVectorProto &sparse_vector)
 
template<typename T >
SparseVectorView< T > MakeView (const SparseVector< T > &sparse_vector)
 
 MATH_OPT_DEFINE_ENUM (BasisStatus, BASIS_STATUS_UNSPECIFIED)
 
 MATH_OPT_DEFINE_ENUM (CallbackEvent, CALLBACK_EVENT_UNSPECIFIED)
 
std::ostream & operator<< (std::ostream &out, const ModelSubset::Bounds &bounds)
 
std::ostream & operator<< (std::ostream &out, const ModelSubset &model_subset)
 
std::ostream & operator<< (std::ostream &out, const ComputeInfeasibleSubsystemResult &result)
 
template<typename E >
Enum< E >::Proto EnumToProto (std::optional< E > value)
 
template<typename E >
Enum< E >::Proto EnumToProto (E value)
 
template<typename P >
std::optional< typename EnumProto< P >::Cpp > EnumFromProto (P proto_value)
 
template<typename E >
absl::string_view EnumToString (E value)
 
template<typename E >
std::optional< absl::string_view > EnumToOptString (E value)
 
template<typename E >
std::optional< E > EnumFromString (absl::string_view str)
 
template<typename E , typename = std::enable_if_t<Enum<E>::kIsImplemented>>
std::ostream & operator<< (std::ostream &out, const E value)
 
template<typename E , typename = std::enable_if_t<Enum<E>::kIsImplemented>>
std::ostream & operator<< (std::ostream &out, const std::optional< E > opt_value)
 
std::ostream & operator<< (std::ostream &out, const LeadingCoefficientFormatter formatter)
 
std::ostream & operator<< (std::ostream &out, const ConstantFormatter formatter)
 
template<typename Map , typename = std::enable_if_t<is_key_type_v<typename Map::key_type>>>
std::vector< typename Map::key_type > SortedKeys (const Map &map)
 
template<typename Set , typename = std::enable_if_t<is_key_type_v<typename Set::key_type>>>
std::vector< typename Set::key_type > SortedElements (const Set &set)
 
template<typename Map , typename Keys , typename = std::enable_if_t<is_key_type_v<typename Map::key_type>>>
std::vector< typename Map::mapped_type > Values (const Map &map, const Keys &keys)
 
std::ostream & operator<< (std::ostream &ostr, const LinearConstraint &linear_constraint)
 
bool operator== (const LinearConstraint &lhs, const LinearConstraint &rhs)
 
bool operator!= (const LinearConstraint &lhs, const LinearConstraint &rhs)
 
template<typename H >
AbslHashValue (H h, const LinearConstraint &linear_constraint)
 
absl::StatusOr< MapFilter< Variable > > VariableFilterFromProto (const Model &model, const SparseVectorFilterProto &proto)
 
absl::StatusOr< MapFilter< LinearConstraint > > LinearConstraintFilterFromProto (const Model &model, const SparseVectorFilterProto &proto)
 
absl::StatusOr< MapFilter< QuadraticConstraint > > QuadraticConstraintFilterFromProto (const Model &model, const SparseVectorFilterProto &proto)
 
template<typename KeyType >
MapFilter< KeyType > MakeSkipAllFilter ()
 
template<typename KeyType >
MapFilter< KeyType > MakeSkipZerosFilter ()
 
template<typename Collection , typename ValueType = typename Collection::value_type>
MapFilter< ValueType > MakeKeepKeysFilter (const Collection &keys)
 
template<typename KeyType >
MapFilter< KeyType > MakeKeepKeysFilter (std::initializer_list< KeyType > keys)
 
void PrintTo (const PrimalSolution &primal_solution, std::ostream *const os)
 
void PrintTo (const DualSolution &dual_solution, std::ostream *const os)
 
void PrintTo (const PrimalRay &primal_ray, std::ostream *const os)
 
void PrintTo (const DualRay &dual_ray, std::ostream *const os)
 
void PrintTo (const Basis &basis, std::ostream *const os)
 
void PrintTo (const Solution &solution, std::ostream *const os)
 
void PrintTo (const SolveResult &result, std::ostream *const os)
 
Matcher< VariableMap< double > > IsNearlySubsetOf (VariableMap< double > expected, double tolerance)
 
Matcher< VariableMap< double > > IsNear (VariableMap< double > expected, const double tolerance)
 
Matcher< LinearConstraintMap< double > > IsNearlySubsetOf (LinearConstraintMap< double > expected, double tolerance)
 
Matcher< LinearConstraintMap< double > > IsNear (LinearConstraintMap< double > expected, const double tolerance)
 
Matcher< absl::flat_hash_map< QuadraticConstraint, double > > IsNear (absl::flat_hash_map< QuadraticConstraint, double > expected, const double tolerance)
 
Matcher< absl::flat_hash_map< QuadraticConstraint, double > > IsNearlySubsetOf (absl::flat_hash_map< QuadraticConstraint, double > expected, double tolerance)
 
template<typename K >
Matcher< absl::flat_hash_map< K, double > > IsNear (absl::flat_hash_map< K, double > expected, const double tolerance)
 
template<typename K >
Matcher< absl::flat_hash_map< K, double > > IsNearlySubsetOf (absl::flat_hash_map< K, double > expected, const double tolerance)
 
testing::Matcher< LinearExpressionIsIdentical (LinearExpression expected)
 
testing::Matcher< LinearExpressionLinearExpressionIsNear (const LinearExpression expected, const double tolerance)
 
testing::Matcher< BoundedLinearExpressionIsNearlyEquivalent (const BoundedLinearExpression &expected, const double tolerance)
 
testing::Matcher< QuadraticExpressionIsIdentical (QuadraticExpression expected)
 
Matcher< SolutionStatusSolutionStatusIs (const SolutionStatus expected, const bool allow_undetermined)
 
Matcher< PrimalSolutionIsNear (PrimalSolution expected, const double tolerance, const bool allow_undetermined)
 
Matcher< DualSolutionIsNear (DualSolution expected, const double tolerance, const bool allow_undetermined)
 
Matcher< BasisBasisIs (const Basis &expected)
 
Matcher< SolutionIsNear (Solution expected, const SolutionMatcherOptions options)
 
Matcher< PrimalRayIsNear (PrimalRay expected, const double tolerance)
 
Matcher< PrimalRayPrimalRayIsNear (VariableMap< double > expected_var_values, const double tolerance)
 
Matcher< DualRayIsNear (DualRay expected, const double tolerance)
 
Matcher< ObjectiveBoundsObjectiveBoundsNear (const ObjectiveBounds &expected, const double tolerance)
 
Matcher< SolveResult > TerminatesWithOneOf (const std::vector< TerminationReason > &allowed)
 Checks that the result has one of the allowed termination reasons.
 
Matcher< SolveResult > TerminatesWith (const TerminationReason expected)
 
testing::Matcher< SolveResult > TerminatesWithLimit (const Limit expected, const bool allow_limit_undetermined)
 
testing::Matcher< SolveResult > TerminatesWithReasonFeasible (const Limit expected, const bool allow_limit_undetermined)
 
testing::Matcher< SolveResult > TerminatesWithReasonNoSolutionFound (const Limit expected, const bool allow_limit_undetermined)
 
template<typename MatcherType >
std::string MatcherToStringImpl (const MatcherType &matcher, const bool negate)
 
template<typename T >
std::string MatcherToString (const Matcher< T > &matcher, bool negate)
 
template<typename T >
std::string MatcherToString (const ::testing::PolymorphicMatcher< T > &matcher, bool negate)
 
 MATCHER_P (FirstElementIs, first_element_matcher,(negation ? absl::StrCat("is empty or first element ", MatcherToString(first_element_matcher, true)) :absl::StrCat("has at least one element and first element ", MatcherToString(first_element_matcher, false))))
 
Matcher< TerminationLimitIs (math_opt::Limit limit, const Matcher< std::string > detail_matcher)
 
Matcher< TerminationReasonIs (TerminationReason reason)
 
Matcher< TerminationReasonIsOptimal ()
 
Matcher< ProblemStatusProblemStatusIs (const ProblemStatus &expected)
 
Matcher< TerminationTerminationIsOptimal ()
 
Matcher< TerminationTerminationIsOptimal (const double primal_objective_value, const std::optional< double > dual_objective_value, const double tolerance)
 
Matcher< TerminationTerminationIsIgnoreDetail (const Termination &expected)
 
Matcher< SolveResult > IsOptimal (const std::optional< double > expected_primal_objective, const double tolerance)
 
Matcher< SolveResult > IsOptimalWithSolution (const double expected_objective, const VariableMap< double > expected_variable_values, const double tolerance)
 
Matcher< SolveResult > IsOptimalWithDualSolution (const double expected_objective, const LinearConstraintMap< double > expected_dual_values, const VariableMap< double > expected_reduced_costs, const double tolerance)
 
Matcher< SolveResult > IsOptimalWithDualSolution (const double expected_objective, const LinearConstraintMap< double > expected_dual_values, const absl::flat_hash_map< QuadraticConstraint, double > expected_quadratic_dual_values, const VariableMap< double > expected_reduced_costs, const double tolerance)
 
Matcher< SolveResult > HasSolution (PrimalSolution expected, double tolerance=kMatcherDefaultTolerance)
 SolveResult has a primal solution matching expected within tolerance.
 
Matcher< SolveResult > HasDualSolution (DualSolution expected, const double tolerance)
 
Matcher< SolveResult > HasPrimalRay (PrimalRay expected, const double tolerance)
 
Matcher< SolveResult > HasPrimalRay (VariableMap< double > expected_vars, const double tolerance)
 
Matcher< SolveResult > HasDualRay (DualRay expected, const double tolerance)
 
Matcher< SolveResult > IsConsistentWith (const SolveResult &expected, const SolveResultMatcherOptions &options)
 
testing::Matcher< ComputeInfeasibleSubsystemResultIsFeasible ()
 
testing::Matcher< ComputeInfeasibleSubsystemResultIsUndetermined ()
 
testing::Matcher< ComputeInfeasibleSubsystemResultIsInfeasible (const std::optional< bool > expected_is_minimal, const std::optional< ModelSubset > expected_infeasible_subsystem)
 
Matcher< UpdateResultDidUpdate ()
 Actual UpdateResult.did_update is true.
 
testing::Matcher< TerminationLimitIs (Limit limit, testing::Matcher< std::string > detail_matcher=testing::_)
 
template<typename K , typename V , typename = std::enable_if_t<is_key_type_v<K>>>
void PrintTo (const absl::flat_hash_map< K, V > &id_map, std::ostream *const os)
 
MessageCallback PrinterMessageCallback (std::ostream &output_stream, const absl::string_view prefix)
 
MessageCallback InfoLoggerMessageCallback (const absl::string_view prefix, const absl::SourceLocation loc)
 
MessageCallback VLoggerMessageCallback (int level, absl::string_view prefix, absl::SourceLocation loc)
 
MessageCallback VectorMessageCallback (std::vector< std::string > *sink)
 
MessageCallback RepeatedPtrFieldMessageCallback (google::protobuf::RepeatedPtrField< std::string > *sink)
 
std::ostream & operator<< (std::ostream &ostr, const Model &model)
 
std::ostream & operator<< (std::ostream &ostr, const Objective &objective)
 
bool operator== (const Objective &lhs, const Objective &rhs)
 
bool operator!= (const Objective &lhs, const Objective &rhs)
 
template<typename H >
AbslHashValue (H h, const Objective &objective)
 
bool AbslParseFlag (const absl::string_view text, SolverType *const value, std::string *const error)
 
std::string AbslUnparseFlag (const SolverType value)
 
bool AbslParseFlag (absl::string_view text, LPAlgorithm *const value, std::string *const error)
 
std::string AbslUnparseFlag (const LPAlgorithm value)
 
bool AbslParseFlag (absl::string_view text, Emphasis *const value, std::string *const error)
 
std::string AbslUnparseFlag (const Emphasis value)
 
bool AbslParseFlag (absl::string_view text, SolveParameters *solve_parameters, std::string *error)
 
std::string AbslUnparseFlag (SolveParameters solve_parameters)
 
 MATH_OPT_DEFINE_ENUM (SolverType, SOLVER_TYPE_UNSPECIFIED)
 
 MATH_OPT_DEFINE_ENUM (LPAlgorithm, LP_ALGORITHM_UNSPECIFIED)
 
 MATH_OPT_DEFINE_ENUM (Emphasis, EMPHASIS_UNSPECIFIED)
 
 MATH_OPT_DEFINE_ENUM (SolutionStatus, SOLUTION_STATUS_UNSPECIFIED)
 
absl::StatusOr< SolveResult > Solve (const Model &model, const SolverType solver_type, const SolveArguments &solve_args, const SolverInitArguments &init_args)
 
absl::StatusOr< ComputeInfeasibleSubsystemResultComputeInfeasibleSubsystem (const Model &model, const SolverType solver_type, const ComputeInfeasibleSubsystemArguments &compute_args, const SolverInitArguments &init_args)
 
absl::StatusOr< std::unique_ptr< IncrementalSolver > > NewIncrementalSolver (Model *model, SolverType solver_type, SolverInitArguments arguments)
 
std::ostream & operator<< (std::ostream &ostr, const ObjectiveBounds &objective_bounds)
 
std::ostream & operator<< (std::ostream &ostr, const Termination &termination)
 
std::ostream & operator<< (std::ostream &ostr, const ProblemStatus &problem_status)
 
std::ostream & operator<< (std::ostream &ostr, const SolveStats &solve_stats)
 
absl::Status CheckSolverSpecificOutputEmpty (const SolveResultProto &result)
 
std::ostream & operator<< (std::ostream &out, const SolveResult &result)
 
 MATH_OPT_DEFINE_ENUM (FeasibilityStatus, FEASIBILITY_STATUS_UNSPECIFIED)
 
 MATH_OPT_DEFINE_ENUM (TerminationReason, TERMINATION_REASON_UNSPECIFIED)
 
 MATH_OPT_DEFINE_ENUM (Limit, LIMIT_UNSPECIFIED)
 
bool AbslParseFlag (const absl::string_view text, SolverResources *const solver_resources, std::string *const error)
 
std::string AbslUnparseFlag (const SolverResources &solver_resources)
 
absl::StatusOr< VariableMap< double > > VariableValuesFromProto (const ModelStorage *const model, const SparseDoubleVectorProto &vars_proto)
 
absl::StatusOr< VariableMap< int32_t > > VariableValuesFromProto (const ModelStorage *model, const SparseInt32VectorProto &vars_proto)
 
SparseDoubleVectorProto VariableValuesToProto (const VariableMap< double > &variable_values)
 Returns the proto equivalent of variable_values.
 
absl::StatusOr< absl::flat_hash_map< Objective, double > > AuxiliaryObjectiveValuesFromProto (const ModelStorage *const model, const google::protobuf::Map< int64_t, double > &aux_obj_proto)
 
google::protobuf::Map< int64_t, double > AuxiliaryObjectiveValuesToProto (const absl::flat_hash_map< Objective, double > &aux_obj_values)
 
absl::StatusOr< LinearConstraintMap< double > > LinearConstraintValuesFromProto (const ModelStorage *const model, const SparseDoubleVectorProto &lin_cons_proto)
 
SparseDoubleVectorProto LinearConstraintValuesToProto (const LinearConstraintMap< double > &linear_constraint_values)
 Returns the proto equivalent of linear_constraint_values.
 
absl::StatusOr< absl::flat_hash_map< QuadraticConstraint, double > > QuadraticConstraintValuesFromProto (const ModelStorage *const model, const SparseDoubleVectorProto &quad_cons_proto)
 
SparseDoubleVectorProto QuadraticConstraintValuesToProto (const absl::flat_hash_map< QuadraticConstraint, double > &quadratic_constraint_values)
 Returns the proto equivalent of quadratic_constraint_values.
 
absl::StatusOr< VariableMap< BasisStatus > > VariableBasisFromProto (const ModelStorage *const model, const SparseBasisStatusVector &basis_proto)
 
SparseBasisStatusVector VariableBasisToProto (const VariableMap< BasisStatus > &basis_values)
 Returns the proto equivalent of basis_values.
 
absl::StatusOr< LinearConstraintMap< BasisStatus > > LinearConstraintBasisFromProto (const ModelStorage *const model, const SparseBasisStatusVector &basis_proto)
 
SparseBasisStatusVector LinearConstraintBasisToProto (const LinearConstraintMap< BasisStatus > &basis_values)
 Returns the proto equivalent of basis_values.
 
std::ostream & operator<< (std::ostream &out, const ModelRanges &ranges)
 
ModelRanges ComputeModelRanges (const Model &model)
 Returns the ranges of the finite non-zero values in the given model.
 
std::ostream & operator<< (std::ostream &ostr, const LinearExpression &expression)
 
std::ostream & operator<< (std::ostream &ostr, const BoundedLinearExpression &bounded_expression)
 
std::ostream & operator<< (std::ostream &ostr, const QuadraticExpression &expr)
 
std::ostream & operator<< (std::ostream &ostr, const BoundedQuadraticExpression &bounded_expression)
 
internal::VariablesEquality operator== (const Variable &lhs, const Variable &rhs)
 
bool operator!= (const Variable &lhs, const Variable &rhs)
 
std::ostream & operator<< (std::ostream &ostr, const Variable &variable)
 
LinearTerm operator* (double coefficient, LinearTerm term)
 
LinearTerm operator* (LinearTerm term, double coefficient)
 
LinearTerm operator* (double coefficient, Variable variable)
 
LinearTerm operator* (Variable variable, double coefficient)
 
LinearTerm operator/ (LinearTerm term, double coefficient)
 
LinearTerm operator/ (Variable variable, double coefficient)
 
template<typename Iterable >
LinearExpression Sum (const Iterable &items)
 
RightIterable LinearExpression InnerProduct (const LeftIterable &left, const RightIterable &right)
 
LinearExpression operator- (LinearExpression expr)
 
LinearExpression operator+ (Variable lhs, double rhs)
 
LinearExpression operator+ (double lhs, Variable rhs)
 
LinearExpression operator+ (Variable lhs, Variable rhs)
 
LinearExpression operator+ (const LinearTerm &lhs, double rhs)
 
LinearExpression operator+ (double lhs, const LinearTerm &rhs)
 
LinearExpression operator+ (const LinearTerm &lhs, Variable rhs)
 
LinearExpression operator+ (Variable lhs, const LinearTerm &rhs)
 
LinearExpression operator+ (const LinearTerm &lhs, const LinearTerm &rhs)
 
LinearExpression operator+ (LinearExpression lhs, double rhs)
 
LinearExpression operator+ (double lhs, LinearExpression rhs)
 
LinearExpression operator+ (LinearExpression lhs, Variable rhs)
 
LinearExpression operator+ (Variable lhs, LinearExpression rhs)
 
LinearExpression operator+ (LinearExpression lhs, const LinearTerm &rhs)
 
LinearExpression operator+ (LinearTerm lhs, LinearExpression rhs)
 
LinearExpression operator+ (LinearExpression lhs, const LinearExpression &rhs)
 
LinearExpression operator- (Variable lhs, double rhs)
 
LinearExpression operator- (double lhs, Variable rhs)
 
LinearExpression operator- (Variable lhs, Variable rhs)
 
LinearExpression operator- (const LinearTerm &lhs, double rhs)
 
LinearExpression operator- (double lhs, const LinearTerm &rhs)
 
LinearExpression operator- (const LinearTerm &lhs, Variable rhs)
 
LinearExpression operator- (Variable lhs, const LinearTerm &rhs)
 
LinearExpression operator- (const LinearTerm &lhs, const LinearTerm &rhs)
 
LinearExpression operator- (LinearExpression lhs, double rhs)
 
LinearExpression operator- (double lhs, LinearExpression rhs)
 
LinearExpression operator- (LinearExpression lhs, Variable rhs)
 
LinearExpression operator- (Variable lhs, LinearExpression rhs)
 
LinearExpression operator- (LinearExpression lhs, const LinearTerm &rhs)
 
LinearExpression operator- (LinearTerm lhs, LinearExpression rhs)
 
LinearExpression operator- (LinearExpression lhs, const LinearExpression &rhs)
 
LinearExpression operator* (LinearExpression lhs, double rhs)
 
LinearExpression operator* (double lhs, LinearExpression rhs)
 
LinearExpression operator/ (LinearExpression lhs, double rhs)
 
LowerBoundedLinearExpression operator>= (LinearExpression expression, double constant)
 
LowerBoundedLinearExpression operator<= (double constant, LinearExpression expression)
 
LowerBoundedLinearExpression operator>= (const LinearTerm &term, double constant)
 
LowerBoundedLinearExpression operator<= (double constant, const LinearTerm &term)
 
LowerBoundedLinearExpression operator>= (Variable variable, double constant)
 
LowerBoundedLinearExpression operator<= (double constant, Variable variable)
 
UpperBoundedLinearExpression operator<= (LinearExpression expression, double constant)
 
UpperBoundedLinearExpression operator>= (double constant, LinearExpression expression)
 
UpperBoundedLinearExpression operator<= (const LinearTerm &term, double constant)
 
UpperBoundedLinearExpression operator>= (double constant, const LinearTerm &term)
 
UpperBoundedLinearExpression operator<= (Variable variable, double constant)
 
UpperBoundedLinearExpression operator>= (double constant, Variable variable)
 
BoundedLinearExpression operator<= (LowerBoundedLinearExpression lhs, double rhs)
 
BoundedLinearExpression operator>= (double lhs, LowerBoundedLinearExpression rhs)
 
BoundedLinearExpression operator>= (UpperBoundedLinearExpression lhs, double rhs)
 
BoundedLinearExpression operator<= (double lhs, UpperBoundedLinearExpression rhs)
 
BoundedLinearExpression operator<= (LinearExpression lhs, const LinearExpression &rhs)
 
BoundedLinearExpression operator>= (LinearExpression lhs, const LinearExpression &rhs)
 
BoundedLinearExpression operator<= (LinearExpression lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator>= (LinearExpression lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator<= (const LinearTerm &lhs, LinearExpression rhs)
 
BoundedLinearExpression operator>= (const LinearTerm &lhs, LinearExpression rhs)
 
BoundedLinearExpression operator<= (LinearExpression lhs, Variable rhs)
 
BoundedLinearExpression operator>= (LinearExpression lhs, Variable rhs)
 
BoundedLinearExpression operator<= (Variable lhs, LinearExpression rhs)
 
BoundedLinearExpression operator>= (Variable lhs, LinearExpression rhs)
 
BoundedLinearExpression operator<= (const LinearTerm &lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator>= (const LinearTerm &lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator<= (const LinearTerm &lhs, Variable rhs)
 
BoundedLinearExpression operator>= (const LinearTerm &lhs, Variable rhs)
 
BoundedLinearExpression operator<= (Variable lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator>= (Variable lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator<= (Variable lhs, Variable rhs)
 
BoundedLinearExpression operator>= (Variable lhs, Variable rhs)
 
BoundedLinearExpression operator== (LinearExpression lhs, const LinearExpression &rhs)
 
BoundedLinearExpression operator== (LinearExpression lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator== (const LinearTerm &lhs, LinearExpression rhs)
 
BoundedLinearExpression operator== (LinearExpression lhs, Variable rhs)
 
BoundedLinearExpression operator== (Variable lhs, LinearExpression rhs)
 
BoundedLinearExpression operator== (LinearExpression lhs, double rhs)
 
BoundedLinearExpression operator== (double lhs, LinearExpression rhs)
 
BoundedLinearExpression operator== (const LinearTerm &lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator== (const LinearTerm &lhs, Variable rhs)
 
BoundedLinearExpression operator== (Variable lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator== (const LinearTerm &lhs, double rhs)
 
BoundedLinearExpression operator== (double lhs, const LinearTerm &rhs)
 
BoundedLinearExpression operator== (Variable lhs, double rhs)
 
BoundedLinearExpression operator== (double lhs, Variable rhs)
 
std::ostream & operator<< (std::ostream &ostr, const QuadraticTermKey &key)
 
bool operator== (QuadraticTermKey lhs, QuadraticTermKey rhs)
 
bool operator!= (QuadraticTermKey lhs, QuadraticTermKey rhs)
 
QuadraticTerm operator- (QuadraticTerm term)
 ------------------------— Subtraction (-) ------------------------------—
 
QuadraticTerm operator* (const double lhs, QuadraticTerm rhs)
 -------------------------— Multiplication (*) --------------------------—
 
QuadraticTerm operator* (Variable lhs, Variable rhs)
 
QuadraticTerm operator* (Variable lhs, LinearTerm rhs)
 
QuadraticTerm operator* (LinearTerm lhs, Variable rhs)
 
QuadraticTerm operator* (LinearTerm lhs, LinearTerm rhs)
 
QuadraticTerm operator* (QuadraticTerm lhs, const double rhs)
 
QuadraticTerm operator/ (QuadraticTerm lhs, const double rhs)
 ----------------------------— Division (/) -----------------------------—
 
QuadraticExpression operator- (QuadraticExpression expr)
 
QuadraticExpression operator+ (const double lhs, const QuadraticTerm &rhs)
 --------------------------— Addition (+) -------------------------------—
 
QuadraticExpression operator+ (double lhs, QuadraticExpression rhs)
 
QuadraticExpression operator+ (Variable lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator+ (Variable lhs, QuadraticExpression rhs)
 
QuadraticExpression operator+ (const LinearTerm &lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator+ (const LinearTerm &lhs, QuadraticExpression rhs)
 
QuadraticExpression operator+ (LinearExpression lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator+ (const LinearExpression &lhs, QuadraticExpression rhs)
 
QuadraticExpression operator+ (const QuadraticTerm &lhs, double rhs)
 
QuadraticExpression operator+ (const QuadraticTerm &lhs, Variable rhs)
 
QuadraticExpression operator+ (const QuadraticTerm &lhs, const LinearTerm &rhs)
 
QuadraticExpression operator+ (const QuadraticTerm &lhs, LinearExpression rhs)
 
QuadraticExpression operator+ (const QuadraticTerm &lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator+ (const QuadraticTerm &lhs, QuadraticExpression rhs)
 
QuadraticExpression operator+ (QuadraticExpression lhs, double rhs)
 
QuadraticExpression operator+ (QuadraticExpression lhs, Variable rhs)
 
QuadraticExpression operator+ (QuadraticExpression lhs, const LinearTerm &rhs)
 
QuadraticExpression operator+ (QuadraticExpression lhs, const LinearExpression &rhs)
 
QuadraticExpression operator+ (QuadraticExpression lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator+ (QuadraticExpression lhs, const QuadraticExpression &rhs)
 
QuadraticExpression operator- (double lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator- (double lhs, QuadraticExpression rhs)
 
QuadraticExpression operator- (Variable lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator- (Variable lhs, QuadraticExpression rhs)
 
QuadraticExpression operator- (const LinearTerm &lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator- (const LinearTerm &lhs, QuadraticExpression rhs)
 
QuadraticExpression operator- (LinearExpression lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator- (const LinearExpression &lhs, QuadraticExpression rhs)
 
QuadraticExpression operator- (const QuadraticTerm &lhs, double rhs)
 
QuadraticExpression operator- (const QuadraticTerm &lhs, Variable rhs)
 
QuadraticExpression operator- (const QuadraticTerm &lhs, const LinearTerm &rhs)
 
QuadraticExpression operator- (const QuadraticTerm &lhs, LinearExpression rhs)
 
QuadraticExpression operator- (const QuadraticTerm &lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator- (const QuadraticTerm &lhs, QuadraticExpression rhs)
 
QuadraticExpression operator- (QuadraticExpression lhs, double rhs)
 
QuadraticExpression operator- (QuadraticExpression lhs, Variable rhs)
 
QuadraticExpression operator- (QuadraticExpression lhs, const LinearTerm &rhs)
 
QuadraticExpression operator- (QuadraticExpression lhs, const LinearExpression &rhs)
 
QuadraticExpression operator- (QuadraticExpression lhs, const QuadraticTerm &rhs)
 
QuadraticExpression operator- (QuadraticExpression lhs, const QuadraticExpression &rhs)
 
QuadraticExpression operator* (double lhs, QuadraticExpression rhs)
 
QuadraticExpression operator* (Variable lhs, const LinearExpression &rhs)
 
QuadraticExpression operator* (LinearTerm lhs, const LinearExpression &rhs)
 
QuadraticExpression operator* (const LinearExpression &lhs, Variable rhs)
 
QuadraticExpression operator* (const LinearExpression &lhs, LinearTerm rhs)
 
QuadraticExpression operator* (const LinearExpression &lhs, const LinearExpression &rhs)
 
QuadraticExpression operator* (QuadraticExpression lhs, double rhs)
 
QuadraticExpression operator/ (QuadraticExpression lhs, double rhs)
 
LowerBoundedQuadraticExpression operator>= (QuadraticExpression lhs, double rhs)
 
LowerBoundedQuadraticExpression operator>= (QuadraticTerm lhs, double rhs)
 
LowerBoundedQuadraticExpression operator<= (double lhs, QuadraticExpression rhs)
 
LowerBoundedQuadraticExpression operator<= (double lhs, QuadraticTerm rhs)
 
UpperBoundedQuadraticExpression operator>= (double lhs, QuadraticExpression rhs)
 
UpperBoundedQuadraticExpression operator>= (double lhs, QuadraticTerm rhs)
 
UpperBoundedQuadraticExpression operator<= (QuadraticExpression lhs, double rhs)
 
UpperBoundedQuadraticExpression operator<= (QuadraticTerm lhs, double rhs)
 
BoundedQuadraticExpression operator>= (UpperBoundedQuadraticExpression lhs, double rhs)
 
BoundedQuadraticExpression operator>= (double lhs, LowerBoundedQuadraticExpression rhs)
 
BoundedQuadraticExpression operator<= (LowerBoundedQuadraticExpression lhs, double rhs)
 
BoundedQuadraticExpression operator<= (double lhs, UpperBoundedQuadraticExpression rhs)
 
BoundedQuadraticExpression operator>= (QuadraticExpression lhs, const QuadraticExpression &rhs)
 Comparisons with lhs = QuadraticExpression.
 
BoundedQuadraticExpression operator>= (QuadraticExpression lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator>= (QuadraticExpression lhs, const LinearExpression &rhs)
 
BoundedQuadraticExpression operator>= (QuadraticExpression lhs, LinearTerm rhs)
 
BoundedQuadraticExpression operator>= (QuadraticExpression lhs, Variable rhs)
 
BoundedQuadraticExpression operator<= (QuadraticExpression lhs, const QuadraticExpression &rhs)
 
BoundedQuadraticExpression operator<= (QuadraticExpression lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator<= (QuadraticExpression lhs, const LinearExpression &rhs)
 
BoundedQuadraticExpression operator<= (QuadraticExpression lhs, LinearTerm rhs)
 
BoundedQuadraticExpression operator<= (QuadraticExpression lhs, Variable rhs)
 
BoundedQuadraticExpression operator== (QuadraticExpression lhs, const QuadraticExpression &rhs)
 
BoundedQuadraticExpression operator== (QuadraticExpression lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator== (QuadraticExpression lhs, const LinearExpression &rhs)
 
BoundedQuadraticExpression operator== (QuadraticExpression lhs, LinearTerm rhs)
 
BoundedQuadraticExpression operator== (QuadraticExpression lhs, Variable rhs)
 
BoundedQuadraticExpression operator== (QuadraticExpression lhs, double rhs)
 
BoundedQuadraticExpression operator>= (QuadraticTerm lhs, QuadraticExpression rhs)
 Comparisons with lhs = QuadraticTerm.
 
BoundedQuadraticExpression operator>= (QuadraticTerm lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator>= (QuadraticTerm lhs, LinearExpression rhs)
 
BoundedQuadraticExpression operator>= (QuadraticTerm lhs, LinearTerm rhs)
 
BoundedQuadraticExpression operator>= (QuadraticTerm lhs, Variable rhs)
 
BoundedQuadraticExpression operator<= (QuadraticTerm lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator<= (QuadraticTerm lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator<= (QuadraticTerm lhs, LinearExpression rhs)
 
BoundedQuadraticExpression operator<= (QuadraticTerm lhs, LinearTerm rhs)
 
BoundedQuadraticExpression operator<= (QuadraticTerm lhs, Variable rhs)
 
BoundedQuadraticExpression operator== (QuadraticTerm lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator== (QuadraticTerm lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator== (QuadraticTerm lhs, LinearExpression rhs)
 
BoundedQuadraticExpression operator== (QuadraticTerm lhs, LinearTerm rhs)
 
BoundedQuadraticExpression operator== (QuadraticTerm lhs, Variable rhs)
 
BoundedQuadraticExpression operator== (QuadraticTerm lhs, double rhs)
 
BoundedQuadraticExpression operator>= (const LinearExpression &lhs, QuadraticExpression rhs)
 Comparisons with lhs = LinearExpression.
 
BoundedQuadraticExpression operator>= (LinearExpression lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator<= (const LinearExpression &lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator<= (LinearExpression lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator== (const LinearExpression &lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator== (LinearExpression lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator>= (LinearTerm lhs, QuadraticExpression rhs)
 Comparisons with lhs = LinearTerm.
 
BoundedQuadraticExpression operator>= (LinearTerm lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator<= (LinearTerm lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator<= (LinearTerm lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator== (LinearTerm lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator== (LinearTerm lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator>= (Variable lhs, QuadraticExpression rhs)
 Comparisons with lhs = Variable.
 
BoundedQuadraticExpression operator>= (Variable lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator<= (Variable lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator<= (Variable lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator== (Variable lhs, QuadraticExpression rhs)
 
BoundedQuadraticExpression operator== (Variable lhs, QuadraticTerm rhs)
 
BoundedQuadraticExpression operator== (double lhs, QuadraticTerm rhs)
 Comparisons with lhs = Double.
 
BoundedQuadraticExpression operator== (const double lhs, QuadraticExpression rhs)
 Double –.
 
template<typename H >
AbslHashValue (H h, const Variable &variable)
 
template<typename LeftIterable , typename RightIterable >
LinearExpression InnerProduct (const LeftIterable &left, const RightIterable &right)
 
template<typename H >
AbslHashValue (H h, const QuadraticTermKey &key)
 
absl::StatusOr< std::string > ModelProtoToLp (const ModelProto &model)
 
absl::StatusOr< ModelProto > ModelProtoFromLp (const absl::string_view lp_data)
 
absl::StatusOr< std::string > ModelProtoToMps (const ModelProto &model)
 
absl::StatusOr< ModelProto > ReadMpsFile (const absl::string_view filename)
 
absl::StatusOr< ModelProto > MpsToModelProto (absl::string_view mps_data)
 Converts a string with the contents of an MPS file into a ModelProto.
 
void RemoveNames (ModelProto &model)
 Removes the model, variables and constraints names of the provided model.
 
void RemoveNames (ModelUpdateProto &update)
 Removes the variables and constraints names of the provided update.
 
absl::StatusOr<::operations_research::math_opt::ModelProto > MPModelProtoToMathOptModel (const ::operations_research::MPModelProto &model)
 
absl::StatusOr< std::optional< SolutionHintProto > > MPModelProtoSolutionHintToMathOptHint (const MPModelProto &model)
 
absl::StatusOr<::operations_research::MPModelProto > MathOptModelToMPModelProto (const ::operations_research::math_opt::ModelProto &model)
 
absl::StatusOr< ModelProto > MPModelProtoToMathOptModel (const MPModelProto &model)
 
absl::StatusOr< MPModelProto > MathOptModelToMPModelProto (const ModelProto &model)
 
void AddRobustConstraint (const Model &uncertainty_model, const Variable rhs, absl::Span< const std::pair< LinearExpression, Variable > > uncertain_coefficients, Model &main_model)
 
absl::Status FormulateIndicatorConstraintAsMip (Model &model, const IndicatorConstraint indicator_constraint)
 
double LowerBound (const LinearExpression &linear_expression)
 
double UpperBound (const LinearExpression &linear_expression)
 
absl::StatusOr< ModelSubsetCheckPrimalSolutionFeasibility (const Model &model, const VariableMap< double > &variable_values, const FeasibilityCheckerOptions &options)
 
absl::StatusOr< std::vector< std::string > > ViolatedConstraintsAsStrings (const Model &model, const ModelSubset &violated_constraints, const VariableMap< double > &variable_values)
 
absl::StatusOr< VariableMap< double > > MoveVariablesToTheirBestFeasibleValue (const Model &model, const VariableMap< double > &input_solution, absl::Span< const Variable > variables, const MoveVariablesToTheirBestFeasibleValueOptions &options)
 
double RoundedLowerBound (const Variable v, const double tolerance)
 
double RoundedUpperBound (const Variable v, const double tolerance)
 Same as RoundedLowerBound() but for upper-bound.
 
bool ActivatePrimalRay (SolverType solver_type, SolveParameters &params)
 
bool ActivateDualRay (SolverType solver_type, SolveParameters &params)
 
std::ostream & operator<< (std::ostream &out, const MessageCallbackTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const CallbackTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const TimeLimitTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const GenericTestParameters &params)
 
std::ostream & operator<< (std::ostream &ostr, const InfeasibleSubsystemSupport &support_menu)
 
std::ostream & operator<< (std::ostream &ostr, const InfeasibleSubsystemTestParameters &params)
 
 TEST_P (InfeasibleSubsystemTest, CanComputeInfeasibleSubsystem)
 
 TEST_P (InfeasibleSubsystemTest, InvertedVariableBounds)
 
 TEST_P (InfeasibleSubsystemTest, IntegerVariableWithInfeasibleBounds)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentLessThanLinearConstraint)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentGreaterThanLinearConstraint)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentEqualityLinearConstraint)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentRangedLinearConstraint)
 
∞ ≤ x  (variable bounds) TEST_P(InfeasibleSubsystemTest
 The entire model is an IIS.
 
 EXPECT_THAT (ComputeInfeasibleSubsystem(model, GetParam().solver_type), IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=false,.upper=true}}},.linear_constraints={ {c, ModelSubset::Bounds{.lower=true,.upper=false}}}})))
 
 TEST_P (InfeasibleSubsystemTest, InconsistentLessThanQuadraticConstraint)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentGreaterThanQuadraticConstraint)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentEqualityQuadraticConstraint)
 
 EXPECT_THAT (ComputeInfeasibleSubsystem(model, GetParam().solver_type), IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=true,.upper=true}}},.quadratic_constraints={ {c, ModelSubset::Bounds{.lower=true,.upper=false}}}})))
 
 EXPECT_THAT (ComputeInfeasibleSubsystem(model, GetParam().solver_type), IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=true,.upper=false}}},.second_order_cone_constraints={c}})))
 
 EXPECT_THAT (ComputeInfeasibleSubsystem(model, GetParam().solver_type), IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=false,.upper=true}}},.second_order_cone_constraints={c}})))
 
y y TEST_P (InfeasibleSubsystemTest, InconsistentSos1Constraint)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentSos1ConstraintWithExpressions)
 
z z y TEST_P (InfeasibleSubsystemTest, InconsistentSos2Constraint)
 
 TEST_P (InfeasibleSubsystemTest, InconsistentSos2ConstraintWithExpressions)
 
 EXPECT_THAT (ComputeInfeasibleSubsystem(model, GetParam().solver_type), IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=true,.upper=false}}},.variable_integrality={x},.indicator_constraints={c}})))
 
 TEST_P (InfeasibleSubsystemTest, IndicatorConstraintOkInconsistentImpliedNullIndicator)
 
 TEST_P (InfeasibleSubsystemTest, NontrivialInfeasibleIpSolveWithoutLimitsFindsIIS)
 
 TEST_P (InfeasibleSubsystemTest, NontrivialInfeasibleIpSolveTimeLimitZeroIsUndetermined)
 
 TEST_P (InfeasibleSubsystemTest, NontrivialInfeasibleIpSolveInterruptedBeforeStartIsUndetermined)
 
 TEST_P (InfeasibleSubsystemTest, NontrivialInfeasibleIpSolveWithMessageCallbackIsInvoked)
 
std::ostream & operator<< (std::ostream &out, const InvalidInputTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const InvalidParameterTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const SolutionHintTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const BranchPrioritiesTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const LazyConstraintsTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const IpMultipleSolutionsTestParams &params)
 
std::ostream & operator<< (std::ostream &ostr, const SolveResultSupport &solve_result_support)
 
std::ostream & operator<< (std::ostream &ostr, const ParameterSupport &param_support)
 
std::ostream & operator<< (std::ostream &ostr, const IpParameterTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const LargeInstanceTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const LogicalConstraintTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const LpIncompleteSolveTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const LpModelSolveParametersTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const LpParameterTestParams &params)
 
std::ostream & operator<< (std::ostream &out, const SimpleLpTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const SimpleMipTestParameters &params)
 
<=x<=1 IncrementalMipTest::IncrementalMipTest() :model_("incremental_solve_test"), x_(model_.AddContinuousVariable(0.0, 1.0, "x")), y_(model_.AddIntegerVariable(0.0, 2.0, "y")), c_(model_.AddLinearConstraint(0<=x_+y_<=1.5, "c")) { model_.Maximize(3.0 *x_+2.0 *y_+0.1);solver_=NewIncrementalSolver(&model_, TestedSolver()).value();const SolveResult first_solve=solver_->Solve().value();CHECK(first_solve.has_primal_feasible_solution());CHECK_LE(std::abs(first_solve.objective_value() - 3.6), kTolerance)<< first_solve.objective_value();} namespace { TEST_P(SimpleMipTest, OneVarMax) { Model model;const Variable x=model.AddVariable(0.0, 4.0, false, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, OneVarMin) { Model model;const Variable x=model.AddVariable(-2.4, 4.0, false, "x");model.Minimize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(-4.8));EXPECT_THAT(result.variable_values(), IsNear({{x, -2.4}}));} TEST_P(SimpleMipTest, OneIntegerVar) { Model model;const Variable x=model.AddVariable(0.0, 4.5, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, SimpleLinearConstraint) { Model model;const Variable x=model.AddBinaryVariable("x");const Variable y=model.AddBinaryVariable("y");model.Maximize(2.0 *x+y);model.AddLinearConstraint(0.0<=x+y<=1.5, "c");ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(2.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 1}, {y, 0}}));} TEST_P(SimpleMipTest, Unbounded) { Model model;const Variable x=model.AddVariable(0.0, kInf, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));if(GetParam().report_unboundness_correctly) { ASSERT_THAT(result, TerminatesWithOneOf({TerminationReason::kUnbounded, TerminationReason::kInfeasibleOrUnbounded}));} else { ASSERT_THAT(result, TerminatesWith(TerminationReason::kOtherError));} } TEST_P(SimpleMipTest, Infeasible) { Model model;const Variable x=model.AddVariable(0.0, 3.0, true, "x");model.Maximize(2.0 *x);model.AddLinearConstraint(x >=4.0);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, TerminatesWith(TerminationReason::kInfeasible));} TEST_P(SimpleMipTest, FractionalBoundsContainNoInteger) { if(GetParam().solver_type==SolverType::kGurobi) { GTEST_SKIP()<< "TODO(b/272298816): Gurobi bindings are broken here.";} Model model;const Variable x=model.AddIntegerVariable(0.5, 0.6, "x");model.Maximize(x);EXPECT_THAT(Solve(model, GetParam().solver_type), IsOkAndHolds(TerminatesWith(TerminationReason::kInfeasible)));} TEST_P(IncrementalMipTest, EmptyUpdate) { ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(3.6));EXPECT_THAT(result.variable_values(), IsNear({{x_, 0.5}, {y_, 1.0}}));} TEST_P(IncrementalMipTest, MakeContinuous) { model_.set_continuous(y_);ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(4.1));EXPECT_THAT(result.variable_values(), IsNear({{x_, 1.0}, {y_, 0.5}}));} TEST_P(IncrementalMipTest, DISABLED_MakeContinuousWithNonIntegralBounds) { solver_.reset();Model model("bounds");const Variable x=model.AddIntegerVariable(0.5, 1.5, "x");model.Maximize(x);ASSERT_OK_AND_ASSIGN(const auto solver, NewIncrementalSolver(&model, TestedSolver()));ASSERT_THAT(solver->Solve(), IsOkAndHolds(IsOptimal(1.0)));model.set_continuous(x);ASSERT_THAT(solver->Update(), IsOkAndHolds(DidUpdate()));ASSERT_THAT(solver-> SolveWithoutUpdate ()
 
<=x<=1 IncrementalMipTest::IncrementalMipTest() :model_("incremental_solve_test"), x_(model_.AddContinuousVariable(0.0, 1.0, "x")), y_(model_.AddIntegerVariable(0.0, 2.0, "y")), c_(model_.AddLinearConstraint(0<=x_+y_<=1.5, "c")) { model_.Maximize(3.0 *x_+2.0 *y_+0.1);solver_=NewIncrementalSolver(&model_, TestedSolver()).value();const SolveResult first_solve=solver_->Solve().value();CHECK(first_solve.has_primal_feasible_solution());CHECK_LE(std::abs(first_solve.objective_value() - 3.6), kTolerance)<< first_solve.objective_value();} namespace { TEST_P(SimpleMipTest, OneVarMax) { Model model;const Variable x=model.AddVariable(0.0, 4.0, false, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, OneVarMin) { Model model;const Variable x=model.AddVariable(-2.4, 4.0, false, "x");model.Minimize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(-4.8));EXPECT_THAT(result.variable_values(), IsNear({{x, -2.4}}));} TEST_P(SimpleMipTest, OneIntegerVar) { Model model;const Variable x=model.AddVariable(0.0, 4.5, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, SimpleLinearConstraint) { Model model;const Variable x=model.AddBinaryVariable("x");const Variable y=model.AddBinaryVariable("y");model.Maximize(2.0 *x+y);model.AddLinearConstraint(0.0<=x+y<=1.5, "c");ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(2.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 1}, {y, 0}}));} TEST_P(SimpleMipTest, Unbounded) { Model model;const Variable x=model.AddVariable(0.0, kInf, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));if(GetParam().report_unboundness_correctly) { ASSERT_THAT(result, TerminatesWithOneOf({TerminationReason::kUnbounded, TerminationReason::kInfeasibleOrUnbounded}));} else { ASSERT_THAT(result, TerminatesWith(TerminationReason::kOtherError));} } TEST_P(SimpleMipTest, Infeasible) { Model model;const Variable x=model.AddVariable(0.0, 3.0, true, "x");model.Maximize(2.0 *x);model.AddLinearConstraint(x >=4.0);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, TerminatesWith(TerminationReason::kInfeasible));} TEST_P(SimpleMipTest, FractionalBoundsContainNoInteger) { if(GetParam().solver_type==SolverType::kGurobi) { GTEST_SKIP()<< "TODO(b/272298816): Gurobi bindings are broken here.";} Model model;const Variable x=model.AddIntegerVariable(0.5, 0.6, "x");model.Maximize(x);EXPECT_THAT(Solve(model, GetParam().solver_type), IsOkAndHolds(TerminatesWith(TerminationReason::kInfeasible)));} TEST_P(IncrementalMipTest, EmptyUpdate) { ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(3.6));EXPECT_THAT(result.variable_values(), IsNear({{x_, 0.5}, {y_, 1.0}}));} TEST_P(IncrementalMipTest, MakeContinuous) { model_.set_continuous(y_);ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(4.1));EXPECT_THAT(result.variable_values(), IsNear({{x_, 1.0}, {y_, 0.5}}));} TEST_P(IncrementalMipTest, DISABLED_MakeContinuousWithNonIntegralBounds) { solver_.reset();Model model("bounds");const Variable x=model.AddIntegerVariable(0.5, 1.5, "x");model.Maximize(x);ASSERT_OK_AND_ASSIGN(const auto solver, NewIncrementalSolver(&model, TestedSolver()));ASSERT_THAT(solver->Solve(), IsOkAndHolds(IsOptimal(1.0)));model.set_continuous(x);ASSERT_THAT(solver->Update(), IsOkAndHolds(DidUpdate()));ASSERT_THAT(solver-> IsOkAndHolds (IsOptimal(1.5)))
 
model Minimize (x)
 
 ASSERT_THAT (solver->Update(), IsOkAndHolds(DidUpdate()))
 
 ASSERT_THAT (solver->SolveWithoutUpdate(), IsOkAndHolds(IsOptimal(0.5)))
 
 TEST_P (IncrementalMipTest, MakeIntegralWithNonIntegralBounds)
 
 TEST_P (IncrementalMipTest, MakeInteger)
 
 TEST_P (IncrementalMipTest, ObjDir)
 
 TEST_P (IncrementalMipTest, ObjOffset)
 
 TEST_P (IncrementalMipTest, LinearObjCoef)
 
 TEST_P (IncrementalMipTest, VariableLb)
 
 TEST_P (IncrementalMipTest, VariableUb)
 
 TEST_P (IncrementalMipTest, LinearConstraintLb)
 
 TEST_P (IncrementalMipTest, LinearConstraintUb)
 
 TEST_P (IncrementalMipTest, LinearConstraintCoefficient)
 
 TEST_P (IncrementalMipTest, AddVariable)
 
 TEST_P (IncrementalMipTest, AddLinearConstraint)
 
 TEST_P (IncrementalMipTest, DeleteVariable)
 
 TEST_P (IncrementalMipTest, DeleteLinearConstraint)
 
 TEST_P (IncrementalMipTest, ChangeBoundsWithTemporaryInversion)
 
std::ostream & operator<< (std::ostream &out, const MultiObjectiveTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const QcTestParameters &params)
 
std::string ToString (QpSupportType qp_support)
 
std::ostream & operator<< (std::ostream &out, const QpTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const SecondOrderConeTestParameters &params)
 
std::ostream & operator<< (std::ostream &out, const StatusTestParameters &params)
 
std::unique_ptr< ModelSmallModel (const bool integer)
 
std::unique_ptr< ModelDenseIndependentSet (const bool integer, const int n)
 
ModelSolveParameters::SolutionHint DenseIndependentSetHint5 (const Model &model)
 
std::unique_ptr< ModelIndependentSetCompleteGraph (const bool integer, const int n)
 
 MATH_OPT_REGISTER_SOLVER (SOLVER_TYPE_CP_SAT, CpSatSolver::New)
 
template<typename IndexType >
void UpdateIdIndexMap (glop::StrictITIVector< IndexType, bool > indices_to_delete, IndexType num_indices, absl::flat_hash_map< int64_t, IndexType > &id_index_map)
 
template<typename IndexType >
SparseDoubleVectorProto FillSparseDoubleVector (absl::Span< const int64_t > ids_in_order, const absl::flat_hash_map< int64_t, IndexType > &id_map, const glop::StrictITIVector< IndexType, glop::Fractional > &values, const SparseVectorFilterProto &filter)
 
template<typename ValueType >
BasisStatusProto FromGlopBasisStatus (const ValueType glop_basis_status)
 ValueType should be glop's VariableStatus or ConstraintStatus.
 
template<typename IndexType , typename ValueType >
SparseBasisStatusVector FillSparseBasisStatusVector (absl::Span< const int64_t > ids_in_order, const absl::flat_hash_map< int64_t, IndexType > &id_map, const glop::StrictITIVector< IndexType, ValueType > &values)
 
template<typename ValueType >
ValueType ToGlopBasisStatus (const BasisStatusProto basis_status)
 ValueType should be glop's VariableStatus or ConstraintStatus.
 
template<typename T >
std::vector< int64_t > GetSortedIs (const absl::flat_hash_map< int64_t, T > &id_map)
 
template<typename T >
glop::StrictITIVector< T, int64_t > IndexToId (const absl::flat_hash_map< int64_t, T > &id_map)
 
double WorstGLPKDualBound (const bool is_maximize, const double objective_value, const double relative_gap_limit)
 
absl::StatusOr< std::optional< GlpkRay > > GlpkComputeUnboundRay (glp_prob *const problem)
 
GScipParameters::MetaParamValue ConvertMathOptEmphasis (EmphasisProto emphasis)
 
absl::StatusOr< GRBenvUniquePtrGurobiNewPrimaryEnv (const std::optional< GurobiIsvKey > &isv_key)
 
std::vector< bool > EventToGurobiWhere (const absl::flat_hash_set< CallbackEventProto > &events)
 
absl::Status GurobiCallbackImpl (const Gurobi::CallbackContext &context, const GurobiCallbackInput &callback_input, MessageCallbackData &message_callback_data, SolveInterrupter *const local_interrupter)
 
void GurobiCallbackImplFlush (const GurobiCallbackInput &callback_input, MessageCallbackData &message_callback_data)
 
absl::StatusOr< GRBenvUniquePtrNewPrimaryEnvironment (std::optional< GurobiInitializerProto::ISVKey > proto_isv_key)
 
 MATH_OPT_REGISTER_SOLVER (SOLVER_TYPE_HIGHS, HighsSolver::New)
 
 MATH_OPT_REGISTER_SOLVER (SOLVER_TYPE_PDLP, PdlpSolver::New)
 
template<typename V , typename C >
MemberPointerValueType (V C::*)
 
template<typename V , typename C >
MemberPointerClassType (V C::*)
 
template<auto PointerToMember, typename BaseIter >
auto MakeUpdateDataFieldIterator (BaseIter base_iter)
 
template<auto PointerToMember, typename UpdateTrackers >
auto MakeUpdateDataFieldRange (const UpdateTrackers &trackers)
 
 DEFINE_STRONG_INT_TYPE (VariableId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (AuxiliaryObjectiveId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (LinearConstraintId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (QuadraticConstraintId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (SecondOrderConeConstraintId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (Sos1ConstraintId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (Sos2ConstraintId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (IndicatorConstraintId, int64_t)
 
 DEFINE_STRONG_INT_TYPE (UpdateTrackerId, int64_t)
 
template<typename T >
iterator_range< T > make_range (T x, T y)
 
template<typename T >
iterator_range< T > make_range (std::pair< T, T > p)
 
template<typename Collection >
auto collection_to_range (Collection &c)
 
template<typename T >
std::string StreamToString (const T &value)
 
absl::Span< const FileFormatAllFileFormats ()
 
std::string AbslUnparseFlag (const FileFormat f)
 
std::ostream & operator<< (std::ostream &out, const FileFormat f)
 
bool AbslParseFlag (const absl::string_view text, FileFormat *const f, std::string *const error)
 
absl::flat_hash_map< absl::string_view, FileFormatExtensionToFileFormat ()
 
std::optional< FileFormatFormatFromFilePath (absl::string_view file_path)
 
std::optional< FileFormatFormatFromFlagOrFilePath (const std::optional< FileFormat > format_flag_value, const absl::string_view file_path)
 
std::string OptionalFormatFlagPossibleValuesList ()
 
std::string FormatFlagPossibleValuesList ()
 
absl::StatusOr< std::pair< ModelProto, std::optional< SolutionHintProto > > > ReadModel (const absl::string_view file_path, const FileFormat format)
 
absl::Status WriteModel (const absl::string_view file_path, const ModelProto &model_proto, const std::optional< SolutionHintProto > &hint_proto, const FileFormat format)
 
absl::Status ValidateFeasibilityStatus (const FeasibilityStatusProto &status)
 
absl::Status ValidateProblemStatus (const ProblemStatusProto &status)
 
absl::Status CheckPrimalStatusIs (const ProblemStatusProto &status, const FeasibilityStatusProto required_status)
 Assumes ValidateProblemStatus(status) is ok.
 
absl::Status CheckPrimalStatusIsNot (const ProblemStatusProto &status, const FeasibilityStatusProto forbidden_status)
 Assumes ValidateProblemStatus(status) is ok.
 
absl::Status CheckDualStatusIsNot (const ProblemStatusProto &status, const FeasibilityStatusProto forbidden_status)
 Assumes ValidateProblemStatus(status) is ok.
 
absl::Status CheckDualStatusIs (const ProblemStatusProto &status, const FeasibilityStatusProto required_status, const bool primal_or_dual_infeasible_also_ok)
 Assumes ValidateProblemStatus(status) is ok.
 
absl::Status ValidateObjectiveBounds (const ObjectiveBoundsProto &bounds)
 
absl::Status CheckFinitePrimalBound (const ObjectiveBoundsProto &bounds)
 
absl::Status ValidateBoundStatusConsistency (const ObjectiveBoundsProto &objective_bounds, const ProblemStatusProto &status, bool is_maximize)
 
absl::Status ValidateCallbackRegistration (const CallbackRegistrationProto &callback_registration, const ModelSummary &model_summary)
 Checks that CallbackRegistrationProto is valid given a valid model summary.
 
absl::Status ValidateCallbackDataProto (const CallbackDataProto &cb_data, const CallbackRegistrationProto &callback_registration, const ModelSummary &model_summary)
 
absl::Status ValidateCallbackResultProto (const CallbackResultProto &callback_result, const CallbackEventProto callback_event, const CallbackRegistrationProto &callback_registration, const ModelSummary &model_summary)
 
absl::Status CheckRegisteredCallbackEvents (const CallbackRegistrationProto &registration, const absl::flat_hash_set< CallbackEventProto > &supported_events)
 
absl::Status CheckIdsRangeAndStrictlyIncreasing (absl::Span< const int64_t > ids)
 
absl::Status CheckIdsSubset (absl::Span< const int64_t > ids, const IdNameBiMap &universe, std::optional< int64_t > upper_bound)
 
absl::Status CheckIdsSubset (absl::Span< const int64_t > ids, const IdNameBiMap &universe, absl::string_view ids_description, absl::string_view universe_description)
 
absl::Status CheckIdsIdentical (absl::Span< const int64_t > first_ids, const IdNameBiMap &second_ids, absl::string_view first_description, absl::string_view second_description)
 first_ids and second_ids must include distinct ids.
 
absl::Status ValidateModelSubset (const ModelSubsetProto &model_subset, const ModelSummary &model_summary)
 
absl::Status ValidateComputeInfeasibleSubsystemResult (const ComputeInfeasibleSubsystemResultProto &result, const ModelSummary &model_summary)
 
absl::Status ValidateComputeInfeasibleSubsystemResultNoModel (const ComputeInfeasibleSubsystemResultProto &result)
 Validates the internal consistency of the fields.
 
absl::Status ValidateLinearExpression (const LinearExpressionProto &expression, const IdNameBiMap &variable_universe)
 
absl::Status ValidateSparseVectorFilter (const SparseVectorFilterProto &v, const IdNameBiMap &valid_ids)
 
absl::Status ValidateModelSolveParameters (const ModelSolveParametersProto &parameters, const ModelSummary &model_summary)
 
absl::StatusOr< ModelSummaryValidateModel (const ModelProto &model, const bool check_names)
 
absl::Status ValidateModelUpdate (const ModelUpdateProto &model_update, ModelSummary &model_summary)
 
absl::Status ValidateSolutions (const google::protobuf::RepeatedPtrField< SolutionProto > &solutions, const ModelSolveParametersProto &parameters, const ModelSummary &model_summary)
 
absl::Status CheckHasPrimalSolution (const SolveResultProto &result)
 Returns absl::Ok only if a primal feasible solution is available.
 
absl::Status CheckPrimalSolutionAndTerminationConsistency (const TerminationProto &termination, const google::protobuf::RepeatedPtrField< SolutionProto > &solutions, const bool maximize)
 
absl::Status CheckDualSolutionAndStatusConsistency (const TerminationProto &termination, const google::protobuf::RepeatedPtrField< SolutionProto > &solutions, const bool maximize)
 
absl::Status ValidateResult (const SolveResultProto &result, const ModelSolveParametersProto &parameters, const ModelSummary &model_summary)
 Validates the input result.
 
absl::Status CheckScalarNoNanNoInf (const double d)
 
absl::Status CheckScalar (double value, const DoubleOptions &options)
 Checks value is not NaN and satisfies the additional conditions in options.
 
absl::Status ValidateSolution (const SolutionProto &solution, const ModelSolveParametersProto &parameters, const ModelSummary &model_summary)
 
absl::Status ValidatePrimalSolutionVector (const SparseDoubleVectorProto &vector, const SparseVectorFilterProto &filter, const ModelSummary &model_summary)
 
absl::Status ValidatePrimalSolution (const PrimalSolutionProto &primal_solution, const SparseVectorFilterProto &filter, const ModelSummary &model_summary)
 
absl::Status ValidatePrimalRay (const PrimalRayProto &primal_ray, const SparseVectorFilterProto &filter, const ModelSummary &model_summary)
 
absl::Status ValidateDualSolution (const DualSolutionProto &dual_solution, const ModelSolveParametersProto &parameters, const ModelSummary &model_summary)
 
absl::Status ValidateDualRay (const DualRayProto &dual_ray, const ModelSolveParametersProto &parameters, const ModelSummary &model_summary)
 
absl::Status SparseBasisStatusVectorIsValid (const SparseVectorView< int > &status_vector_view)
 
absl::Status ValidateBasis (const BasisProto &basis, const ModelSummary &model_summary, const bool check_dual_feasibility)
 
absl::Status ValidateSolveParameters (const SolveParametersProto &parameters)
 
absl::Status ValidateSolveStats (const SolveStatsProto &solve_stats)
 
absl::Status SparseMatrixValid (const SparseDoubleMatrixProto &matrix, const bool enforce_upper_triangular)
 
absl::Status SparseMatrixIdsAreKnown (const SparseDoubleMatrixProto &matrix, const IdNameBiMap &row_ids, const IdNameBiMap &column_ids)
 
template<typename T >
absl::Status CheckIdsAndValuesSize (const SparseVectorView< T > &vector_view, absl::string_view value_name="values")
 
template<typename T , typename = std::enable_if_t<!std::is_floating_point<T>::value>>
absl::Status CheckValues (const SparseVectorView< T > &vector_view, absl::string_view value_name="values")
 
template<typename T , typename = std::enable_if_t<!std::is_floating_point<T>::value>>
absl::Status CheckIdsAndValues (const SparseVectorView< T > &vector_view, absl::string_view value_name="values")
 
template<typename T , typename = std::enable_if_t<std::is_floating_point<T>::value>>
absl::Status CheckValues (const SparseVectorView< T > &vector_view, const DoubleOptions &options, absl::string_view value_name="values")
 
template<typename T , typename = std::enable_if_t<std::is_floating_point<T>::value>>
absl::Status CheckIdsAndValues (const SparseVectorView< T > &vector_view, const DoubleOptions &options, absl::string_view value_name="values")
 
absl::Status ValidateTermination (const TerminationProto &termination, bool is_maximize)
 Checks all messages are valid and compatible.
 

Variables

constexpr absl::string_view kDeletedConstraintDefaultDescription
 
constexpr double kInf = std::numeric_limits<double>::infinity()
 
constexpr std::size_t kMaxNonBinaryIndicatorVariables = 10
 The maximum number of non-binary indicator variables to report.
 
constexpr std::size_t kMaxInvertedBounds = 10
 The maximum number of variables/constraints with inverted bounds to report.
 
absl::string_view detail = {})
 
template<typename T >
constexpr bool is_key_type_v
 
constexpr double kMatcherDefaultTolerance = 1e-5
 
For infeasible and unbounded problems
 
For infeasible and unbounded see Not checked if options check_solutions_if_inf_or_unbounded and the If options first_solution_only is false
 problem is infeasible or unbounded (default).
 
For infeasible and unbounded see Not checked if options check_solutions_if_inf_or_unbounded and the If options first_solution_only is check the entire list of Dual solution is not checked if options check_dual
 solutions matches in the same order.
 
constexpr absl::string_view kDeletedObjectiveDefaultDescription
 
When unset
 
When the underlying default is used When the feature cannot be turned off
 
When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by default
 
When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is supported
 mapped to kMedium.
 
When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is kLow
 
When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is kMedium
 
When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is kHigh
 
constexpr double kMaxIntegralityTolerance = 0.25
 
x InconsistentVariableBoundsAndLinearConstraint
 
const Variable x = model.AddContinuousVariable(-kInf, 0.0)
 
const LinearConstraint c = model.AddLinearConstraint(x >= 1.0)
 
x InconsistentVariableBoundsAndQuadraticConstraint
 
x InconsistentSecondOrderConeConstraint
 
x InconsistentSecondOrderConeConstraintWithExpressionUnderNorm
 
x InconsistentSecondOrderConeConstraintWithExpressionInUpperBound
 
x InconsistentIndicatorConstraint
 
constexpr double kTolerance = 1e-6
 
constexpr absl::string_view kNoMultiObjectiveSupportMessage
 
constexpr std::string_view kNoQpSupportMessage
 
constexpr std::string_view kNoNonDiagonalQpSupportMessage
 
constexpr ObjectiveId kPrimaryObjectiveId
 
*If primal bound
 
*If primal *dual status is infeasible
 
*If primal *dual status is and *dual bound is equal to primal bound *is finite
 

Detailed Description

An object oriented wrapper for quadratic constraints in ModelStorage.

Classes for modeling sparse matrices.

Holds MathOpt models that are shared across tests from this directory.

This file contains primal solution improvement heuristics.

Tools to extract some sub-components of sparse matrices.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. IWYU pragma: private, include "ortools/math_opt/cpp/math_opt.h" IWYU pragma: friend "ortools/math_opt/cpp/.*"

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. IWYU pragma: private, include "ortools/math_opt/cpp/math_opt.h" IWYU pragma: friend "ortools/math_opt/cpp/.*" The MathOpt C++ API defines enums that are used in parameters and results and that corresponds to Proto generated enums.

The tools in this header make sure the C++ enums provide the following features:

  • enumerating all enum values
  • bidirectional string conversion
  • operator<< stream support
  • bidirectional proto generated enum conversion

Example declaration:

my_file.proto: enum MyEnumProto { MY_ENUM_UNSPECIFIED = 0; MY_ENUM_FIRST_VALUE = 1; MY_ENUM_SECOND_VALUE = 2; }

my_file.h: enum class MyEnum { kFirstValue = MY_ENUM_FIRST_VALUE, kSecondValue = MY_ENUM_SECOND_VALUE, };

MATH_OPT_DEFINE_ENUM(MyEnum, MY_ENUM_UNSPECIFIED);
#define MATH_OPT_DEFINE_ENUM(CppEnum, proto_unspecified_value)
Definition enums.h:325

my_file.cc: std::optional<absl::string_view> Enum<MyEnum>::ToOptString(MyEnum value) { switch (value) { case MyEnum::kFirstValue: return "first_value"; case MyEnum::kSecondValue: return "second_value"; } return std::nullopt; }

absl::Span<const MyEnum> Enum<MyEnum>::AllValues() {
static constexpr MyEnum kMyEnumValues[] = {MyEnum::kFirstValue,
MyEnum::kSecondValue};
return absl::MakeConstSpan(kMyEnumValues);
}
static absl::Span< const E > AllValues()
Returns all possible values of the enum.

my_file_test.cc: #include "ortools/math_opt/cpp/enums_testing.h" ... INSTANTIATE_TYPED_TEST_SUITE_P(MyEnum, EnumTest, MyEnum);

Once this is done, the following functions are available:

  • absl::Span<MyEnum> Enum<MyEnum>::AllValues()
  • optional<MyEnum> EnumFromString<MyEnum>(string_view)
  • string_view EnumToString(MyEnum)
  • optional<string_view> EnumToOptString(MyEnum)
  • optional<MyEnum> EnumFromProto(MyEnumProto)
  • MyEnumProto EnumToProto(optional<MyEnum>)
  • MyEnumProto EnumToProto(MyEnum)
  • operator<<(MyEnum)
  • operator<<(std::optional<MyEnum>)

See examples of usage in the Enum struct documentation below.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. IWYU pragma: private, include "ortools/math_opt/cpp/math_opt.h" IWYU pragma: friend "ortools/math_opt/cpp/.*" This header defines the common properties of "key types" and some related constants.

Key types are types that are used as identifiers in the C++ interface where the ModelStorage is using typed integers. They are pairs of (storage, typed_index) where storage is a pointer on an ModelStorage and typed_index is the typed integer type used in ModelStorage (or a pair of typed integers for QuadraticTermKey).

A key type K must match the following requirements:

  • K::IdType is a value type used for indices.
  • K has a constructor K(const ModelStorage*, K::IdType).
  • K is a value-semantic type.
  • K has a function with signature K::IdType K::typed_id() const.
  • K has a function with signature const ModelStorage* K::storage() const. It must return a non-null pointer.
  • K::IdType is a valid key for absl::flat_hash_map or absl::flat_hash_set (supports hash and ==).
  • the is_key_type_v<> below should include them.

Printing

absl::flat_hash_map<K, double> Matchers

Matcher helpers

Primal Ray Matcher

Dual Ray Matcher

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. IWYU pragma: private, include "ortools/math_opt/cpp/math_opt.h" IWYU pragma: friend "ortools/math_opt/cpp/.*"

An object oriented wrapper for objectives in ModelStorage.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Parses a the model in "CPLEX LP" format using SCIP.

Note
../../lp_data/lp_parser.h parses ".lp" files in the LPSolve version of the LP format, which is different from the (now) more standard CPLEX version of the LP format. These formats are not compatible. See https://lpsolve.sourceforge.net/5.5/lp-format.htm https://lpsolve.sourceforge.net/5.5/CPLEX-format.htm for a comparison.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Functions to remove names from models and updates.

Input models can contain duplicated names which MathOpt solvers will refuse. The functions in this header can be use to mitigate that.

These functions can also be used to anonymize models before saving them.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Methods for manipulating LinearExpressions.

Why in labs? Lots of users seem to need this (e.g. for big-M calculations), but there are several possible algorithms, and it is not clear what, if anything, would be used widely. The function also makes many assumptions on the input that are not easy to verify and can lead to confusing errors, it is worth seeing if the API can be hardened a bit.

LargeInstanceIpParameterTest

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Todo
(b/178702980): this should not be needed IWYU pragma: no_include <type_traits>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This header defines primal/dual unboundness ray computation functions for GLPK solver. They use the index space of the computation form of the model as defined in operations_research/glpk/glpk_computational_form.h.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Google C++ bindings for Gurobi C API.

Attempts to be as close to the Gurobi C API as possible, with the following differences:

  • Use destructors to automatically clean up the environment and model.
  • Use absl::Status to propagate errors instead of int gurobi error codes.
  • Use absl::StatusOr instead of output arguments.
  • Use absl::Span<T> instead of T* and size for array args.
  • Use std::string instead of null terminated char* for string values (note that attribute names are still char*).
  • When setting array data, accept const data (absl::Span<const T>).
  • Callbacks are passed as an argument to optimize and then are cleared.
  • Callbacks propagate errors with status.
  • There is no distinction between a GRBmodel and the GRBenv created for a model, they are jointly captured by the newly defined Gurobi object.
  • Parameters are set on the Gurobi class rather than on a GRBenv. We do not provide an API fo setting parameters on the primary environment, only on the child environment created by GRBnewmodel (for details see https://www.gurobi.com/documentation/9.1/refman/c_newmodel.html ).

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Unimplemented features:

  • Quadratic objective
  • Todo
    (b/272767311): initial basis, more precise returned basis.

Solutions & Rays

Typedef Documentation

◆ Callback

Definition at line 93 of file callback.h.

◆ GRBenvUniquePtr

Unique pointer to a GRBenv. It destroys the environment on destruction calling GRBfreeenv. Most users will not use this directly.

Definition at line 59 of file g_gurobi.h.

◆ LinearConstraintMap

template<typename V >
using operations_research::math_opt::LinearConstraintMap = absl::flat_hash_map<LinearConstraint, V>

Definition at line 95 of file linear_constraint.h.

◆ MessageCallback

using operations_research::math_opt::MessageCallback = std::function<void(const std::vector<std::string>&)>

Callback function for messages callback sent by the solver.

Each message represents a single output line from the solver, and each message does not contain any '
' character in it.

Thread-safety: a callback may be called concurrently from multiple threads. The users is expected to use proper synchronization primitives to deal with that.

Definition at line 40 of file message_callback.h.

◆ MockSolveFunction

◆ ObjectiveId

using operations_research::math_opt::ObjectiveId = std::optional<AuxiliaryObjectiveId>

nullopt denotes the primary objective.

Definition at line 31 of file model_storage_types.h.

◆ ObjectiveMap

template<typename V >
using operations_research::math_opt::ObjectiveMap = absl::flat_hash_map<Objective, V>

Definition at line 123 of file objective.h.

◆ ProtoEnumIsValid

Definition at line 161 of file enums.h.

◆ QuadraticProductId

using operations_research::math_opt::QuadraticProductId = std::pair<VariableId, VariableId>

Id type used for quadratic terms, i.e. products of two variables.

Definition at line 641 of file variable_and_expressions.h.

◆ QuadraticTermMap

template<typename V >
using operations_research::math_opt::QuadraticTermMap = absl::flat_hash_map<QuadraticTermKey, V>

Definition at line 731 of file variable_and_expressions.h.

◆ Range

using operations_research::math_opt::Range = std::pair<double, double>

A range of values, first is the minimum, second is the maximum.

Definition at line 27 of file statistics.h.

◆ SolveFunction

Initial value:

The type of a standard function with the same signature as Solve() above.

If you want mock the Solve() for testing, you can take a SolveFunction as an argument, e.g. absl::Status DoMySolve(SolveFunction solve_function=Solve) { Model model; ///< fill in model... SolveArguments args; SolveInitArguments init_args; ASSIGN_OR_RETURN( const SolveResult result, solve_function(model, SolverType::kGscip, args, init_args)); ///< process result... return absl::OkStatus(); }

Definition at line 82 of file solve.h.

◆ Sos1ConstraintData

Definition at line 98 of file storage.h.

◆ Sos2ConstraintData

Definition at line 99 of file storage.h.

◆ sparse_value_type

Initial value:
typename std::remove_reference<
decltype(SparseVector().values())>::type::value_type

Recovers the values-type of a SparseVector type like SparseDoubleVector or SparseBoolVector.

Definition at line 70 of file sparse_vector_view.h.

◆ SparseSubmatrixRowsView

Initial value:
std::vector<std::pair<int64_t, SparseVectorView<double>>>

A vector that contains one pair (row_id, columns_coefficients) per row, sorted by row_id. The columns_coefficients are views.

Definition at line 31 of file sparse_submatrix.h.

◆ VariableMap

template<typename V >
using operations_research::math_opt::VariableMap = absl::flat_hash_map<Variable, V>

Definition at line 187 of file variable_and_expressions.h.

Enumeration Type Documentation

◆ BasisStatus

enum class operations_research::math_opt::BasisStatus : int8_t
strong

Status of a variable/constraint in a LP basis.

Enumerator
kFree 

The variable/constraint is free (it has no finite bounds).

kAtLowerBound 

The variable/constraint is at its lower bound (which must be finite).

kAtUpperBound 

The variable/constraint is at its upper bound (which must be finite).

kFixedValue 

The variable/constraint has identical finite lower and upper bounds.

kBasic 

The variable/constraint is basic.

Definition at line 30 of file basis_status.h.

◆ CallbackEvent

The supported events during a solve for callbacks.

Enumerator
kPresolve 

The solver is currently running presolve.

This event is supported for SolverType::kGurobi only.

kSimplex 

The solver is currently running the simplex method.

This event is supported for SolverType::kGurobi only.

kMip 

The solver is in the MIP loop (called periodically before starting a new node). Useful for early termination. Note that this event does not provide information on LP relaxations nor about new incumbent solutions.

This event is supported for MIP models with SolverType::kGurobi only.

kMipSolution 

Called every time a new MIP incumbent is found.

This event is fully supported for MIP models by SolverType::kGurobi. SolverType::kCpSat has partial support: you can view the solutions and request termination, but you cannot add lazy constraints. Other solvers don't support this event.

kMipNode 

Called inside a MIP node. Note that there is no guarantee that the callback function will be called on every node. That behavior is solver-dependent.

Disabling cuts using SolveParameters may interfere with this event being called and/or adding cuts at this event, the behavior is solver specific.

This event is supported for MIP models with SolverType::kGurobi only.

kBarrier 

Called in each iterate of an interior point/barrier method.

This event is supported for SolverType::kGurobi only.

Definition at line 96 of file callback.h.

◆ Emphasis

never give an error, and will map onto their best match.

Enumerator
kOff 
kLow 
kMedium 
kHigh 
kVeryHigh 

Definition at line 179 of file parameters.h.

◆ FeasibilityStatus

Problem feasibility status as claimed by the solver (solver is not required to return a certificate for the claim).

Enumerator
kUndetermined 

Solver does not claim a status.

kFeasible 

Solver claims the problem is feasible.

kInfeasible 

Solver claims the problem is infeasible.

Definition at line 43 of file solve_result.h.

◆ GlpkRayType

The type of the GlpkRay.

Enumerator
kPrimal 

A primal ray.

If x (vector of variables) is a primal feasible solution to a primal unbounded problem and r is the ray, then x' = x + t r is also a primal feasible solution for all t >= 0.

kDual 

A dual ray.

If λ (vector of reduced costs) is a dual feasible solution to a dual unbounded problem and r is the ray, then λ' = λ + t r is also a dual feasible solution for all t >= 0.

Definition at line 33 of file rays.h.

◆ Limit

When a Solve() stops early with TerminationReason kFeasible or kNoSolutionFound, the specific limit that was hit.

Enumerator
kUndetermined 

Used if the underlying solver cannot determine which limit was reached, or as a null value when we terminated not from a limit (e.g. kOptimal).

kIteration 

An iterative algorithm stopped after conducting the maximum number of iterations (e.g. simplex or barrier iterations).

kTime 

The algorithm stopped after a user-specified computation time.

kNode 

A branch-and-bound algorithm stopped because it explored a maximum number of nodes in the branch-and-bound tree.

kSolution 

The algorithm stopped because it found the required number of solutions. This is often used in MIPs to get the solver to return the first feasible solution it encounters.

kMemory 

The algorithm stopped because it ran out of memory.

kCutoff 

The solver was run with a cutoff (e.g. SolveParameters.cutoff_limit was set) on the objective, indicating that the user did not want any solution worse than the cutoff, and the solver concluded there were no solutions at least as good as the cutoff. Typically no further solution information is provided.

kObjective 

The algorithm stopped because it found a solution better than a minimum limit set by the user.

kNorm 

The algorithm stopped because the norm of an iterate became too large.

kInterrupted 

The algorithm stopped because of an interrupt signal or a user interrupt request.

kSlowProgress 

The algorithm stopped because it was unable to continue making progress towards the solution.

kOther 

The algorithm stopped due to a limit not covered by one of the above. Note that kUndetermined is used when the reason cannot be determined, and kOther is used when the reason is known but does not fit into any of the above alternatives.

Definition at line 173 of file solve_result.h.

◆ LPAlgorithm

Selects an algorithm for solving linear programs.

Enumerator
kPrimalSimplex 

The (primal) simplex method. Typically can provide primal and dual solutions, primal/dual rays on primal/dual unbounded problems, and a basis.

kDualSimplex 

The dual simplex method. Typically can provide primal and dual solutions, primal/dual rays on primal/dual unbounded problems, and a basis.

kBarrier 

The barrier method, also commonly called an interior point method (IPM). Can typically give both primal and dual solutions. Some implementations can also produce rays on unbounded/infeasible problems. A basis is not given unless the underlying solver does "crossover" and finishes with simplex.

kFirstOrder 

An algorithm based around a first-order method. These will typically produce both primal and dual solutions, and potentially also certificates of primal and/or dual infeasibility. First-order methods typically will provide solutions with lower accuracy, so users should take care to set solution quality parameters (e.g., tolerances) and to validate solutions.

Definition at line 128 of file parameters.h.

◆ QpSupportType

Enumerator
kNoQpSupport 
kDiagonalQpOnly 
kConvexQp 

Definition at line 26 of file qp_tests.h.

◆ SolutionStatus

Feasibility of a primal or dual solution as claimed by the solver.

Enumerator
kUndetermined 

Solver does not claim a feasibility status.

kFeasible 

Solver claims the solution is feasible.

kInfeasible 

Solver claims the solution is infeasible.

Definition at line 39 of file solution.h.

◆ SolverType

The solvers supported by MathOpt.

Enumerator
kGscip 

Solving Constraint Integer Programs (SCIP) solver (third party).

Supports LP, MIP, and nonconvex integer quadratic problems. No dual data for LPs is returned though. Prefer GLOP for LPs.

kGurobi 

Gurobi solver (third party).

Supports LP, MIP, and nonconvex integer quadratic problems. Generally the fastest option, but has special licensing.

kGlop 

Google's Glop solver.

Supports LP with primal and dual simplex methods.

kCpSat 

Google's CP-SAT solver.

Supports problems where all variables are integer and bounded (or implied to be after presolve). Experimental support to rescale and discretize problems with continuous variables.

kPdlp 

Google's PDLP solver.

Supports LP and convex diagonal quadratic objectives. Uses first order methods rather than simplex. Can solve very large problems.

kGlpk 

GNU Linear Programming Kit (GLPK) (third party).

Supports MIP and LP.

Thread-safety: GLPK use thread-local storage for memory allocations. As a consequence when using IncrementalSolver, the user must make sure that instances are destroyed on the same thread as they are created or GLPK will crash. It seems OK to call IncrementalSolver::Solve() from another thread than the one used to create the Solver but it is not documented by GLPK and should be avoided. Of course these limitations do not apply to the Solve() function that recreates a new GLPK problem in the calling thread and destroys before returning.

When solving a LP with the presolver, a solution (and the unbound rays) are only returned if an optimal solution has been found. Else nothing is returned. See glpk-5.0/doc/glpk.pdf page #40 available from glpk-5.0.tar.gz for details.

kEcos 

The Embedded Conic Solver (ECOS).

Supports LP and SOCP problems. Uses interior point methods (barrier).

kScs 

The Splitting Conic Solver (SCS) (third party).

Supports LP and SOCP problems. Uses a first-order method.

kHighs 

The HiGHS Solver (third party).

Supports LP and MIP problems (convex QPs are unimplemented).

kSantorini 

MathOpt's reference implementation of a MIP solver.

Slow/not recommended for production. Not an LP solver (no dual information returned).

Definition at line 42 of file parameters.h.

◆ SupportType

Enumerator
kNotSupported 
kSupported 
kNotImplemented 

Definition at line 317 of file math_opt_proto_utils.h.

◆ TerminationReason

The reason a call to Solve() terminates.

Enumerator
kOptimal 

A provably optimal solution (up to numerical tolerances) has been found.

kInfeasible 

The primal problem has no feasible solutions.

kUnbounded 

The primal problem is feasible and arbitrarily good solutions can be found along a primal ray.

kInfeasibleOrUnbounded 

The primal problem is either infeasible or unbounded. More details on the problem status may be available in termination.problem_status. Note that Gurobi's unbounded status may be mapped here.

kImprecise 

The problem was solved to one of the criteria above (Optimal, Infeasible, Unbounded, or InfeasibleOrUnbounded), but one or more tolerances was not met. Some primal/dual solutions/rays may be present, but either they will be slightly infeasible, or (if the problem was nearly optimal) their may be a gap between the best solution objective and best objective bound.

Users can still query primal/dual solutions/rays and solution stats, but they are responsible for dealing with the numerical imprecision.

kFeasible 

The optimizer reached some kind of limit and a primal feasible solution is returned. See SolveResultProto.limit_detail for detailed description of the kind of limit that was reached.

kNoSolutionFound 

The optimizer reached some kind of limit and it did not find a primal feasible solution. See SolveResultProto.limit_detail for detailed description of the kind of limit that was reached.

kNumericalError 

The algorithm stopped because it encountered unrecoverable numerical error. No solution information is available.

kOtherError 

The algorithm stopped because of an error not covered by one of the statuses defined above. No solution information is available.

Definition at line 124 of file solve_result.h.

Function Documentation

◆ ≤()

x operations_research::math_opt::≤ ( variable bounds)

The entire model is an IIS.

x is integer

The model is: min 0 s.t. x ≥ 1 (linear constraint)

Todo
(b/227217735): Test ranged quadratic constraints when supported.

The model is: min 0 s.t. x² ≥ 1

The model is: min 0 s.t. ||{x}||₂ ≤ 1 An IIS is: ||{x}||₂ ≤ 1

The model is: min 0 s.t. ||{2x}||₂ ≤ 1 An IIS is: ||{2x}||₂ ≤ 1

The model is: min 0 s.t. ||{x}||₂ ≤ 2x - 2 An IIS is: ||{x}||₂ ≤ 2x - 2

An IIS is: {x, y} is SOS1

An IIS is: {x, y, z} is SOS2

The model is: min 0 s.t. x == 1 --> 1 ≤ 0 x is integer

An IIS is: x == 1 --> 1 ≤ 0

◆ ABSL_DEPRECATED()

operations_research::math_opt::ABSL_DEPRECATED ( "Use TerminateForReason(bool, TerminationReasonProto, absl::string_view) " "instead" )

◆ AbslHashValue() [1/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const IndicatorConstraint & constraint )

Definition at line 135 of file indicator_constraint.h.

◆ AbslHashValue() [2/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const LinearConstraint & linear_constraint )

Definition at line 172 of file linear_constraint.h.

◆ AbslHashValue() [3/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const Objective & objective )

Definition at line 213 of file objective.h.

◆ AbslHashValue() [4/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const QuadraticConstraint & quadratic_constraint )

Definition at line 189 of file quadratic_constraint.h.

◆ AbslHashValue() [5/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const QuadraticTermKey & key )

Definition at line 2097 of file variable_and_expressions.h.

◆ AbslHashValue() [6/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const SecondOrderConeConstraint & constraint )

Definition at line 125 of file second_order_cone_constraint.h.

◆ AbslHashValue() [7/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const Sos1Constraint & constraint )

Definition at line 125 of file sos1_constraint.h.

◆ AbslHashValue() [8/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const Sos2Constraint & constraint )

Definition at line 126 of file sos2_constraint.h.

◆ AbslHashValue() [9/9]

template<typename H >
H operations_research::math_opt::AbslHashValue ( H h,
const Variable & variable )

Definition at line 1306 of file variable_and_expressions.h.

◆ AbslParseFlag() [1/6]

bool operations_research::math_opt::AbslParseFlag ( absl::string_view text,
Emphasis * value,
std::string * error )

Parses a flag of type Emphasis.

The expected values are the one returned by EnumToString().

Definition at line 169 of file parameters.cc.

◆ AbslParseFlag() [2/6]

bool operations_research::math_opt::AbslParseFlag ( absl::string_view text,
LPAlgorithm * value,
std::string * error )

Parses a flag of type LPAlgorithm.

The expected values are the one returned by EnumToString().

Definition at line 136 of file parameters.cc.

◆ AbslParseFlag() [3/6]

bool operations_research::math_opt::AbslParseFlag ( absl::string_view text,
SolveParameters * solve_parameters,
std::string * error )

Definition at line 329 of file parameters.cc.

◆ AbslParseFlag() [4/6]

bool operations_research::math_opt::AbslParseFlag ( const absl::string_view text,
FileFormat *const f,
std::string *const error )

Definition at line 79 of file file_format_flags.cc.

◆ AbslParseFlag() [5/6]

bool operations_research::math_opt::AbslParseFlag ( const absl::string_view text,
SolverResources *const solver_resources,
std::string *const error )

Definition at line 49 of file solver_resources.cc.

◆ AbslParseFlag() [6/6]

bool operations_research::math_opt::AbslParseFlag ( absl::string_view text,
SolverType * value,
std::string * error )

Parses a flag of type SolverType.

The expected values are the one returned by EnumToString().

Definition at line 102 of file parameters.cc.

◆ AbslUnparseFlag() [1/6]

std::string operations_research::math_opt::AbslUnparseFlag ( Emphasis value)

Unparses a flag of type Emphasis.

The returned values are the same as EnumToString().

Definition at line 174 of file parameters.cc.

◆ AbslUnparseFlag() [2/6]

std::string operations_research::math_opt::AbslUnparseFlag ( const FileFormat f)

Definition at line 57 of file file_format_flags.cc.

◆ AbslUnparseFlag() [3/6]

std::string operations_research::math_opt::AbslUnparseFlag ( LPAlgorithm value)

Unparses a flag of type LPAlgorithm.

The returned values are the same as EnumToString().

Definition at line 141 of file parameters.cc.

◆ AbslUnparseFlag() [4/6]

std::string operations_research::math_opt::AbslUnparseFlag ( const SolverResources & solver_resources)

Definition at line 68 of file solver_resources.cc.

◆ AbslUnparseFlag() [5/6]

std::string operations_research::math_opt::AbslUnparseFlag ( SolverType value)

Unparses a flag of type SolverType.

The returned values are the same as EnumToString().

Definition at line 107 of file parameters.cc.

◆ AbslUnparseFlag() [6/6]

std::string operations_research::math_opt::AbslUnparseFlag ( SolveParameters solve_parameters)

Definition at line 347 of file parameters.cc.

◆ ActivateDualRay()

bool operations_research::math_opt::ActivateDualRay ( SolverType solver_type,
SolveParameters & params )

Updates the input parameters so that the solver produces a dual ray for infeasible ones. Return true if the solver supports producing dual rays, else returns false.

◆ ActivatePrimalRay()

bool operations_research::math_opt::ActivatePrimalRay ( SolverType solver_type,
SolveParameters & params )

Updates the input parameters so that the solver produces a primal ray for unbounded problems for infeasible ones. Return true if the solver supports producing primal rays, else returns false.

◆ AddRobustConstraint()

void operations_research::math_opt::AddRobustConstraint ( const Model & uncertainty_model,
Variable rhs,
absl::Span< const std::pair< LinearExpression, Variable > > uncertain_coefficients,
Model & main_model )

Uses LP duality to construct an extended formulation of

max_w{ a(w) * x : w in W} <= rhs

where W is described by uncertainty_model (the variables of uncertainty_model are w). All the variables and constraints of the extended formulation are added to main_model.

Requirements:

  • x must be variables of main_model
  • rhs must be a variable of main_model
  • uncertainty_model must be an LP
  • uncertain coefficient a(w)_i for x_i should be a LinearExpression of w.

Input-only arguments:

  • uncertainty_model
  • rhs
  • uncertain_coefficients: pairs [a(w)_i, x_i] for all i Input-output argument:
  • main_model

Definition at line 202 of file dualizer.cc.

◆ AllFileFormats()

absl::Span< const FileFormat > operations_research::math_opt::AllFileFormats ( )

Definition at line 45 of file file_format_flags.cc.

◆ ApplyAllFilters()

void operations_research::math_opt::ApplyAllFilters ( const ModelSolveParametersProto & model_solve_params,
SolutionProto & solution )

Applies the primal, dual and reduced costs filters from model_solve_params to the primal solution variable values, dual solution dual values, and dual solution reduced costs, respectively, and overwriting these values with the results.

Warning
solution is modified in place.
Todo
(b/261603235): this function is not very efficient, decide if this matters.

Definition at line 119 of file math_opt_proto_utils.cc.

◆ ASSERT_THAT() [1/2]

operations_research::math_opt::ASSERT_THAT ( solver-> SolveWithoutUpdate(),
IsOkAndHolds(IsOptimal(0.5))  )

◆ ASSERT_THAT() [2/2]

operations_research::math_opt::ASSERT_THAT ( solver-> Update(),
IsOkAndHolds(DidUpdate())  )

◆ AtomicConstraintNonzeroVariables()

template<typename IdType >
std::vector< Variable > operations_research::math_opt::AtomicConstraintNonzeroVariables ( const ModelStorage & storage,
const IdType id )

Definition at line 42 of file model_util.h.

◆ AtomicConstraints()

template<typename ConstraintType >
std::vector< ConstraintType > operations_research::math_opt::AtomicConstraints ( const ModelStorage & storage)

Duck-types on ConstraintType having a typedef for the associated IdType, and having a (const ModelStorage*, IdType) constructor.

Definition at line 57 of file model_util.h.

◆ AuxiliaryObjectiveValuesFromProto()

absl::StatusOr< absl::flat_hash_map< Objective, double > > operations_research::math_opt::AuxiliaryObjectiveValuesFromProto ( const ModelStorage * model,
const google::protobuf::Map< int64_t, double > & aux_obj_proto )

Returns an absl::flat_hash_map<Objective, double> equivalent to aux_obj_proto.

Requires that (or returns a status error):

  • The keys of aux_obj_proto correspond to objectives in model.
Note
the values of aux_obj_proto are not checked (it may have NaNs).

Definition at line 163 of file sparse_containers.cc.

◆ AuxiliaryObjectiveValuesToProto()

google::protobuf::Map< int64_t, double > operations_research::math_opt::AuxiliaryObjectiveValuesToProto ( const absl::flat_hash_map< Objective, double > & aux_obj_values)

Returns the proto equivalent of auxiliary_obj_values.

Requires that (or will CHECK-fail):

  • The keys of aux_obj_values all correspond to auxiliary objectives.

Definition at line 178 of file sparse_containers.cc.

◆ BasisIs()

testing::Matcher< Basis > operations_research::math_opt::BasisIs ( const Basis & expected)

Definition at line 449 of file matchers.cc.

◆ CheckDualSolutionAndStatusConsistency()

absl::Status operations_research::math_opt::CheckDualSolutionAndStatusConsistency ( const TerminationProto & termination,
const google::protobuf::RepeatedPtrField< SolutionProto > & solutions,
const bool maximize )

Definition at line 204 of file result_validator.cc.

◆ CheckDualStatusIs()

absl::Status operations_research::math_opt::CheckDualStatusIs ( const ProblemStatusProto & status,
FeasibilityStatusProto required_status,
bool primal_or_dual_infeasible_also_ok = false )

Assumes ValidateProblemStatus(status) is ok.

If primal_or_dual_infeasible_also_ok is false, returns absl::Ok only if status.dual_status = required_status. If primal_or_dual_infeasible_also_ok is true, it returns absl::Ok when status.dual_status = required_status and when primal_or_dual_infeasible is true. Assumes validateProblemStatus(status) returns absl::Ok.

ValidateProblemStatus call above guarantees primal and dual statuses are FEASIBILITY_STATUS_UNDETERMINED here.

Definition at line 102 of file bounds_and_status_validator.cc.

◆ CheckDualStatusIsNot()

absl::Status operations_research::math_opt::CheckDualStatusIsNot ( const ProblemStatusProto & status,
FeasibilityStatusProto forbidden_status )

Assumes ValidateProblemStatus(status) is ok.

Returns absl::Ok only if status.dual_status != forbidden_status. Assumes validateProblemStatus(status) returns absl::Ok.

Definition at line 89 of file bounds_and_status_validator.cc.

◆ CheckFinitePrimalBound()

absl::Status operations_research::math_opt::CheckFinitePrimalBound ( const ObjectiveBoundsProto & bounds)

Definition at line 136 of file bounds_and_status_validator.cc.

◆ CheckHasPrimalSolution()

absl::Status operations_research::math_opt::CheckHasPrimalSolution ( const SolveResultProto & result)

Returns absl::Ok only if a primal feasible solution is available.

Definition at line 171 of file result_validator.cc.

◆ CheckIdsAndValues() [1/2]

template<typename T , typename = std::enable_if_t<!std::is_floating_point<T>::value>>
absl::Status operations_research::math_opt::CheckIdsAndValues ( const SparseVectorView< T > & vector_view,
absl::string_view value_name = "values" )

Definition at line 50 of file sparse_vector_validator.h.

◆ CheckIdsAndValues() [2/2]

template<typename T , typename = std::enable_if_t<std::is_floating_point<T>::value>>
absl::Status operations_research::math_opt::CheckIdsAndValues ( const SparseVectorView< T > & vector_view,
const DoubleOptions & options,
absl::string_view value_name = "values" )

Definition at line 73 of file sparse_vector_validator.h.

◆ CheckIdsAndValuesSize()

template<typename T >
absl::Status operations_research::math_opt::CheckIdsAndValuesSize ( const SparseVectorView< T > & vector_view,
absl::string_view value_name = "values" )

Definition at line 30 of file sparse_vector_validator.h.

◆ CheckIdsIdentical()

absl::Status operations_research::math_opt::CheckIdsIdentical ( absl::Span< const int64_t > first_ids,
const IdNameBiMap & second_ids,
absl::string_view first_description,
absl::string_view second_description )

first_ids and second_ids must include distinct ids.

Definition at line 86 of file ids_validator.cc.

◆ CheckIdsRangeAndStrictlyIncreasing()

absl::Status operations_research::math_opt::CheckIdsRangeAndStrictlyIncreasing ( absl::Span< const int64_t > ids)

Checks that the input ids are in [0, max(int64_t)) range and that they are strictly increasing.

Definition at line 36 of file ids_validator.cc.

◆ CheckIdsSubset() [1/2]

absl::Status operations_research::math_opt::CheckIdsSubset ( absl::Span< const int64_t > ids,
const IdNameBiMap & universe,
absl::string_view ids_description,
absl::string_view universe_description )

Checks that the elements of ids are a subset of universe. Elements of ids do not need to be sorted or distinct.

Definition at line 71 of file ids_validator.cc.

◆ CheckIdsSubset() [2/2]

absl::Status operations_research::math_opt::CheckIdsSubset ( absl::Span< const int64_t > ids,
const IdNameBiMap & universe,
std::optional< int64_t > upper_bound = std::nullopt )

Checks that the elements of ids are a subset of universe. Elements of ids do not need to be sorted or distinct. If upper_bound is set, elements must be strictly less than upper_bound.

Todo
(b/232526223): try merge this with the CheckIdsSubset overload below, or at least have one call the other.

Definition at line 55 of file ids_validator.cc.

◆ CheckPrimalSolutionAndTerminationConsistency()

absl::Status operations_research::math_opt::CheckPrimalSolutionAndTerminationConsistency ( const TerminationProto & termination,
const google::protobuf::RepeatedPtrField< SolutionProto > & solutions,
const bool maximize )

Definition at line 180 of file result_validator.cc.

◆ CheckPrimalSolutionFeasibility()

absl::StatusOr< ModelSubset > operations_research::math_opt::CheckPrimalSolutionFeasibility ( const Model & model,
const VariableMap< double > & variable_values,
const FeasibilityCheckerOptions & options = {} )

Returns a subset of models constraints that are violated at the point in variable_values. A point feasible with respect to all constraints will return an empty subset, which can be checked via ModelSubset::empty().

Feasibility is checked within tolerances that can be configured in options.

Returns an InvalidArgument error if variable_values does not contain an entry for each variable in model (and no extras).

Definition at line 213 of file solution_feasibility_checker.cc.

◆ CheckPrimalStatusIs()

absl::Status operations_research::math_opt::CheckPrimalStatusIs ( const ProblemStatusProto & status,
FeasibilityStatusProto required_status )

Assumes ValidateProblemStatus(status) is ok.

Returns absl::Ok only if status.primal_status = required_status. Assumes validateProblemStatus(status) returns absl::Ok.

Definition at line 63 of file bounds_and_status_validator.cc.

◆ CheckPrimalStatusIsNot()

absl::Status operations_research::math_opt::CheckPrimalStatusIsNot ( const ProblemStatusProto & status,
FeasibilityStatusProto forbidden_status )

Assumes ValidateProblemStatus(status) is ok.

Returns absl::Ok only if status.primal_status != forbidden_status. Assumes validateProblemStatus(status) returns absl::Ok.

Definition at line 76 of file bounds_and_status_validator.cc.

◆ CheckRegisteredCallbackEvents()

absl::Status operations_research::math_opt::CheckRegisteredCallbackEvents ( const CallbackRegistrationProto & registration,
const absl::flat_hash_set< CallbackEventProto > & supported_events )

Returns an InvalidArgumentError if some of the registered events are not supported.

Definition at line 299 of file callback_validator.cc.

◆ CheckScalar()

absl::Status operations_research::math_opt::CheckScalar ( const double value,
const DoubleOptions & options )

Checks value is not NaN and satisfies the additional conditions in options.

Definition at line 36 of file scalar_validator.cc.

◆ CheckScalarNoNanNoInf()

absl::Status operations_research::math_opt::CheckScalarNoNanNoInf ( const double d)

Definition at line 28 of file scalar_validator.cc.

◆ CheckSolverSpecificOutputEmpty()

absl::Status operations_research::math_opt::CheckSolverSpecificOutputEmpty ( const SolveResultProto & result)

Definition at line 491 of file solve_result.cc.

◆ CheckValues() [1/2]

template<typename T , typename = std::enable_if_t<!std::is_floating_point<T>::value>>
absl::Status operations_research::math_opt::CheckValues ( const SparseVectorView< T > & vector_view,
absl::string_view value_name = "values" )

Definition at line 42 of file sparse_vector_validator.h.

◆ CheckValues() [2/2]

template<typename T , typename = std::enable_if_t<std::is_floating_point<T>::value>>
absl::Status operations_research::math_opt::CheckValues ( const SparseVectorView< T > & vector_view,
const DoubleOptions & options,
absl::string_view value_name = "values" )

Definition at line 59 of file sparse_vector_validator.h.

◆ collection_to_range()

template<typename Collection >
auto operations_research::math_opt::collection_to_range ( Collection & c)

Definition at line 82 of file range.h.

◆ ComputeInfeasibleSubsystem()

absl::StatusOr< ComputeInfeasibleSubsystemResult > operations_research::math_opt::ComputeInfeasibleSubsystem ( const Model & model,
SolverType solver_type,
const ComputeInfeasibleSubsystemArguments & compute_args = {},
const SolverInitArguments & init_args = {} )

Computes an infeasible subsystem of the input model.

A Status error will be returned if the inputs are invalid or there is an unexpected failure in an underlying solver or for some internal math_opt errors. Otherwise, check ComputeInfeasibleSubsystemResult::feasibility to see if an infeasible subsystem was found.

Memory model: the returned ComputeInfeasibleSubsystemResult owns its own memory (for subsystems, solve stats, etc.), EXCEPT for a pointer back to the model. As a result:

Thread-safety: this method is safe to call concurrently on the same Model.

Definition at line 72 of file solve.cc.

◆ ComputeModelRanges()

ModelRanges operations_research::math_opt::ComputeModelRanges ( const Model & model)

Returns the ranges of the finite non-zero values in the given model.

Definition at line 97 of file statistics.cc.

◆ ConvertMathOptEmphasis()

GScipParameters::MetaParamValue operations_research::math_opt::ConvertMathOptEmphasis ( EmphasisProto emphasis)

Definition at line 605 of file gscip_solver.cc.

◆ CutoffTerminationProto()

TerminationProto operations_research::math_opt::CutoffTerminationProto ( bool is_maximize,
const absl::string_view detail )

Calls NoSolutionFoundTerminationProto() with LIMIT_CUTOFF LIMIT.

Definition at line 314 of file math_opt_proto_utils.cc.

◆ DEFINE_STRONG_INT_TYPE() [1/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( AuxiliaryObjectiveId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [2/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( IndicatorConstraintId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [3/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( LinearConstraintId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [4/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( QuadraticConstraintId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [5/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( SecondOrderConeConstraintId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [6/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( Sos1ConstraintId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [7/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( Sos2ConstraintId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [8/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( UpdateTrackerId ,
int64_t  )

◆ DEFINE_STRONG_INT_TYPE() [9/9]

operations_research::math_opt::DEFINE_STRONG_INT_TYPE ( VariableId ,
int64_t  )

◆ DenseIndependentSet()

std::unique_ptr< Model > operations_research::math_opt::DenseIndependentSet ( const bool integer,
const int n )

Problem data.

Add the variables

Set the objective.

Constraints of type (A).

Constraints of type (B).

Definition at line 44 of file test_models.cc.

◆ DenseIndependentSetHint5()

ModelSolveParameters::SolutionHint operations_research::math_opt::DenseIndependentSetHint5 ( const Model & model)

Definition at line 95 of file test_models.cc.

◆ DidUpdate()

testing::Matcher< UpdateResult > operations_research::math_opt::DidUpdate ( )

Actual UpdateResult.did_update is true.

Rarely used

Definition at line 1027 of file matchers.cc.

◆ EnumFromProto()

template<typename P >
std::optional< typename EnumProto< P >::Cpp > operations_research::math_opt::EnumFromProto ( P proto_value)

Returns the C++ enum that matches the input Proto enum, returns std::nullopt if the input is kProtoUnspecifiedValue.

Definition at line 281 of file enums.h.

◆ EnumFromString()

template<typename E >
std::optional< E > operations_research::math_opt::EnumFromString ( absl::string_view str)

Returns the enum value that corresponds to the input string or nullopt if no enum matches.

The expected strings are the one returned by EnumToString().

This is O(n) in complexity so use with care.

Definition at line 302 of file enums.h.

◆ EnumToOptString()

template<typename E >
std::optional< absl::string_view > operations_research::math_opt::EnumToOptString ( E value)

Returns a unique string that represent the enum. Returns nullopt if the input value is not a valid value of the enum.

Definition at line 297 of file enums.h.

◆ EnumToProto() [1/2]

template<typename E >
Enum< E >::Proto operations_research::math_opt::EnumToProto ( E value)

Returns the Proto enum that matches the input C++ proto.

Implementation note: this overload is necessary for EnumToProto(Xxx::kXxx) since C++ won't deduce E in std::optional<E> with the other overload.

Definition at line 276 of file enums.h.

◆ EnumToProto() [2/2]

template<typename E >
Enum< E >::Proto operations_research::math_opt::EnumToProto ( std::optional< E > value)

Returns the Proto enum that matches the input C++ proto, returns Enum<E>::kProtoUnspecifiedValue if the input is std::nullopt.

Template functions implementations after this point.

Definition at line 270 of file enums.h.

◆ EnumToString()

template<typename E >
absl::string_view operations_research::math_opt::EnumToString ( E value)

Returns a unique string that represent the enum.

It CHECKs that the input is a valid enum value. For most users this should always be the case since MathOpt don't generates invalid data.

Prefer using operator<< when possible though. As a side benefice it does not CHECK but instead prints the integer value of the invalid input.

Definition at line 289 of file enums.h.

◆ EventSet()

absl::flat_hash_set< CallbackEventProto > operations_research::math_opt::EventSet ( const CallbackRegistrationProto & callback_registration)

Returns the callback_registration.request_registration as a set of enums.

Here we don't use for-range loop since for repeated enum fields, the type used in C++ is RepeatedField<int>. Using the generated getter instead guarantees type safety.

Definition at line 141 of file math_opt_proto_utils.cc.

◆ EventToGurobiWhere()

std::vector< bool > operations_research::math_opt::EventToGurobiWhere ( const absl::flat_hash_set< CallbackEventProto > & events)

Converts a set of CallbackEventProto enums to a bit vector indicating which Gurobi callback events need to run our callback.

The returned vector will have an entry for each possible value of "where" that Gurobi's callbacks can stop at, see the table here: https://www.gurobi.com/documentation/9.1/refman/cb_codes.html

Definition at line 310 of file gurobi_callback.cc.

◆ EXPECT_THAT() [1/5]

operations_research::math_opt::EXPECT_THAT ( ComputeInfeasibleSubsystem(model, GetParam().solver_type) ,
IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=false,.upper=true}}},.linear_constraints={ {c, ModelSubset::Bounds{.lower=true,.upper=false}}}}))  )

◆ EXPECT_THAT() [2/5]

operations_research::math_opt::EXPECT_THAT ( ComputeInfeasibleSubsystem(model, GetParam().solver_type) ,
IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=false,.upper=true}}},.second_order_cone_constraints={c}}))  )

◆ EXPECT_THAT() [3/5]

operations_research::math_opt::EXPECT_THAT ( ComputeInfeasibleSubsystem(model, GetParam().solver_type) ,
IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=true,.upper=false}}},.second_order_cone_constraints={c}}))  )

◆ EXPECT_THAT() [4/5]

operations_research::math_opt::EXPECT_THAT ( ComputeInfeasibleSubsystem(model, GetParam().solver_type) ,
IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=true,.upper=false}}},.variable_integrality={x},.indicator_constraints={c}}))  )

◆ EXPECT_THAT() [5/5]

operations_research::math_opt::EXPECT_THAT ( ComputeInfeasibleSubsystem(model, GetParam().solver_type) ,
IsOkAndHolds(IsInfeasible(true, ModelSubset{ .variable_bounds={{x, ModelSubset::Bounds{.lower=true,.upper=true}}},.quadratic_constraints={ {c, ModelSubset::Bounds{.lower=true,.upper=false}}}}))  )

◆ ExtensionToFileFormat()

absl::flat_hash_map< absl::string_view, FileFormat > operations_research::math_opt::ExtensionToFileFormat ( )

Definition at line 92 of file file_format_flags.cc.

◆ FeasibleTermination()

TerminationProto operations_research::math_opt::FeasibleTermination ( const LimitProto limit,
const absl::string_view detail )

Definition at line 168 of file math_opt_proto_utils.cc.

◆ FeasibleTerminationProto()

TerminationProto operations_research::math_opt::FeasibleTerminationProto ( bool is_maximize,
LimitProto limit,
double finite_primal_objective,
std::optional< double > optional_dual_objective = std::nullopt,
absl::string_view detail = {} )

Returns a TERMINATION_REASON_FEASIBLE termination with a FEASIBILITY_STATUS_FEASIBLE primal status. The dual status depends on optional_dual_objective.

finite_primal_objective should be finite and limit should not be LIMIT_CUTOFF for a valid TerminationProto to be returned (use LimitCutoffTerminationProto() below instead).

Assumes dual solution exists iff optional_dual_objective is set even if infinite (some solvers return feasible dual solutions without an objective value). If set the dual status is set to FEASIBILITY_STATUS_FEASIBLE, else it is FEASIBILITY_STATUS_UNDETERMINED.

It sets the primal bound based on the primal objective. The dual bound is either set to the optional_dual_objective if set, else to a trivial value.

Todo
(b/290359402): Consider improving to require a finite dual bound when dual feasible solutions are returned.

Definition at line 344 of file math_opt_proto_utils.cc.

◆ FillSparseBasisStatusVector()

template<typename IndexType , typename ValueType >
SparseBasisStatusVector operations_research::math_opt::FillSparseBasisStatusVector ( absl::Span< const int64_t > ids_in_order,
const absl::flat_hash_map< int64_t, IndexType > & id_map,
const glop::StrictITIVector< IndexType, ValueType > & values )

Definition at line 497 of file glop_solver.cc.

◆ FillSparseDoubleVector()

template<typename IndexType >
SparseDoubleVectorProto operations_research::math_opt::FillSparseDoubleVector ( absl::Span< const int64_t > ids_in_order,
const absl::flat_hash_map< int64_t, IndexType > & id_map,
const glop::StrictITIVector< IndexType, glop::Fractional > & values,
const SparseVectorFilterProto & filter )

Definition at line 461 of file glop_solver.cc.

◆ FilterSparseVector()

SparseDoubleVectorProto operations_research::math_opt::FilterSparseVector ( const SparseDoubleVectorProto & input,
const SparseVectorFilterProto & filter )

Applies filter to each element of input and returns the elements that remain.

Todo
(b/261603235): this function is not very efficient, decide if this matters.

Definition at line 105 of file math_opt_proto_utils.cc.

◆ FirstLinearConstraintId()

std::optional< int64_t > operations_research::math_opt::FirstLinearConstraintId ( const LinearConstraintsProto & linear_constraints)
inline

Returns the id of the first linear constraint if there is one. If the input proto is valid, this will also be the smallest id.

Definition at line 70 of file math_opt_proto_utils.h.

◆ FirstVariableId()

std::optional< int64_t > operations_research::math_opt::FirstVariableId ( const VariablesProto & variables)
inline

Returns the id of the first variable if there is one. If the input proto is valid, this will also be the smallest id.

Definition at line 63 of file math_opt_proto_utils.h.

◆ FormatFlagPossibleValuesList()

std::string operations_research::math_opt::FormatFlagPossibleValuesList ( )

Definition at line 179 of file file_format_flags.cc.

◆ FormatFromFilePath()

std::optional< FileFormat > operations_research::math_opt::FormatFromFilePath ( absl::string_view file_path)

Sort extensions in reverse lexicographic order. The point here would be to consider ".pb.txt" before we text for ".txt".

Definition at line 105 of file file_format_flags.cc.

◆ FormatFromFlagOrFilePath()

std::optional< FileFormat > operations_research::math_opt::FormatFromFlagOrFilePath ( const std::optional< FileFormat > format_flag_value,
const absl::string_view file_path )

Definition at line 127 of file file_format_flags.cc.

◆ FormulateIndicatorConstraintAsMip()

absl::Status operations_research::math_opt::FormulateIndicatorConstraintAsMip ( Model & model,
IndicatorConstraint indicator_constraint )

Takes a model and an indicator_constraint from that same model, and models that constraint using mixed-integer programming (MIP). This entails deleting indicator_constraint from model and adding new linear constraints.

As of 2023-10-03, this formulation is a simple big-M formulation:

Indicator constraint: x = 1 --> lb ≤ <a, y> ≤ ub Becomes: if lb > -∞: <a, y> ≥ lb + (LowerBound(<a, y>) - lb) (1 - x) if ub < +∞: <a, y> ≤ ub + (UpperBound(<a, y>) - ub) (1 - x),

where LowerBound() and UpperBound() are from linear_expr_util.

Will return an error if indicator_constraint is not valid or associated with model, or if the simple bound computations are not able to prove that the indicator constraint is MIP representable (namely, if LowerBound() and/or UpperBound() return -∞ or +∞, respectively).

One if the implied constraint should hold; zero otherwise.

Definition at line 27 of file general_constraint_to_mip.cc.

◆ FromGlopBasisStatus()

template<typename ValueType >
BasisStatusProto operations_research::math_opt::FromGlopBasisStatus ( const ValueType glop_basis_status)

ValueType should be glop's VariableStatus or ConstraintStatus.

Definition at line 480 of file glop_solver.cc.

◆ FromLinearExpression()

LinearExpressionData operations_research::math_opt::FromLinearExpression ( const LinearExpression & expression)

Converts a LinearExpression to the associated "raw ID" format.

Definition at line 34 of file model_util.cc.

◆ GetObjectiveBounds()

ObjectiveBoundsProto operations_research::math_opt::GetObjectiveBounds ( const SolveResultProto & solve_result)

Returns solve_result.termination.objective_bounds if present. Otherwise, it builds ObjectiveBoundsProto from solve_result.solve_stats.best_primal/dual_bound

Todo
(b/290091715): Remove once solve_stats.best_primal/dual_bound is removed and we know termination.objective_bounds will always be present.

Definition at line 45 of file math_opt_proto_utils.cc.

◆ GetProblemStatus()

ProblemStatusProto operations_research::math_opt::GetProblemStatus ( const SolveResultProto & solve_result)

Returns solve_result.termination.problem_status if present. Otherwise, it returns solve_result.solve_stats.problem_status

Todo
(b/290091715): Remove once solve_stats.problem_status is removed and we know termination.problem_status will always be present.

Definition at line 56 of file math_opt_proto_utils.cc.

◆ GetSortedIs()

template<typename T >
std::vector< int64_t > operations_research::math_opt::GetSortedIs ( const absl::flat_hash_map< int64_t, T > & id_map)

Definition at line 531 of file glop_solver.cc.

◆ GlpkComputeUnboundRay()

absl::StatusOr< std::optional< GlpkRay > > operations_research::math_opt::GlpkComputeUnboundRay ( glp_prob * problem)

Returns the primal or dual ray if one is identified by glp_get_unbnd_ray(). Returns an error status if an internal error occurs.

No ray, do nothing.

The factorization may not exists when GLPK's trivial_lp() is used to solve a trivial LP. Here we force the computation of the factorization if necessary.

The function glp_get_unbnd_ray() returns either:

  • a non-basic tableau variable if we have primal unboundness.
  • a basic tableau variable if we have dual unboundness.

Definition at line 352 of file rays.cc.

◆ GurobiCallbackImpl()

absl::Status operations_research::math_opt::GurobiCallbackImpl ( const Gurobi::CallbackContext & context,
const GurobiCallbackInput & callback_input,
MessageCallbackData & message_callback_data,
SolveInterrupter *const local_interrupter )

Gurobi 9 ignores early calls to GRBterminate(). For example calling GRBterminate() in the first call of a MESSAGE callback only will not interrupt the solve. The rationale is that it is likely Gurobi resets its own internal "terminated" flag at the beginning of the solve but do make some callbacks calls first.

Hence here we make sure to call GRBterminate() for every event once the interrupter has been triggered. This in particular includes POLLING which is regularly emitted by Gurobi during the solve.

The POLLING event is a way for interactive applications that uses Gurobi but don't want to deal with threading to regain some kind of interactivity while a long solve is running by being called back from time to time. No data can be retrieved from this event. This event if thus not wrapped by MathOpt.

At this point we know we have a user callback, thus we must have a local interrupter to deal with termination.

Definition at line 319 of file gurobi_callback.cc.

◆ GurobiCallbackImplFlush()

void operations_research::math_opt::GurobiCallbackImplFlush ( const GurobiCallbackInput & callback_input,
MessageCallbackData & message_callback_data )

Makes the final calls to the message callback with any unfinished line if necessary. It must be called once at the end of the solve, even when the solve or one callback failed (in case the last unfinished line contains some details about that).

Here we know that message_callback_data has only been filled-in if message_cb was not nullptr. Hence it is safe to make this call without testing.

Definition at line 382 of file gurobi_callback.cc.

◆ GurobiNewPrimaryEnv()

absl::StatusOr< GRBenvUniquePtr > operations_research::math_opt::GurobiNewPrimaryEnv ( const std::optional< GurobiIsvKey > & isv_key = std::nullopt)

Returns a new primary Gurobi environment, using the ISV key if provided, or a regular license otherwise. Gurobi::New() creates an environment automatically if not provided, so most users will not use this directly.

Surprisingly, Gurobi will still create an environment if initialization fails, so we want this wrapper even in the error case to free it properly.

Definition at line 154 of file g_gurobi.cc.

◆ HasDualRay()

testing::Matcher< SolveResult > operations_research::math_opt::HasDualRay ( DualRay expected,
double tolerance = kMatcherDefaultTolerance )

Actual SolveResult contains a dual ray that matches expected within tolerance.

Definition at line 851 of file matchers.cc.

◆ HasDualSolution()

testing::Matcher< SolveResult > operations_research::math_opt::HasDualSolution ( DualSolution expected,
double tolerance = kMatcherDefaultTolerance )

SolveResult has a dual solution matching expected within tolerance.

Definition at line 831 of file matchers.cc.

◆ HasPrimalRay() [1/2]

testing::Matcher< SolveResult > operations_research::math_opt::HasPrimalRay ( PrimalRay expected,
double tolerance = kMatcherDefaultTolerance )

Actual SolveResult contains a primal ray that matches expected within tolerance.

Definition at line 839 of file matchers.cc.

◆ HasPrimalRay() [2/2]

testing::Matcher< SolveResult > operations_research::math_opt::HasPrimalRay ( VariableMap< double > expected_vars,
double tolerance = kMatcherDefaultTolerance )

Actual SolveResult contains a primal ray with variable values equivalent to (under L_inf scaling) expected_vars up to tolerance.

Definition at line 844 of file matchers.cc.

◆ HasSolution()

testing::Matcher< SolveResult > operations_research::math_opt::HasSolution ( PrimalSolution expected,
const double tolerance )

SolveResult has a primal solution matching expected within tolerance.

Definition at line 823 of file matchers.cc.

◆ IndependentSetCompleteGraph()

std::unique_ptr< Model > operations_research::math_opt::IndependentSetCompleteGraph ( const bool integer,
const int n )

Definition at line 109 of file test_models.cc.

◆ IndexToId()

template<typename T >
glop::StrictITIVector< T, int64_t > operations_research::math_opt::IndexToId ( const absl::flat_hash_map< int64_t, T > & id_map)

Returns a vector of containing the MathOpt id of each row or column. Here T is either (Col|Row)Index and id_map is expected to be GlopSolver::(linear_constraints_|variables_).

Guard value used to identify not-yet-set elements of index_to_id.

At this point, index_to_id can't contain any kEmptyId values since index_to_id.size() == id_map.size() and we modified id_map.size() elements in the loop, after checking that the modified element was changed by a previous iteration.

Definition at line 546 of file glop_solver.cc.

◆ InfeasibleOrUnboundedTerminationProto()

TerminationProto operations_research::math_opt::InfeasibleOrUnboundedTerminationProto ( bool is_maximize,
FeasibilityStatusProto dual_feasibility_status = FEASIBILITY_STATUS_UNDETERMINED,
absl::string_view detail = {} )

Returns a TERMINATION_REASON_INFEASIBLE_OR_UNBOUNDED termination with FEASIBILITY_STATUS_UNDETERMINED primal status and the provided dual status along with trivial bounds.

primal_or_dual_infeasible is set if dual_feasibility_status is FEASIBILITY_STATUS_UNDETERMINED.

dual_feasibility_status must be infeasible or undetermined for a valid TerminationProto to be returned.

Definition at line 369 of file math_opt_proto_utils.cc.

◆ InfeasibleTerminationProto()

TerminationProto operations_research::math_opt::InfeasibleTerminationProto ( bool is_maximize,
FeasibilityStatusProto dual_feasibility_status = FEASIBILITY_STATUS_UNDETERMINED,
absl::string_view detail = {} )

Returns a TERMINATION_REASON_INFEASIBLE termination with FEASIBILITY_STATUS_INFEASIBLE primal status and the provided dual status.

It sets a trivial primal bound and a dual bound based on the provided dual status, which should be FEASIBILITY_STATUS_FEASIBLE or FEASIBILITY_STATUS_UNDETERMINED. If the dual status is FEASIBILITY_STATUS_UNDETERMINED, then the dual bound will be trivial and if the dual status is FEASIBILITY_STATUS_FEASIBLE, then the dual bound will be equal to the primal bound.

The convention for infeasible MIPs is that dual_feasibility_status is feasible (There always exist a dual feasible convex relaxation of an infeasible MIP).

dual_feasibility_status must not be FEASIBILITY_STATUS_UNSPECIFIED for a valid TerminationProto to be returned.

Definition at line 251 of file math_opt_proto_utils.cc.

◆ InfoLoggerMessageCallback()

MessageCallback operations_research::math_opt::InfoLoggerMessageCallback ( absl::string_view prefix = "",
absl::SourceLocation loc = absl::SourceLocation::current() )

Returns a message callback function that prints each line to LOG(INFO), prefixing each line with the given prefix.

Usage:

SolveArguments args; args.message_callback = InfoLoggerMessageCallback("[solver] ");

Definition at line 93 of file message_callback.cc.

◆ InnerProduct() [1/2]

RightIterable LinearExpression operations_research::math_opt::InnerProduct ( const LeftIterable & left,
const RightIterable & right )
inline

◆ InnerProduct() [2/2]

template<typename LeftIterable , typename RightIterable >
LinearExpression operations_research::math_opt::InnerProduct ( const LeftIterable & left,
const RightIterable & right )

Definition at line 1717 of file variable_and_expressions.h.

◆ IsConsistentWith()

For infeasible and unbounded see Not checked if options check_solutions_if_inf_or_unbounded and the If options first_solution_only is check the entire list of Dual solution is not checked if options check the entire list of Enable with options check_basis testing::Matcher< SolveResult > operations_research::math_opt::IsConsistentWith ( const SolveResult & expected,
const SolveResultMatcherOptions & options = {} )

solutions matches in the same order.

  • The basis is not checked by default. If enabled, checked with BasisIs(). This function is symmetric in that: EXPECT_THAT(actual, IsConsistentWith(expected)); EXPECT_THAT(expected, IsConsistentWith(actual)); agree on matching, they only differ in strings produced. Per gmock conventions, prefer the former.

For problems with either primal or dual infeasibility, see SolveResultMatcherOptions::inf_or_unb_soft_match for guidance on how to best set the termination reason and inf_or_unb_soft_match.

Definition at line 942 of file matchers.cc.

◆ IsFeasible()

testing::Matcher< ComputeInfeasibleSubsystemResult > operations_research::math_opt::IsFeasible ( )

ComputeInfeasibleSubsystemResult matchers

Matchers for a ComputeInfeasibleSubsystemResult Checks that ComputeInfeasibleSubsystemResult.feasibility is kFeasible, that the .infeasible_subsystem is empty and that is_minimal is false.

Definition at line 972 of file matchers.cc.

◆ IsIdentical() [1/2]

testing::Matcher< LinearExpression > operations_research::math_opt::IsIdentical ( LinearExpression expected)

Matchers for LinearExpression and QuadraticExpression

Matchers for various Variable expressions (e.g. LinearExpression) Checks that the expressions are structurally identical (i.e., internal maps have the same keys and storage, coefficients are exactly equal). This factory will CHECK-fail if expected contains any NaN values, and any NaN values in the expression compared against will result in the matcher failing.

Definition at line 278 of file matchers.cc.

◆ IsIdentical() [2/2]

testing::Matcher< QuadraticExpression > operations_research::math_opt::IsIdentical ( QuadraticExpression expected)

Checks that the expressions are structurally identical (i.e., internal maps have the same keys and storage, coefficients are exactly equal). This factory will CHECK-fail if expected contains any NaN values, and any NaN values in the expression compared against will result in the matcher failing.

Definition at line 319 of file matchers.cc.

◆ IsInfeasible()

testing::Matcher< ComputeInfeasibleSubsystemResult > operations_research::math_opt::IsInfeasible ( std::optional< bool > expected_is_minimal = std::nullopt,
std::optional< ModelSubset > expected_infeasible_subsystem = std::nullopt )

Checks that ComputeInfeasibleSubsystemResult.feasibility is kInfeasible and that .infeasible_subsystem is not empty. If expected_is_minimal is set, test that .is_minimal has the same value. If expected_infeasible_subsystem is set, test that the resulting ModelSubset::Proto() are EqualsProto().

Definition at line 994 of file matchers.cc.

◆ IsNear() [1/9]

template<typename K >
Matcher< absl::flat_hash_map< K, double > > operations_research::math_opt::IsNear ( absl::flat_hash_map< K, double > expected,
const double tolerance )

Definition at line 259 of file matchers.cc.

◆ IsNear() [2/9]

testing::Matcher< absl::flat_hash_map< QuadraticConstraint, double > > operations_research::math_opt::IsNear ( absl::flat_hash_map< QuadraticConstraint, double > expected,
double tolerance = kMatcherDefaultTolerance )

Checks that the maps have identical keys and values within tolerance. This factory will CHECK-fail if expected contains any NaN values.

Definition at line 241 of file matchers.cc.

◆ IsNear() [3/9]

testing::Matcher< DualRay > operations_research::math_opt::IsNear ( DualRay expected,
double tolerance = kMatcherDefaultTolerance )

Checks that dual variables and reduced costs are defined for the same set of Variables/LinearConstraints, and that their rescaled values are within tolerance.

Definition at line 597 of file matchers.cc.

◆ IsNear() [4/9]

testing::Matcher< DualSolution > operations_research::math_opt::IsNear ( DualSolution expected,
double tolerance = kMatcherDefaultTolerance,
bool allow_undetermined = false )

Checks dual variables, reduced costs and objective are within tolerance and feasibility statuses are identical.

Definition at line 434 of file matchers.cc.

◆ IsNear() [5/9]

testing::Matcher< LinearConstraintMap< double > > operations_research::math_opt::IsNear ( LinearConstraintMap< double > expected,
double tolerance = kMatcherDefaultTolerance )

Checks that the maps have identical keys and values within tolerance. This factory will CHECK-fail if expected contains any NaN values, and any NaN values in the expression compared against will result in the matcher failing.

Definition at line 234 of file matchers.cc.

◆ IsNear() [6/9]

testing::Matcher< PrimalRay > operations_research::math_opt::IsNear ( PrimalRay expected,
double tolerance = kMatcherDefaultTolerance )

Matchers for a Rays Checks variables match and that after rescaling, variable values are within tolerance.

Definition at line 533 of file matchers.cc.

◆ IsNear() [7/9]

testing::Matcher< PrimalSolution > operations_research::math_opt::IsNear ( PrimalSolution expected,
double tolerance = kMatcherDefaultTolerance,
bool allow_undetermined = false )

Checks variables match and variable/objective values are within tolerance and feasibility statuses are identical.

Definition at line 423 of file matchers.cc.

◆ IsNear() [8/9]

testing::Matcher< Solution > operations_research::math_opt::IsNear ( Solution expected,
const SolutionMatcherOptions options )

Definition at line 458 of file matchers.cc.

◆ IsNear() [9/9]

testing::Matcher< VariableMap< double > > operations_research::math_opt::IsNear ( VariableMap< double > expected,
double tolerance = kMatcherDefaultTolerance )

Matchers for absl::flat_hash_map Checks that the maps have identical keys and values within tolerance. This factory will CHECK-fail if expected contains any NaN values.

Definition at line 221 of file matchers.cc.

◆ IsNearlyEquivalent()

testing::Matcher< BoundedLinearExpression > operations_research::math_opt::IsNearlyEquivalent ( const BoundedLinearExpression & expected,
double tolerance = kMatcherDefaultTolerance )

Checks that the bounded linear expression is equivalent to expected, where equivalence is maintained by:

  • adding alpha to the lower bound, the linear expression and upper bound
  • multiplying the lower bound, linear expression, by -1 (and flipping the inequalities).
    Note
    , as implemented, we do not allow for arbitrary multiplicative rescalings (this makes additive tolerance complicated).

Definition at line 310 of file matchers.cc.

◆ IsNearlySubsetOf() [1/4]

template<typename K >
Matcher< absl::flat_hash_map< K, double > > operations_research::math_opt::IsNearlySubsetOf ( absl::flat_hash_map< K, double > expected,
const double tolerance )

Definition at line 266 of file matchers.cc.

◆ IsNearlySubsetOf() [2/4]

testing::Matcher< absl::flat_hash_map< QuadraticConstraint, double > > operations_research::math_opt::IsNearlySubsetOf ( absl::flat_hash_map< QuadraticConstraint, double > expected,
double tolerance = kMatcherDefaultTolerance )

Checks that the keys of actual are a subset of the keys of expected, and that for all shared keys, the values are within tolerance. This factory will CHECK-fail if expected contains any NaN values, and any NaN values in the expression compared against will result in the matcher failing.

Definition at line 249 of file matchers.cc.

◆ IsNearlySubsetOf() [3/4]

testing::Matcher< LinearConstraintMap< double > > operations_research::math_opt::IsNearlySubsetOf ( LinearConstraintMap< double > expected,
double tolerance = kMatcherDefaultTolerance )

Checks that the keys of actual are a subset of the keys of expected, and that for all shared keys, the values are within tolerance. This factory will CHECK-fail if expected contains any NaN values, and any NaN values in the expression compared against will result in the matcher failing.

Definition at line 227 of file matchers.cc.

◆ IsNearlySubsetOf() [4/4]

testing::Matcher< VariableMap< double > > operations_research::math_opt::IsNearlySubsetOf ( VariableMap< double > expected,
double tolerance = kMatcherDefaultTolerance )

Checks that the keys of actual are a subset of the keys of expected, and that for all shared keys, the values are within tolerance. This factory will CHECK-fail if expected contains any NaN values, and any NaN values in the expression compared against will result in the matcher failing.

Definition at line 215 of file matchers.cc.

◆ IsOkAndHolds()

<=x<=1 IncrementalMipTest::IncrementalMipTest() :model_("incremental_solve_test"), x_(model_.AddContinuousVariable(0.0, 1.0, "x")), y_(model_.AddIntegerVariable(0.0, 2.0, "y")), c_(model_.AddLinearConstraint(0<=x_+y_<=1.5, "c")) { model_.Maximize(3.0 *x_+2.0 *y_+0.1);solver_=NewIncrementalSolver(&model_, TestedSolver()).value();const SolveResult first_solve=solver_->Solve().value();CHECK(first_solve.has_primal_feasible_solution());CHECK_LE(std::abs(first_solve.objective_value() - 3.6), kTolerance)<< first_solve.objective_value();} namespace { TEST_P(SimpleMipTest, OneVarMax) { Model model;const Variable x=model.AddVariable(0.0, 4.0, false, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, OneVarMin) { Model model;const Variable x=model.AddVariable(-2.4, 4.0, false, "x");model.Minimize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(-4.8));EXPECT_THAT(result.variable_values(), IsNear({{x, -2.4}}));} TEST_P(SimpleMipTest, OneIntegerVar) { Model model;const Variable x=model.AddVariable(0.0, 4.5, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, SimpleLinearConstraint) { Model model;const Variable x=model.AddBinaryVariable("x");const Variable y=model.AddBinaryVariable("y");model.Maximize(2.0 *x+y);model.AddLinearConstraint(0.0<=x+y<=1.5, "c");ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(2.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 1}, {y, 0}}));} TEST_P(SimpleMipTest, Unbounded) { Model model;const Variable x=model.AddVariable(0.0, kInf, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));if(GetParam().report_unboundness_correctly) { ASSERT_THAT(result, TerminatesWithOneOf({TerminationReason::kUnbounded, TerminationReason::kInfeasibleOrUnbounded}));} else { ASSERT_THAT(result, TerminatesWith(TerminationReason::kOtherError));} } TEST_P(SimpleMipTest, Infeasible) { Model model;const Variable x=model.AddVariable(0.0, 3.0, true, "x");model.Maximize(2.0 *x);model.AddLinearConstraint(x >=4.0);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, TerminatesWith(TerminationReason::kInfeasible));} TEST_P(SimpleMipTest, FractionalBoundsContainNoInteger) { if(GetParam().solver_type==SolverType::kGurobi) { GTEST_SKIP()<< "TODO(b/272298816): Gurobi bindings are broken here.";} Model model;const Variable x=model.AddIntegerVariable(0.5, 0.6, "x");model.Maximize(x);EXPECT_THAT(Solve(model, GetParam().solver_type), IsOkAndHolds(TerminatesWith(TerminationReason::kInfeasible)));} TEST_P(IncrementalMipTest, EmptyUpdate) { ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(3.6));EXPECT_THAT(result.variable_values(), IsNear({{x_, 0.5}, {y_, 1.0}}));} TEST_P(IncrementalMipTest, MakeContinuous) { model_.set_continuous(y_);ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(4.1));EXPECT_THAT(result.variable_values(), IsNear({{x_, 1.0}, {y_, 0.5}}));} TEST_P(IncrementalMipTest, DISABLED_MakeContinuousWithNonIntegralBounds) { solver_.reset();Model model("bounds");const Variable x=model.AddIntegerVariable(0.5, 1.5, "x");model.Maximize(x);ASSERT_OK_AND_ASSIGN(const auto solver, NewIncrementalSolver(&model, TestedSolver()));ASSERT_THAT(solver->Solve(), IsOkAndHolds(IsOptimal(1.0)));model.set_continuous(x);ASSERT_THAT(solver->Update(), IsOkAndHolds(DidUpdate()));ASSERT_THAT(solver-> operations_research::math_opt::IsOkAndHolds ( IsOptimal(1.5) )

◆ IsOptimal()

testing::Matcher< SolveResult > operations_research::math_opt::IsOptimal ( std::optional< double > expected_primal_objective = std::nullopt,
double tolerance = kMatcherDefaultTolerance )

Matchers for a SolveResult Checks the following:

  • The termination reason is optimal.
  • If expected_primal_objective contains a value, there is at least one primal feasible solution and that solution has an objective value within tolerance of expected_objective. However, primal and dual bounds are not checked.
    Todo
    (b/309658404): Note the bounds should be at least finite once we validate this.

Definition at line 762 of file matchers.cc.

◆ IsOptimalWithDualSolution() [1/2]

testing::Matcher< SolveResult > operations_research::math_opt::IsOptimalWithDualSolution ( const double expected_objective,
const LinearConstraintMap< double > expected_dual_values,
const absl::flat_hash_map< QuadraticConstraint, double > expected_quadratic_dual_values,
const VariableMap< double > expected_reduced_costs,
const double tolerance )

Definition at line 805 of file matchers.cc.

◆ IsOptimalWithDualSolution() [2/2]

testing::Matcher< SolveResult > operations_research::math_opt::IsOptimalWithDualSolution ( const double expected_objective,
const LinearConstraintMap< double > expected_dual_values,
const VariableMap< double > expected_reduced_costs,
const double tolerance )

Definition at line 790 of file matchers.cc.

◆ IsOptimalWithSolution()

testing::Matcher< SolveResult > operations_research::math_opt::IsOptimalWithSolution ( const double expected_objective,
const VariableMap< double > expected_variable_values,
const double tolerance )

Definition at line 777 of file matchers.cc.

◆ IsUndetermined()

testing::Matcher< ComputeInfeasibleSubsystemResult > operations_research::math_opt::IsUndetermined ( )

Checks that ComputeInfeasibleSubsystemResult.feasibility is kUndetermined, that the .infeasible_subsystem is empty and that is_minimal is false..

Definition at line 983 of file matchers.cc.

◆ LimitIs() [1/2]

testing::Matcher< Termination > operations_research::math_opt::LimitIs ( Limit limit,
testing::Matcher< std::string > detail_matcher = testing::_ )

Checks the following:

  • The reason is kFeasible or kNoSolutionFound.
  • The limit is the expected one.
  • If the optional detail_matcher is provided, it matches the detail.

See TerminatesWithLimit() for a similar matcher for SolveResult.

Todo
: b/343234961 - Maybe change the name and sync the signatures/features.

◆ LimitIs() [2/2]

Matcher< Termination > operations_research::math_opt::LimitIs ( math_opt::Limit limit,
const Matcher< std::string > detail_matcher )

Definition at line 709 of file matchers.cc.

◆ LimitTerminationProto() [1/2]

TerminationProto operations_research::math_opt::LimitTerminationProto ( bool is_maximize,
LimitProto limit,
std::optional< double > optional_finite_primal_objective,
std::optional< double > optional_dual_objective = std::nullopt,
absl::string_view detail = {} )

Either calls FeasibleTerminationProto() or NoSolutionFoundTerminationProto() based on optional_finite_primal_objective having a value.

That is it assumes a primal feasible solution exists iff optional_finite_primal_objective has a value.

Definition at line 270 of file math_opt_proto_utils.cc.

◆ LimitTerminationProto() [2/2]

TerminationProto operations_research::math_opt::LimitTerminationProto ( LimitProto limit,
double primal_objective,
double dual_objective,
bool claim_dual_feasible_solution_exists,
absl::string_view detail = {} )

Returns either a TERMINATION_REASON_FEASIBLE or TERMINATION_REASON_NO_SOLUTION_FOUND termination depending on primal_objective being finite or not. That is it assumes there is a primal feasible solution iff primal_objective is finite.

If claim_dual_feasible_solution_exists is true, the dual_status is set as FEASIBILITY_STATUS_FEASIBLE, else FEASIBILITY_STATUS_UNDETERMINED.

This function assumes dual solution exists if claim_dual_feasible_solution_exists is true even if dual_objective is infinite (some solvers return feasible dual solutions without an objective value). If dual_objective is finite then claim_dual_feasible_solution_exists must be true for a valid termination to be returned.

Todo
(b/290359402): Consider improving to require a finite dual bound when dual feasible solutions are returned.

Definition at line 284 of file math_opt_proto_utils.cc.

◆ LinearConstraintBasisFromProto()

absl::StatusOr< LinearConstraintMap< BasisStatus > > operations_research::math_opt::LinearConstraintBasisFromProto ( const ModelStorage * model,
const SparseBasisStatusVector & basis_proto )

Returns the LinearConstraintMap<BasisStatus> equivalent to basis_proto.

Requires that (or returns a status error):

  • basis_proto.ids and basis_proto.values have equal size.
  • basis_proto.ids is sorted.
  • basis_proto.ids has elements that are linear constraints in model (this implies that each id is in [0, max(int64_t))).
  • basis_proto.values does not contain UNSPECIFIED and has valid enum values.

Definition at line 230 of file sparse_containers.cc.

◆ LinearConstraintBasisToProto()

SparseBasisStatusVector operations_research::math_opt::LinearConstraintBasisToProto ( const LinearConstraintMap< BasisStatus > & basis_values)

Returns the proto equivalent of basis_values.

Definition at line 238 of file sparse_containers.cc.

◆ LinearConstraintFilterFromProto()

absl::StatusOr< MapFilter< LinearConstraint > > operations_research::math_opt::LinearConstraintFilterFromProto ( const Model & model,
const SparseVectorFilterProto & proto )

Returns the MapFilter<LinearConstraint> equivalent to proto.

Requires that (or returns a status error):

  • proto.filtered_ids has elements that are linear constraints in model.

Definition at line 46 of file map_filter.cc.

◆ LinearConstraintValuesFromProto()

absl::StatusOr< LinearConstraintMap< double > > operations_research::math_opt::LinearConstraintValuesFromProto ( const ModelStorage * model,
const SparseDoubleVectorProto & lin_cons_proto )

Returns the LinearConstraintMap<double> equivalent to lin_cons_proto.

Requires that (or returns a status error):

  • lin_cons_proto.ids and lin_cons_proto.values have equal size.
  • lin_cons_proto.ids is sorted.
  • lin_cons_proto.ids has elements that are linear constraints in model (this implies that each id is in [0, max(int64_t))).
Note
the values of lin_cons_proto.values are not checked (it may have NaNs).

Definition at line 189 of file sparse_containers.cc.

◆ LinearConstraintValuesToProto()

SparseDoubleVectorProto operations_research::math_opt::LinearConstraintValuesToProto ( const LinearConstraintMap< double > & linear_constraint_values)

Returns the proto equivalent of linear_constraint_values.

Definition at line 197 of file sparse_containers.cc.

◆ LinearExpressionIsNear()

testing::Matcher< LinearExpression > operations_research::math_opt::LinearExpressionIsNear ( const LinearExpression expected,
const double tolerance )

Definition at line 282 of file matchers.cc.

◆ LowerBound()

double operations_research::math_opt::LowerBound ( const LinearExpression & linear_expression)

Computes a lower bound on the value a linear expression can take based on the variable bounds.

The user must ensure:

  • Variable lower bounds are in [-inf, +inf) (required at solve time as well)
  • Variable upper bounds are in (-inf, +inf] (required at solve time as well)
  • Variables bounds are not NaN
  • The expression has no NaNs and all finite coefficients
  • The output computation does not overflow when summing finite terms (rarely an issue, as then your problem is very poorly scaled). Under these assumptions, the returned value will be in [-inf, +inf). If an assumption is broken, it is possible to return NaN or +inf.

This function is deterministic, but runs in O(n log n) and will allocate.

Alternatives:

  • If more precision is needed, see AccurateSum
  • For a faster method that does not allocate, is less precise, and not deterministic, simply add each term to the result in the hash map's iteration order.

Definition at line 52 of file linear_expr_util.cc.

◆ make_range() [1/2]

template<typename T >
iterator_range< T > operations_research::math_opt::make_range ( std::pair< T, T > p)

Converts std::pair<Iter,Iter> to iterator_range<Iter>. E.g.: for (const auto& e : make_range(m.equal_range(k))) ...

Definition at line 77 of file range.h.

◆ make_range() [2/2]

template<typename T >
iterator_range< T > operations_research::math_opt::make_range ( T x,
T y )

Convenience function for iterating over sub-ranges.

This provides a bit of syntactic sugar to make using sub-ranges in for loops a bit easier. Analogous to std::make_pair().

Definition at line 70 of file range.h.

◆ MakeKeepKeysFilter() [1/2]

template<typename Collection , typename ValueType = typename Collection::value_type>
MapFilter< ValueType > operations_research::math_opt::MakeKeepKeysFilter ( const Collection & keys)

Returns a filter that keeps the key-value pairs with the given keys.

Example: std::vector<Variable> decision_vars = ...; const auto filter = MakeKeepKeysFilter(decision_vars);

Definition at line 167 of file map_filter.h.

◆ MakeKeepKeysFilter() [2/2]

template<typename KeyType >
MapFilter< KeyType > operations_research::math_opt::MakeKeepKeysFilter ( std::initializer_list< KeyType > keys)

Returns a filter that keeps the key-value pairs with the given keys.

This overload is necessary since C++ does not automatically deduce the type when using the previous one.

Example: const Variable x = ...; const Variable y = ...; const auto filter = MakeKeepKeysFilter({x, y});

Definition at line 183 of file map_filter.h.

◆ MakeSkipAllFilter()

template<typename KeyType >
MapFilter< KeyType > operations_research::math_opt::MakeSkipAllFilter ( )

Returns a filter that skips all key-value pairs.

This is typically used to disable the dual data in SolveResult when these are ignored by the user.

Example: const auto filter = MakeSkipAllFilter<Variable>();

Definition at line 142 of file map_filter.h.

◆ MakeSkipZerosFilter()

template<typename KeyType >
MapFilter< KeyType > operations_research::math_opt::MakeSkipZerosFilter ( )

Returns a filter that skips all key-value pairs with zero values (or false values for bool).

Example: const auto filter = MakeSkipZerosFilter<Variable>();

Definition at line 154 of file map_filter.h.

◆ MakeTrivialBounds()

ObjectiveBoundsProto operations_research::math_opt::MakeTrivialBounds ( bool is_maximize)

Returns trivial bounds.

Trivial bounds are:

  • for a maximization:
    • primal_bound: -inf
    • dual_bound : +inf
  • for a minimization:
    • primal_bound: +inf
    • dual_bound : -inf

Definition at line 188 of file math_opt_proto_utils.cc.

◆ MakeUpdateDataFieldIterator()

template<auto PointerToMember, typename BaseIter >
auto operations_research::math_opt::MakeUpdateDataFieldIterator ( BaseIter base_iter)

Returns a new iterator on the field identified by the PointerToMember wrapping an iterator of a: std::vector<std::pair<ID, std::unique_ptr<UpdateData>>

Example: std::vector<std::pair<Id, std::unique_ptr<UpdateData>> update_trackers; const auto begin = MakeUpdateDataFieldIterator<&UpdateData::field>(update_trackers.cbegin());

Definition at line 104 of file iterators.h.

◆ MakeUpdateDataFieldRange()

template<auto PointerToMember, typename UpdateTrackers >
auto operations_research::math_opt::MakeUpdateDataFieldRange ( const UpdateTrackers & trackers)

Returns a range (begin and end iterator) pointing to the field identified by the PointerToMember from an iterable of std::pair<ID, std::unique_ptr<UpdateData>

Example: std::vector<std::pair<Id, std::unique_ptr<UpdateData>> trackers; for(auto& f : MakeUpdateDataFieldRange<&UpdateData::field>(trackers)) { ... }

Definition at line 121 of file iterators.h.

◆ MakeView() [1/4]

template<typename Collection , typename T = typename Collection::value_type>
SparseVectorView< T > operations_research::math_opt::MakeView ( absl::Span< const int64_t > ids,
const Collection & values )

Returns a view for values that are vector-like collection like std::vector<T> or google::protobuf::RepeatedField<T>. See other overloads for other values-types.

Definition at line 148 of file sparse_vector_view.h.

◆ MakeView() [2/4]

template<typename T >
SparseVectorView< const T * > operations_research::math_opt::MakeView ( const google::protobuf::RepeatedField< int64_t > & ids,
const google::protobuf::RepeatedPtrField< T > & values )

Returns a view for values that are google::protobuf::RepeatedPtrField<T>. Common use for this overload is when T = std::string. See other overloads for other values-types.

Definition at line 157 of file sparse_vector_view.h.

◆ MakeView() [3/4]

template<typename T >
SparseVectorView< T > operations_research::math_opt::MakeView ( const SparseVector< T > & sparse_vector)

Returns a view for values in a SparseVector. For this case it is preferred over the two-argument overloads. See other overloads for other values-types.

Definition at line 175 of file sparse_vector_view.h.

◆ MakeView() [4/4]

template<typename SparseVectorProto , typename T = sparse_value_type<SparseVectorProto>>
SparseVectorView< T > operations_research::math_opt::MakeView ( const SparseVectorProto & sparse_vector)

Returns a view for values in a SparseDoubleVectorProto, SparseBoolVectorProto or similar structure. For such cases, it is preferred over the two-argument overloads. See other overloads for other values-types.

Definition at line 168 of file sparse_vector_view.h.

◆ MapKeys() [1/2]

template<typename K , typename V >
std::vector< K > operations_research::math_opt::MapKeys ( const absl::flat_hash_map< K, V > & in_map)

Definition at line 35 of file sorted.h.

◆ MapKeys() [2/2]

template<typename K , typename V >
std::vector< K > operations_research::math_opt::MapKeys ( const google::protobuf::Map< K, V > & in_map)

Definition at line 45 of file sorted.h.

◆ MATCHER_P()

operations_research::math_opt::MATCHER_P ( FirstElementIs ,
first_element_matcher ,
(negation ? absl::StrCat("is empty or first element ", MatcherToString(first_element_matcher, true)) :absl::StrCat("has at least one element and first element ", MatcherToString(first_element_matcher, false)))  )

Definition at line 699 of file matchers.cc.

◆ MatcherToString() [1/2]

template<typename T >
std::string operations_research::math_opt::MatcherToString ( const ::testing::PolymorphicMatcher< T > & matcher,
bool negate )

clang-format off Polymorphic matchers do not always define DescribeTo, The <T> type may not be a matcher, but it will implement DescribeTo. clang-format on

Definition at line 694 of file matchers.cc.

◆ MatcherToString() [2/2]

template<typename T >
std::string operations_research::math_opt::MatcherToString ( const Matcher< T > & matcher,
bool negate )

Definition at line 685 of file matchers.cc.

◆ MatcherToStringImpl()

template<typename MatcherType >
std::string operations_research::math_opt::MatcherToStringImpl ( const MatcherType & matcher,
const bool negate )

Definition at line 674 of file matchers.cc.

◆ MATH_OPT_DEFINE_ENUM() [1/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( BasisStatus ,
BASIS_STATUS_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [2/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( CallbackEvent ,
CALLBACK_EVENT_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [3/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( Emphasis ,
EMPHASIS_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [4/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( FeasibilityStatus ,
FEASIBILITY_STATUS_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [5/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( Limit ,
LIMIT_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [6/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( LPAlgorithm ,
LP_ALGORITHM_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [7/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( SolutionStatus ,
SOLUTION_STATUS_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [8/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( SolverType ,
SOLVER_TYPE_UNSPECIFIED  )

◆ MATH_OPT_DEFINE_ENUM() [9/9]

operations_research::math_opt::MATH_OPT_DEFINE_ENUM ( TerminationReason ,
TERMINATION_REASON_UNSPECIFIED  )

◆ MATH_OPT_REGISTER_SOLVER() [1/3]

operations_research::math_opt::MATH_OPT_REGISTER_SOLVER ( SOLVER_TYPE_CP_SAT ,
CpSatSolver::New  )

◆ MATH_OPT_REGISTER_SOLVER() [2/3]

operations_research::math_opt::MATH_OPT_REGISTER_SOLVER ( SOLVER_TYPE_HIGHS ,
HighsSolver::New  )

◆ MATH_OPT_REGISTER_SOLVER() [3/3]

operations_research::math_opt::MATH_OPT_REGISTER_SOLVER ( SOLVER_TYPE_PDLP ,
PdlpSolver::New  )

◆ MathOptModelToMPModelProto() [1/2]

absl::StatusOr<::operations_research::MPModelProto > operations_research::math_opt::MathOptModelToMPModelProto ( const ::operations_research::math_opt::ModelProto & model)
Todo
(user): use the constraint iterator from scip_solver.cc here.

Definition at line 389 of file proto_converter.cc.

◆ MathOptModelToMPModelProto() [2/2]

absl::StatusOr< MPModelProto > operations_research::math_opt::MathOptModelToMPModelProto ( const ModelProto & model)

Returns a linear_solver MPModelProto equivalent to the input math_opt Model. The input Model must be in a valid state, as checked by ValidateModel.

Variables are created in the same order as they appear in model.variables. Hence the returned .variable(i) corresponds to input model.variables.ids(i).

The linear_solver Model stores all general constraints (e.g., quadratic, SOS) in a single repeated field, while ModelProto stores then in separate maps. Therefore neither the relative ordering, nor the raw IDs, of general constraints are preserved in the resulting Model.

◆ MemberPointerClassType()

template<typename V , typename C >
C operations_research::math_opt::MemberPointerClassType ( V C::* )

◆ MemberPointerValueType()

template<typename V , typename C >
V operations_research::math_opt::MemberPointerValueType ( V C::* )

The "functions" are used to extract the types of the field and of the class from pointers-to-member. They have no implementation since they are only used with decltype.

Example: int A::* ptr = &A::x; decltype(MemberPointerValueType(PointerToMember)) v; decltype(MemberPointerClassType(PointerToMember)) c; ///< The type of v is int and the type of c is A.

◆ Minimize()

model operations_research::math_opt::Minimize ( x )

◆ ModelIsSupported()

absl::Status operations_research::math_opt::ModelIsSupported ( const ModelProto & model,
const SupportedProblemStructures & support_menu,
absl::string_view solver_name )

Returns an InvalidArgumentError (respectively, UnimplementedError) if a problem structure is present in model and not supported (resp., not yet implemented) according to support_menu.

Definition at line 387 of file math_opt_proto_utils.cc.

◆ ModelProtoFromLp()

absl::StatusOr< ModelProto > operations_research::math_opt::ModelProtoFromLp ( absl::string_view lp_data)

Parses a the model in "CPLEX LP" format.

This function creates and destroys local temporary files and thus is not portable.

For large models, this will not work on diskless jobs in prod.

Warnings:

  • Only a linear objective and linear constraints are supported. When SCIP is used, indicator constraints are also supported.
  • The names of indicator constraints are not preserved when using SCIP
  • The variables may be permuted.
  • Two sided constraints are not in the LP format. If you round trip a Model Proto with lp_converter.h, the two sided constraints are and rewritten as two one sided constraints with new names.

OR-Tools does not have an LP file parser, so we go from LP file to SCIP, then export to MPS, parse the MPS to ModelProto. This is not efficient, but usually still much faster than solving an LP or MIP. Note the SCIP LP parser actually supports SOS and quadratics, but the OR-tools MPS reader does not.

It would be preferable to write an LP Parser from scratch and delete this.

For more information about the different LP file formats: http://lpsolve.sourceforge.net/5.5/lp-format.htm http://lpsolve.sourceforge.net/5.5/CPLEX-format.htm https://www.ibm.com/docs/en/icos/12.8.0.0?topic=cplex-lp-file-format-algebraic-representation http://www.gurobi.com/documentation/5.1/reference-manual/node871

Set up temporary files

Do the conversion

Definition at line 52 of file lp_parser.cc.

◆ ModelProtoToLp()

absl::StatusOr< std::string > operations_research::math_opt::ModelProtoToLp ( const ModelProto & model)

Returns the model in "CPLEX LP" format.

The RemoveNames() function can be used on the model to remove names if they should not be exported.

Warning
LP format does not support "range constraints" (linear constraints with both upper and lower bounds). An equivalent model without range constraints is exported instead.

For more information about the different LP file formats: http://lpsolve.sourceforge.net/5.5/lp-format.htm http://lpsolve.sourceforge.net/5.5/CPLEX-format.htm https://www.ibm.com/docs/en/icos/12.8.0.0?topic=cplex-lp-file-format-algebraic-representation http://www.gurobi.com/documentation/5.1/reference-manual/node871

Definition at line 27 of file lp_converter.cc.

◆ ModelProtoToMps()

absl::StatusOr< std::string > operations_research::math_opt::ModelProtoToMps ( const ModelProto & model)

Returns the model in MPS format.

The RemoveNames() function can be used on the model to remove names if they should not be exported.

Definition at line 29 of file mps_converter.cc.

◆ MoveVariablesToTheirBestFeasibleValue()

absl::StatusOr< VariableMap< double > > operations_research::math_opt::MoveVariablesToTheirBestFeasibleValue ( const Model & model,
const VariableMap< double > & input_solution,
absl::Span< const Variable > variables,
const MoveVariablesToTheirBestFeasibleValueOptions & options = {} )

Returns a solution that improves the objective value of the input model by moving the input variables' values to the their best feasible value (as defined by the objective) based on the constraints and other variables' values.

The input_solution has to contain a value for each variable in the model. The input model must not be unbounded (and error is returned if this is the case).

Only the value of the variables listed in variables are modified. The variables are considered in the order they appear in the vector. Thus the end result depends on this ordering:

  • If multiple variables appear in the same constraint, the first variable may use up all the constraint's slack; preventing next variables to improve the objective as much as they could.

    This issue can be fixed by sorting variables by their objective coefficient. But this may conflict with the order picked to solve dependencies as explained below.

  • A variable improvement may be limited by another variable it depends on. If it appears first and the second variable's value changes, we may end up with some slack that the first variable could use.

    This issue can be solved by either:

    • Calling this function multiple times until no more variables are changed.
    • Sorting the input variables in a correct order so that the limiting variable appear first.

The variables' values are changed in the direction that improves the objective. Variables that are not in the objective are not modified.

This function is typically useful when solving MIP with a non-zero gap or when the time limit interrupts the solve early. In those cases a MIP solver can return a solution where some variables can trivially be changed to improve the objective but since the solution fits in the termination criteria (either the gap or the time limit) the solver did not do it.

Validate the inputs.

Todo
(b/193121090): here we build the proto as the APIs of MathOpt only works with the proto and can't use the C++ Model (or ModelStorage).

We maintain a solution with updated value for each variable in the order of traversal.

Invariant: values are finite.

We also maintain the values of each constraint in sync with the values in new_solution.

Invariant: constraints_value.at(c) == ConstraintValue(c, new_solution)

The variable can't change the objective. We ignore it.

We will then compute the best bound of the variable value based on its own bounds and all the constraints it belongs to. This best bound is based on the sign of the objective coefficient and the objective direction (min or max). The positive_v_change value tracks which direction this is.

The best_v_bound is the maximum variable's value. We initialize it with the variable's bounds, we use +/-inf if bounds are infinite.

Now iterate on constraints that contain the variable to find the most limiting one.

For reason explained below we also keep track of the fact that we found a limiting constraint, i.e. a constraint with a finite bound in the direction of improvement of v.

The ValidateModel() should have failed.

The variable has no influence on the constraint.

Based on the constraint coefficient's sign and the variable change sign, we compute which constraint bound we need to consider.

If the bound is not finite, ignore this constraint.

We have one constraint with a finite bound if we reach this point.

Compute the bound that the constraint put on the variable.

If the constraint value is not finite (could be +/-inf or NaN due to computation), we consider we can't improve the value of v.

We could here recompute the constraint value without v and do something if the value is finite but in practice it is likely to be an issue.

If we are out of the bounds of the constraint, we can't improve v.

Note
when use_constraint_upper_bound is false we return when c_value < used_bound, i.e. we use < instead of <=. In practice though the case c_value == used_bound is covered by the computation and will return v_current_value.

Can be +/-inf; see comment about some_constraints_are_limiting below.

Update best_v_bound based on the constraint.

Here we don't fail if constraints have finite bounds but computations lead to infinite values. This typically occurs when the limiting constraint has a huge bound and the variable coefficient in the constraint is small. We could improve the algorithm to pick a finite value for the variable that does not lead to an overflow but this is non trivial.

If there is no limiting constraint with a finite bound and the variable own bound is infinite, the model is actually unbounded.

Make sure the value is integral for integer variables. If we have a constraint limiting x <= 1.5 we want to use x = 1.

Note
since best_v_bound is finite, floor or ceil also are.

If we have find no improvement; skip this variable.

Apply the change to new_solution.

As v_improved_value is finite the invariant holds.

Restore the invariant of constraint_values based on the new_solution.

Here we could incrementally update values based on the change of new_solution.at(v) and the coefficient for (c, v). But since we are doing floating point computation, we may introduce some errors for each variable being changed. It is easier to recompute the constraints values from scratch instead.

Definition at line 87 of file solution_improvement.cc.

◆ MPModelProtoSolutionHintToMathOptHint()

absl::StatusOr< std::optional< SolutionHintProto > > operations_research::math_opt::MPModelProtoSolutionHintToMathOptHint ( const MPModelProto & model)

Returns the optional model.solution_hint as a MathOpt hint. Returns nullopt if no hint is set on the input model or if the hint is empty.

The input MPModelProto must be valid, as checked by FindErrorInMPModelProto().

Definition at line 370 of file proto_converter.cc.

◆ MPModelProtoToMathOptModel() [1/2]

absl::StatusOr<::operations_research::math_opt::ModelProto > operations_research::math_opt::MPModelProtoToMathOptModel ( const ::operations_research::MPModelProto & model)

This allocation is reused across loop iterations, use caution!

Note
the open-source version of ASSIGN_OR_RETURN does not support inlining the new_indicator_constraint expression.

Definition at line 217 of file proto_converter.cc.

◆ MPModelProtoToMathOptModel() [2/2]

absl::StatusOr< ModelProto > operations_research::math_opt::MPModelProtoToMathOptModel ( const MPModelProto & model)

Returns a ModelProto equivalent to the input linear_solver Model. The input MPModelProto must be valid, as checked by FindErrorInMPModelProto().

The linear_solver Model stores all general constraints (e.g., quadratic, SOS) in a single repeated field, while ModelProto stores then in separate maps. The output constraint maps will each be populated with consecutive indices starting from 0 (hence the indices may change).

MPModelProto can contain an optional solution_hint which is ignored by this function. In MathOpt the hints are parameters passed to the solve functions instead of being in the model. The MPModelProtoSolutionHintToMathOptHint() function can be used to extract it.

◆ MpsToModelProto()

absl::StatusOr< ModelProto > operations_research::math_opt::MpsToModelProto ( absl::string_view mps_data)

Converts a string with the contents of an MPS file into a ModelProto.

Definition at line 43 of file mps_converter.cc.

◆ NewIncrementalSolver()

absl::StatusOr< std::unique_ptr< IncrementalSolver > > operations_research::math_opt::NewIncrementalSolver ( Model * model,
SolverType solver_type,
SolverInitArguments arguments = {} )

Creates a new incremental solve for the given model. It may returns an error if the parameters are invalid (for example if the selected solver is not linked in the binary).

The returned IncrementalSolver keeps a copy of arguments. Thus the content of arguments.non_streamable (for example pointers to solver specific struct) must be valid until the destruction of the IncrementalSolver. It also registers on the Model to keep track of updates (see class documentation for details).

Definition at line 82 of file solve.cc.

◆ NewPrimaryEnvFromISVKey()

absl::StatusOr< GRBenv * > operations_research::math_opt::NewPrimaryEnvFromISVKey ( const GurobiIsvKey & isv_key)

Returns a new primary Gurobi environment initialized with an ISV key.

See http://www.gurobi.com/products/licensing-pricing/isv-program.

Surprisingly, even when Gurobi fails to load the environment, it still creates one. Here we make sure to free it properly. If initialization succeeds, we Cancel() this below.

We use GRBgeterrormsg() to get the associated error message that goes with the error and the contains additional data like the user, the host, and the hostid.

We want to turn off logging before setting the ISV key so that it doesn't leak. We store the original logging state, and reset it at the end.

Reset output flag to its original value.

Environment initialization succeeded, we don't want to free it upon exiting this function.

Definition at line 30 of file gurobi_isv.cc.

◆ NewPrimaryEnvironment()

absl::StatusOr< GRBenvUniquePtr > operations_research::math_opt::NewPrimaryEnvironment ( std::optional< GurobiInitializerProto::ISVKey > proto_isv_key = {})

Returns a new primary environment.

The typical use of this function is to share the same environment between multiple solver instances. This is necessary when a single-use license is used since only one primary environment can exists in that case.

A single primary environment is not thread-safe and thus it should only be used in a single thread. Even if the user has a license that authorizes multiple primary environments, Gurobi still recommends to use only one and to share it as it is more efficient (see GRBloadenv() documentation).

Of course, if the user wants to run multiple solves in parallel and has a license that authorizes that, one environment should be used per thread.

The primary environment can be passed to MathOpt via the NonStreamableGurobiInitArguments structure and its primary_env field.

The optional ISV key can be used to build the environment from an ISV key instead of using the default license file. See http://www.gurobi.com/products/licensing-pricing/isv-program for details.

Example with default license file:

///< Solving two models on the same thread, sharing the same primary ///< environment. Model model_1; Model model_2;

...

ASSIGN_OR_RETURN(const GRBenvUniquePtr primary_env, NewPrimaryEnvironment());

NonStreamableGurobiInitArguments gurobi_args; gurobi_args.primary_env = primary_env.get();

ASSIGN_OR_RETURN( const std::unique_ptr<IncrementalSolver> incremental_solve_1, NewIncrementalSolver(model, SOLVER_TYPE_GUROBI, SolverInitArguments(gurobi_args))); ASSIGN_OR_RETURN( const std::unique_ptr<IncrementalSolver> incremental_solve_2, NewIncrementalSolver(model, SOLVER_TYPE_GUROBI, SolverInitArguments(gurobi_args)));

ASSIGN_OR_RETURN(const SolveResult result_1, incremental_solve_1->Solve()); ASSIGN_OR_RETURN(const SolveResult result_2, incremental_solve_2->Solve());

With ISV key:

ASSIGN_OR_RETURN(const GRBenvUniquePtr primary_env, NewPrimaryEnvironment(GurobiISVKey{ .name = "the name", .application_name = "the application", .expiration = 0, .key = "...", }.Proto()));

Definition at line 27 of file gurobi_init_arguments.cc.

◆ NoSolutionFoundTermination()

TerminationProto operations_research::math_opt::NoSolutionFoundTermination ( const LimitProto limit,
const absl::string_view detail )

Definition at line 173 of file math_opt_proto_utils.cc.

◆ NoSolutionFoundTerminationProto()

TerminationProto operations_research::math_opt::NoSolutionFoundTerminationProto ( bool is_maximize,
LimitProto limit,
std::optional< double > optional_dual_objective = std::nullopt,
absl::string_view detail = {} )

Returns a TERMINATION_REASON_NO_SOLUTION_FOUND termination with FEASIBILITY_STATUS_UNDETERMINED primal status.

Assumes dual solution exists iff optional_dual_objective is set even if infinite (some solvers return feasible dual solutions without an objective value). optional_dual_objective should not be set when limit is LIMIT_CUTOFF for a valid TerminationProto to be returned (use LimitCutoffTerminationProto() below instead).

It sets a trivial primal bound. The dual bound is either set to the optional_dual_objective if set, else to a trivial value.

Todo
(b/290359402): Consider improving to require a finite dual bound when dual feasible solutions are returned.

Definition at line 321 of file math_opt_proto_utils.cc.

◆ NumConstraints()

int operations_research::math_opt::NumConstraints ( const LinearConstraintsProto & linear_constraints)
inline

Definition at line 53 of file math_opt_proto_utils.h.

◆ NumMatrixNonzeros()

int operations_research::math_opt::NumMatrixNonzeros ( const SparseDoubleMatrixProto & matrix)
inline

Definition at line 57 of file math_opt_proto_utils.h.

◆ NumVariables()

int operations_research::math_opt::NumVariables ( const VariablesProto & variables)
inline

Definition at line 49 of file math_opt_proto_utils.h.

◆ ObjectiveBoundsNear()

testing::Matcher< ObjectiveBounds > operations_research::math_opt::ObjectiveBoundsNear ( const ObjectiveBounds & expected,
const double tolerance )

SolveResult termination reason matchers

Definition at line 607 of file matchers.cc.

◆ operator!=() [1/9]

bool operations_research::math_opt::operator!= ( const IndicatorConstraint & lhs,
const IndicatorConstraint & rhs )

Definition at line 129 of file indicator_constraint.h.

◆ operator!=() [2/9]

bool operations_research::math_opt::operator!= ( const LinearConstraint & lhs,
const LinearConstraint & rhs )

Definition at line 167 of file linear_constraint.h.

◆ operator!=() [3/9]

bool operations_research::math_opt::operator!= ( const Objective & lhs,
const Objective & rhs )

Definition at line 208 of file objective.h.

◆ operator!=() [4/9]

bool operations_research::math_opt::operator!= ( const QuadraticConstraint & lhs,
const QuadraticConstraint & rhs )

Definition at line 183 of file quadratic_constraint.h.

◆ operator!=() [5/9]

bool operations_research::math_opt::operator!= ( const SecondOrderConeConstraint & lhs,
const SecondOrderConeConstraint & rhs )

Definition at line 119 of file second_order_cone_constraint.h.

◆ operator!=() [6/9]

bool operations_research::math_opt::operator!= ( const Sos1Constraint & lhs,
const Sos1Constraint & rhs )

Definition at line 120 of file sos1_constraint.h.

◆ operator!=() [7/9]

bool operations_research::math_opt::operator!= ( const Sos2Constraint & lhs,
const Sos2Constraint & rhs )

Definition at line 121 of file sos2_constraint.h.

◆ operator!=() [8/9]

bool operations_research::math_opt::operator!= ( const Variable & lhs,
const Variable & rhs )
inline

Definition at line 1750 of file variable_and_expressions.h.

◆ operator!=() [9/9]

bool operations_research::math_opt::operator!= ( QuadraticTermKey lhs,
QuadraticTermKey rhs )
inline

Definition at line 2112 of file variable_and_expressions.h.

◆ operator*() [1/19]

QuadraticTerm operations_research::math_opt::operator* ( const double lhs,
QuadraticTerm rhs )
inline

-------------------------— Multiplication (*) --------------------------—

Note
A friend of QuadraticTerm, but does not touch variables

Definition at line 2474 of file variable_and_expressions.h.

◆ operator*() [2/19]

QuadraticExpression operations_research::math_opt::operator* ( const LinearExpression & lhs,
const LinearExpression & rhs )
inline

Definition at line 2547 of file variable_and_expressions.h.

◆ operator*() [3/19]

QuadraticExpression operations_research::math_opt::operator* ( const LinearExpression & lhs,
LinearTerm rhs )
inline

Definition at line 2536 of file variable_and_expressions.h.

◆ operator*() [4/19]

QuadraticExpression operations_research::math_opt::operator* ( const LinearExpression & lhs,
Variable rhs )
inline

Definition at line 2525 of file variable_and_expressions.h.

◆ operator*() [5/19]

LinearTerm operations_research::math_opt::operator* ( double coefficient,
LinearTerm term )
inline

Definition at line 1348 of file variable_and_expressions.h.

◆ operator*() [6/19]

LinearTerm operations_research::math_opt::operator* ( double coefficient,
Variable variable )
inline

Definition at line 1358 of file variable_and_expressions.h.

◆ operator*() [7/19]

LinearExpression operations_research::math_opt::operator* ( double lhs,
LinearExpression rhs )
inline

Definition at line 1577 of file variable_and_expressions.h.

◆ operator*() [8/19]

QuadraticExpression operations_research::math_opt::operator* ( double lhs,
QuadraticExpression rhs )
inline

Definition at line 2479 of file variable_and_expressions.h.

◆ operator*() [9/19]

LinearExpression operations_research::math_opt::operator* ( LinearExpression lhs,
double rhs )
inline

Definition at line 1572 of file variable_and_expressions.h.

◆ operator*() [10/19]

QuadraticExpression operations_research::math_opt::operator* ( LinearTerm lhs,
const LinearExpression & rhs )
inline

Definition at line 2514 of file variable_and_expressions.h.

◆ operator*() [11/19]

QuadraticTerm operations_research::math_opt::operator* ( LinearTerm lhs,
LinearTerm rhs )
inline

Definition at line 2509 of file variable_and_expressions.h.

◆ operator*() [12/19]

QuadraticTerm operations_research::math_opt::operator* ( LinearTerm lhs,
Variable rhs )
inline

Definition at line 2504 of file variable_and_expressions.h.

◆ operator*() [13/19]

LinearTerm operations_research::math_opt::operator* ( LinearTerm term,
double coefficient )
inline

Definition at line 1353 of file variable_and_expressions.h.

◆ operator*() [14/19]

QuadraticExpression operations_research::math_opt::operator* ( QuadraticExpression lhs,
double rhs )
inline

Definition at line 2574 of file variable_and_expressions.h.

◆ operator*() [15/19]

QuadraticTerm operations_research::math_opt::operator* ( QuadraticTerm lhs,
const double rhs )
inline
Note
A friend of QuadraticTerm, but does not touch variables

Definition at line 2569 of file variable_and_expressions.h.

◆ operator*() [16/19]

QuadraticExpression operations_research::math_opt::operator* ( Variable lhs,
const LinearExpression & rhs )
inline

Definition at line 2493 of file variable_and_expressions.h.

◆ operator*() [17/19]

QuadraticTerm operations_research::math_opt::operator* ( Variable lhs,
LinearTerm rhs )
inline

Definition at line 2488 of file variable_and_expressions.h.

◆ operator*() [18/19]

QuadraticTerm operations_research::math_opt::operator* ( Variable lhs,
Variable rhs )
inline

Definition at line 2484 of file variable_and_expressions.h.

◆ operator*() [19/19]

LinearTerm operations_research::math_opt::operator* ( Variable variable,
double coefficient )
inline

Definition at line 1362 of file variable_and_expressions.h.

◆ operator+() [1/35]

QuadraticExpression operations_research::math_opt::operator+ ( double lhs,
const QuadraticTerm & rhs )
inline

--------------------------— Addition (+) -------------------------------—

The binary methods, listed in lexicographic order based on (operator, lhs type #, rhs type #), with the type #s are listed above, are:

Arithmetic operators (non-member).

These are NOT required to explicitly CHECK that the underlying model storages agree between linear_terms_ and quadratic_terms_ unless they are a friend of QuadraticExpression. As much as possible, defer to the assignment operators and the initializer list constructor for QuadraticExpression.

Definition at line 2243 of file variable_and_expressions.h.

◆ operator+() [2/35]

QuadraticExpression operations_research::math_opt::operator+ ( const LinearExpression & lhs,
QuadraticExpression rhs )
inline

Definition at line 2276 of file variable_and_expressions.h.

◆ operator+() [3/35]

LinearExpression operations_research::math_opt::operator+ ( const LinearTerm & lhs,
const LinearTerm & rhs )
inline

Definition at line 1468 of file variable_and_expressions.h.

◆ operator+() [4/35]

QuadraticExpression operations_research::math_opt::operator+ ( const LinearTerm & lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2261 of file variable_and_expressions.h.

◆ operator+() [5/35]

LinearExpression operations_research::math_opt::operator+ ( const LinearTerm & lhs,
double rhs )
inline

Definition at line 1452 of file variable_and_expressions.h.

◆ operator+() [6/35]

QuadraticExpression operations_research::math_opt::operator+ ( const LinearTerm & lhs,
QuadraticExpression rhs )
inline

Definition at line 2265 of file variable_and_expressions.h.

◆ operator+() [7/35]

LinearExpression operations_research::math_opt::operator+ ( const LinearTerm & lhs,
Variable rhs )
inline

Definition at line 1460 of file variable_and_expressions.h.

◆ operator+() [8/35]

QuadraticExpression operations_research::math_opt::operator+ ( const QuadraticTerm & lhs,
const LinearTerm & rhs )
inline

Definition at line 2290 of file variable_and_expressions.h.

◆ operator+() [9/35]

QuadraticExpression operations_research::math_opt::operator+ ( const QuadraticTerm & lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2300 of file variable_and_expressions.h.

◆ operator+() [10/35]

QuadraticExpression operations_research::math_opt::operator+ ( const QuadraticTerm & lhs,
double rhs )
inline

Definition at line 2282 of file variable_and_expressions.h.

◆ operator+() [11/35]

QuadraticExpression operations_research::math_opt::operator+ ( const QuadraticTerm & lhs,
LinearExpression rhs )
inline

Definition at line 2294 of file variable_and_expressions.h.

◆ operator+() [12/35]

QuadraticExpression operations_research::math_opt::operator+ ( const QuadraticTerm & lhs,
QuadraticExpression rhs )
inline

Definition at line 2305 of file variable_and_expressions.h.

◆ operator+() [13/35]

QuadraticExpression operations_research::math_opt::operator+ ( const QuadraticTerm & lhs,
Variable rhs )
inline

Definition at line 2286 of file variable_and_expressions.h.

◆ operator+() [14/35]

LinearExpression operations_research::math_opt::operator+ ( double lhs,
const LinearTerm & rhs )
inline

Definition at line 1456 of file variable_and_expressions.h.

◆ operator+() [15/35]

LinearExpression operations_research::math_opt::operator+ ( double lhs,
LinearExpression rhs )
inline

Definition at line 1477 of file variable_and_expressions.h.

◆ operator+() [16/35]

QuadraticExpression operations_research::math_opt::operator+ ( double lhs,
QuadraticExpression rhs )
inline

Definition at line 2247 of file variable_and_expressions.h.

◆ operator+() [17/35]

LinearExpression operations_research::math_opt::operator+ ( double lhs,
Variable rhs )
inline

Definition at line 1444 of file variable_and_expressions.h.

◆ operator+() [18/35]

LinearExpression operations_research::math_opt::operator+ ( LinearExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 1500 of file variable_and_expressions.h.

◆ operator+() [19/35]

LinearExpression operations_research::math_opt::operator+ ( LinearExpression lhs,
const LinearTerm & rhs )
inline

Definition at line 1490 of file variable_and_expressions.h.

◆ operator+() [20/35]

QuadraticExpression operations_research::math_opt::operator+ ( LinearExpression lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2270 of file variable_and_expressions.h.

◆ operator+() [21/35]

LinearExpression operations_research::math_opt::operator+ ( LinearExpression lhs,
double rhs )
inline

Definition at line 1472 of file variable_and_expressions.h.

◆ operator+() [22/35]

LinearExpression operations_research::math_opt::operator+ ( LinearExpression lhs,
Variable rhs )
inline

Definition at line 1482 of file variable_and_expressions.h.

◆ operator+() [23/35]

LinearExpression operations_research::math_opt::operator+ ( LinearTerm lhs,
LinearExpression rhs )
inline

Definition at line 1495 of file variable_and_expressions.h.

◆ operator+() [24/35]

QuadraticExpression operations_research::math_opt::operator+ ( QuadraticExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 2326 of file variable_and_expressions.h.

◆ operator+() [25/35]

QuadraticExpression operations_research::math_opt::operator+ ( QuadraticExpression lhs,
const LinearTerm & rhs )
inline

Definition at line 2321 of file variable_and_expressions.h.

◆ operator+() [26/35]

QuadraticExpression operations_research::math_opt::operator+ ( QuadraticExpression lhs,
const QuadraticExpression & rhs )
inline

Definition at line 2338 of file variable_and_expressions.h.

◆ operator+() [27/35]

QuadraticExpression operations_research::math_opt::operator+ ( QuadraticExpression lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2332 of file variable_and_expressions.h.

◆ operator+() [28/35]

QuadraticExpression operations_research::math_opt::operator+ ( QuadraticExpression lhs,
double rhs )
inline

Definition at line 2311 of file variable_and_expressions.h.

◆ operator+() [29/35]

QuadraticExpression operations_research::math_opt::operator+ ( QuadraticExpression lhs,
Variable rhs )
inline

Definition at line 2316 of file variable_and_expressions.h.

◆ operator+() [30/35]

LinearExpression operations_research::math_opt::operator+ ( Variable lhs,
const LinearTerm & rhs )
inline

Definition at line 1464 of file variable_and_expressions.h.

◆ operator+() [31/35]

QuadraticExpression operations_research::math_opt::operator+ ( Variable lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2252 of file variable_and_expressions.h.

◆ operator+() [32/35]

LinearExpression operations_research::math_opt::operator+ ( Variable lhs,
double rhs )
inline

Definition at line 1440 of file variable_and_expressions.h.

◆ operator+() [33/35]

LinearExpression operations_research::math_opt::operator+ ( Variable lhs,
LinearExpression rhs )
inline

Definition at line 1486 of file variable_and_expressions.h.

◆ operator+() [34/35]

QuadraticExpression operations_research::math_opt::operator+ ( Variable lhs,
QuadraticExpression rhs )
inline

Definition at line 2256 of file variable_and_expressions.h.

◆ operator+() [35/35]

LinearExpression operations_research::math_opt::operator+ ( Variable lhs,
Variable rhs )
inline

Definition at line 1448 of file variable_and_expressions.h.

◆ operator-() [1/38]

QuadraticExpression operations_research::math_opt::operator- ( const LinearExpression & lhs,
QuadraticExpression rhs )
inline

Definition at line 2398 of file variable_and_expressions.h.

◆ operator-() [2/38]

LinearExpression operations_research::math_opt::operator- ( const LinearTerm & lhs,
const LinearTerm & rhs )
inline

Definition at line 1533 of file variable_and_expressions.h.

◆ operator-() [3/38]

QuadraticExpression operations_research::math_opt::operator- ( const LinearTerm & lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2382 of file variable_and_expressions.h.

◆ operator-() [4/38]

LinearExpression operations_research::math_opt::operator- ( const LinearTerm & lhs,
double rhs )
inline

Definition at line 1517 of file variable_and_expressions.h.

◆ operator-() [5/38]

QuadraticExpression operations_research::math_opt::operator- ( const LinearTerm & lhs,
QuadraticExpression rhs )
inline

Definition at line 2386 of file variable_and_expressions.h.

◆ operator-() [6/38]

LinearExpression operations_research::math_opt::operator- ( const LinearTerm & lhs,
Variable rhs )
inline

Definition at line 1525 of file variable_and_expressions.h.

◆ operator-() [7/38]

QuadraticExpression operations_research::math_opt::operator- ( const QuadraticTerm & lhs,
const LinearTerm & rhs )
inline

Definition at line 2413 of file variable_and_expressions.h.

◆ operator-() [8/38]

QuadraticExpression operations_research::math_opt::operator- ( const QuadraticTerm & lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2423 of file variable_and_expressions.h.

◆ operator-() [9/38]

QuadraticExpression operations_research::math_opt::operator- ( const QuadraticTerm & lhs,
double rhs )
inline

Definition at line 2405 of file variable_and_expressions.h.

◆ operator-() [10/38]

QuadraticExpression operations_research::math_opt::operator- ( const QuadraticTerm & lhs,
LinearExpression rhs )
inline

Definition at line 2417 of file variable_and_expressions.h.

◆ operator-() [11/38]

QuadraticExpression operations_research::math_opt::operator- ( const QuadraticTerm & lhs,
QuadraticExpression rhs )
inline

Definition at line 2428 of file variable_and_expressions.h.

◆ operator-() [12/38]

QuadraticExpression operations_research::math_opt::operator- ( const QuadraticTerm & lhs,
Variable rhs )
inline

Definition at line 2409 of file variable_and_expressions.h.

◆ operator-() [13/38]

LinearExpression operations_research::math_opt::operator- ( double lhs,
const LinearTerm & rhs )
inline

Definition at line 1521 of file variable_and_expressions.h.

◆ operator-() [14/38]

QuadraticExpression operations_research::math_opt::operator- ( double lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2364 of file variable_and_expressions.h.

◆ operator-() [15/38]

LinearExpression operations_research::math_opt::operator- ( double lhs,
LinearExpression rhs )
inline

Definition at line 1542 of file variable_and_expressions.h.

◆ operator-() [16/38]

QuadraticExpression operations_research::math_opt::operator- ( double lhs,
QuadraticExpression rhs )
inline

Definition at line 2368 of file variable_and_expressions.h.

◆ operator-() [17/38]

LinearExpression operations_research::math_opt::operator- ( double lhs,
Variable rhs )
inline

Definition at line 1509 of file variable_and_expressions.h.

◆ operator-() [18/38]

LinearExpression operations_research::math_opt::operator- ( LinearExpression expr)
inline

We intentionally pass one of the LinearExpression argument by value so that we don't make unnecessary copies of temporary objects by using the move constructor and the returned values optimization (RVO).

Definition at line 1432 of file variable_and_expressions.h.

◆ operator-() [19/38]

LinearExpression operations_research::math_opt::operator- ( LinearExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 1567 of file variable_and_expressions.h.

◆ operator-() [20/38]

LinearExpression operations_research::math_opt::operator- ( LinearExpression lhs,
const LinearTerm & rhs )
inline

Definition at line 1556 of file variable_and_expressions.h.

◆ operator-() [21/38]

QuadraticExpression operations_research::math_opt::operator- ( LinearExpression lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2392 of file variable_and_expressions.h.

◆ operator-() [22/38]

LinearExpression operations_research::math_opt::operator- ( LinearExpression lhs,
double rhs )
inline

Definition at line 1537 of file variable_and_expressions.h.

◆ operator-() [23/38]

LinearExpression operations_research::math_opt::operator- ( LinearExpression lhs,
Variable rhs )
inline

Definition at line 1548 of file variable_and_expressions.h.

◆ operator-() [24/38]

LinearExpression operations_research::math_opt::operator- ( LinearTerm lhs,
LinearExpression rhs )
inline

Definition at line 1561 of file variable_and_expressions.h.

◆ operator-() [25/38]

QuadraticExpression operations_research::math_opt::operator- ( QuadraticExpression expr)
inline

We have 6 types that we must consider arithmetic among:

  1. double (scalar value)
  2. Variable (affine value)
  3. LinearTerm (affine value)
  4. LinearExpression (affine value)
  5. QuadraticTerm (quadratic value)
  6. QuadraticExpression (quadratic value) We care only about those methods that result in a QuadraticExpression. For example, multiplying a linear value with a linear value, or adding a scalar to a quadratic value. The single unary method is:
Note
A friend of QuadraticExpression, but does not touch variables

Definition at line 2353 of file variable_and_expressions.h.

◆ operator-() [26/38]

QuadraticExpression operations_research::math_opt::operator- ( QuadraticExpression lhs,
const LinearExpression & rhs )
inline
Note
operator-(QuadraticExpression, const LinearTerm) appears above

Definition at line 2453 of file variable_and_expressions.h.

◆ operator-() [27/38]

QuadraticExpression operations_research::math_opt::operator- ( QuadraticExpression lhs,
const LinearTerm & rhs )
inline
Note
Out-of-order for compilation purposes

Definition at line 2441 of file variable_and_expressions.h.

◆ operator-() [28/38]

QuadraticExpression operations_research::math_opt::operator- ( QuadraticExpression lhs,
const QuadraticExpression & rhs )
inline

Definition at line 2465 of file variable_and_expressions.h.

◆ operator-() [29/38]

QuadraticExpression operations_research::math_opt::operator- ( QuadraticExpression lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2459 of file variable_and_expressions.h.

◆ operator-() [30/38]

QuadraticExpression operations_research::math_opt::operator- ( QuadraticExpression lhs,
double rhs )
inline

Definition at line 2435 of file variable_and_expressions.h.

◆ operator-() [31/38]

QuadraticExpression operations_research::math_opt::operator- ( QuadraticExpression lhs,
Variable rhs )
inline

Definition at line 2446 of file variable_and_expressions.h.

◆ operator-() [32/38]

QuadraticTerm operations_research::math_opt::operator- ( QuadraticTerm term)
inline

------------------------— Subtraction (-) ------------------------------—

We declare those operator overloads that result in a QuadraticTerm, stated in lexicographic ordering based on lhs type, rhs type):

Note
A friend of QuadraticTerm, but does not touch variables

Definition at line 2347 of file variable_and_expressions.h.

◆ operator-() [33/38]

LinearExpression operations_research::math_opt::operator- ( Variable lhs,
const LinearTerm & rhs )
inline

Definition at line 1529 of file variable_and_expressions.h.

◆ operator-() [34/38]

QuadraticExpression operations_research::math_opt::operator- ( Variable lhs,
const QuadraticTerm & rhs )
inline

Definition at line 2374 of file variable_and_expressions.h.

◆ operator-() [35/38]

LinearExpression operations_research::math_opt::operator- ( Variable lhs,
double rhs )
inline

Definition at line 1505 of file variable_and_expressions.h.

◆ operator-() [36/38]

LinearExpression operations_research::math_opt::operator- ( Variable lhs,
LinearExpression rhs )
inline

Definition at line 1552 of file variable_and_expressions.h.

◆ operator-() [37/38]

QuadraticExpression operations_research::math_opt::operator- ( Variable lhs,
QuadraticExpression rhs )
inline

Definition at line 2378 of file variable_and_expressions.h.

◆ operator-() [38/38]

LinearExpression operations_research::math_opt::operator- ( Variable lhs,
Variable rhs )
inline

Definition at line 1513 of file variable_and_expressions.h.

◆ operator/() [1/5]

LinearExpression operations_research::math_opt::operator/ ( LinearExpression lhs,
double rhs )
inline

Definition at line 1582 of file variable_and_expressions.h.

◆ operator/() [2/5]

LinearTerm operations_research::math_opt::operator/ ( LinearTerm term,
double coefficient )
inline

Definition at line 1366 of file variable_and_expressions.h.

◆ operator/() [3/5]

QuadraticExpression operations_research::math_opt::operator/ ( QuadraticExpression lhs,
double rhs )
inline

Definition at line 2587 of file variable_and_expressions.h.

◆ operator/() [4/5]

QuadraticTerm operations_research::math_opt::operator/ ( QuadraticTerm lhs,
const double rhs )
inline

----------------------------— Division (/) -----------------------------—

Note
A friend of QuadraticTerm, but does not touch variables

Definition at line 2582 of file variable_and_expressions.h.

◆ operator/() [5/5]

LinearTerm operations_research::math_opt::operator/ ( Variable variable,
double coefficient )
inline

Definition at line 1371 of file variable_and_expressions.h.

◆ operator<<() [1/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const BoundedLinearExpression & bounded_expression )

Definition at line 101 of file variable_and_expressions.cc.

◆ operator<<() [2/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const BoundedQuadraticExpression & bounded_expression )

Definition at line 185 of file variable_and_expressions.cc.

◆ operator<<() [3/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const IndicatorConstraint & constraint )
inline

Streams the name of the constraint, as registered upon constraint creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.
Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 139 of file indicator_constraint.h.

◆ operator<<() [4/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const InfeasibleSubsystemSupport & support_menu )

Definition at line 43 of file infeasible_subsystem_tests.cc.

◆ operator<<() [5/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const InfeasibleSubsystemTestParameters & params )

Definition at line 51 of file infeasible_subsystem_tests.cc.

◆ operator<<() [6/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const IpParameterTestParameters & params )

Definition at line 165 of file ip_parameter_tests.cc.

◆ operator<<() [7/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const LinearConstraint & linear_constraint )
inline

Streams the name of the constraint, as registered upon constraint creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.
Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 177 of file linear_constraint.h.

◆ operator<<() [8/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const LinearExpression & expression )
Todo
(b/169415597): improve linear expression format:
  • make sure to quote the variable name so that we support:

Definition at line 81 of file variable_and_expressions.cc.

◆ operator<<() [9/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const Model & model )

Prints the objective, the constraints and the variables of the model over several lines in a human-readable way. Includes a new line at the end of the model.

Definition at line 287 of file model.cc.

◆ operator<<() [10/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const Objective & objective )

Streams the name of the objective, as registered upon objective creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 61 of file objective.cc.

◆ operator<<() [11/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const ObjectiveBounds & objective_bounds )

Definition at line 66 of file solve_result.cc.

◆ operator<<() [12/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const ParameterSupport & param_support )

Definition at line 110 of file ip_parameter_tests.cc.

◆ operator<<() [13/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const ProblemStatus & problem_status )

Definition at line 433 of file solve_result.cc.

◆ operator<<() [14/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const QuadraticConstraint & constraint )
inline

Streams the name of the constraint, as registered upon constraint creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.
Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 194 of file quadratic_constraint.h.

◆ operator<<() [15/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const QuadraticExpression & expr )
Todo
(b/169415597): improve quadratic expression formatting. See b/170991498 for desired improvements for LinearExpression streaming which are also applicable here.

Definition at line 155 of file variable_and_expressions.cc.

◆ operator<<() [16/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const QuadraticTermKey & key )
inline

Definition at line 2102 of file variable_and_expressions.h.

◆ operator<<() [17/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const SecondOrderConeConstraint & constraint )
inline

Streams the name of the constraint, as registered upon constraint creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.
Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 129 of file second_order_cone_constraint.h.

◆ operator<<() [18/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const SolveResultSupport & solve_result_support )

Definition at line 94 of file ip_parameter_tests.cc.

◆ operator<<() [19/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const SolveStats & solve_stats )

Definition at line 475 of file solve_result.cc.

◆ operator<<() [20/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const Sos1Constraint & constraint )
inline

Streams the name of the constraint, as registered upon constraint creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.
Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 129 of file sos1_constraint.h.

◆ operator<<() [21/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const Sos2Constraint & constraint )
inline

Streams the name of the constraint, as registered upon constraint creation, or a short default if none was provided.

Todo
(b/170992529): handle quoting of invalid characters in the name.
Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 130 of file sos2_constraint.h.

◆ operator<<() [22/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const Termination & termination )

Definition at line 387 of file solve_result.cc.

◆ operator<<() [23/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & ostr,
const Variable & variable )
inline
Todo
(b/170992529): handle quoting of invalid characters in the name.
Todo
(b/170992529): handle quoting of invalid characters in the name.

Definition at line 1310 of file variable_and_expressions.h.

◆ operator<<() [24/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const BaseSolver::ComputeInfeasibleSubsystemArgs & args )

Definition at line 43 of file base_solver.cc.

◆ operator<<() [25/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const BaseSolver::SolveArgs & args )

Definition at line 32 of file base_solver.cc.

◆ operator<<() [26/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const BranchPrioritiesTestParams & params )

Definition at line 54 of file ip_model_solve_parameters_tests.cc.

◆ operator<<() [27/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const CallbackTestParams & params )

Definition at line 108 of file callback_tests.cc.

◆ operator<<() [28/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const ComputeInfeasibleSubsystemResult & result )

Definition at line 388 of file compute_infeasible_subsystem_result.cc.

◆ operator<<() [29/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const ConstantFormatter formatter )
inline

Do nothing.

Definition at line 72 of file formatters.h.

◆ operator<<() [30/57]

template<typename E , typename = std::enable_if_t<Enum<E>::kIsImplemented>>
std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const E value )

Overload of operator<< for enum types that implements Enum<E>.

It calls EnumToOptString(), printing the returned value if not nullopt. When nullopt it prints the enum numeric value instead.

Definition at line 235 of file enums.h.

◆ operator<<() [31/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const FileFormat f )

Definition at line 74 of file file_format_flags.cc.

◆ operator<<() [32/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const GenericTestParameters & params )

Definition at line 66 of file generic_tests.cc.

◆ operator<<() [33/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const InvalidInputTestParameters & params )

Definition at line 40 of file invalid_input_tests.cc.

◆ operator<<() [34/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const InvalidParameterTestParams & params )

Definition at line 59 of file invalid_input_tests.cc.

◆ operator<<() [35/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const IpMultipleSolutionsTestParams & params )

Definition at line 29 of file ip_multiple_solutions_tests.cc.

◆ operator<<() [36/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const LargeInstanceTestParams & params )

Definition at line 178 of file ip_parameter_tests.cc.

◆ operator<<() [37/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const LazyConstraintsTestParams & params )

Definition at line 61 of file ip_model_solve_parameters_tests.cc.

◆ operator<<() [38/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const LeadingCoefficientFormatter formatter )
inline

Do nothing.

Definition at line 37 of file formatters.h.

◆ operator<<() [39/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const LogicalConstraintTestParameters & params )

Definition at line 54 of file logical_constraint_tests.cc.

◆ operator<<() [40/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const LpIncompleteSolveTestParams & params )

Definition at line 56 of file lp_incomplete_solve_tests.cc.

◆ operator<<() [41/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const LpModelSolveParametersTestParameters & params )

Definition at line 31 of file lp_model_solve_parameters_tests.cc.

◆ operator<<() [42/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const LpParameterTestParams & params )

Definition at line 53 of file lp_parameter_tests.cc.

◆ operator<<() [43/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const MessageCallbackTestParams & params )

Definition at line 62 of file callback_tests.cc.

◆ operator<<() [44/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const ModelRanges & ranges )

Prints the ranges with std::setprecision(2) and std::scientific (restoring the stream flags after printing).

It prints a multi-line table list of ranges. The last line does NOT end with a new line thus the caller should use std::endl if appropriate (see example).

Example:

std::cout << "Model xxx ranges:\n" << ComputeModelRanges(model) << std::endl;

LOG(INFO) << "Model xxx ranges:\n" << ComputeModelRanges(model);

Numbers are printed in scientific notation with a precision of 2. Since they are expected to be positive we can ignore the optional leading minus sign. We thus expects d.dde[+-]dd(d)? (the exponent is at least 2 digits but double can require 3 digits, with max +308 and min -308). Thus we can use a width of 9 to align the ranges properly.

Definition at line 70 of file statistics.cc.

◆ operator<<() [45/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const ModelSubset & model_subset )

Definition at line 306 of file compute_infeasible_subsystem_result.cc.

◆ operator<<() [46/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const ModelSubset::Bounds & bounds )

Definition at line 66 of file compute_infeasible_subsystem_result.cc.

◆ operator<<() [47/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const MultiObjectiveTestParameters & params )

Definition at line 59 of file multi_objective_tests.cc.

◆ operator<<() [48/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const QcTestParameters & params )

Definition at line 45 of file qc_tests.cc.

◆ operator<<() [49/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const QpTestParameters & params )

Definition at line 77 of file qp_tests.cc.

◆ operator<<() [50/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const SecondOrderConeTestParameters & params )

Definition at line 41 of file second_order_cone_tests.cc.

◆ operator<<() [51/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const SimpleLpTestParameters & params )

Definition at line 51 of file lp_tests.cc.

◆ operator<<() [52/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const SimpleMipTestParameters & params )

Definition at line 45 of file mip_tests.cc.

◆ operator<<() [53/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const SolutionHintTestParams & params )

Definition at line 45 of file ip_model_solve_parameters_tests.cc.

◆ operator<<() [54/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const SolveResult & result )

Prints a summary of the solve result on a single line.

This prints the number of available solutions and rays instead of their values.

Printing the whole solution could be problematic for huge models.

Definition at line 690 of file solve_result.cc.

◆ operator<<() [55/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const StatusTestParameters & params )

Definition at line 43 of file status_tests.cc.

◆ operator<<() [56/57]

template<typename E , typename = std::enable_if_t<Enum<E>::kIsImplemented>>
std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const std::optional< E > opt_value )

Overload of operator<< for std::optional<E> when Enum<E> is implemented.

When the value is nullopt, it prints "<unspecified>", else it prints the enum value.

Definition at line 254 of file enums.h.

◆ operator<<() [57/57]

std::ostream & operations_research::math_opt::operator<< ( std::ostream & out,
const TimeLimitTestParameters & params )

Definition at line 47 of file generic_tests.cc.

◆ operator<=() [1/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( const LinearExpression & lhs,
QuadraticExpression rhs )
inline

Definition at line 3085 of file variable_and_expressions.h.

◆ operator<=() [2/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( const LinearTerm & lhs,
const LinearTerm & rhs )
inline

Definition at line 1955 of file variable_and_expressions.h.

◆ operator<=() [3/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( const LinearTerm & lhs,
LinearExpression rhs )
inline

Definition at line 1923 of file variable_and_expressions.h.

◆ operator<=() [4/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( const LinearTerm & lhs,
Variable rhs )
inline

Definition at line 1970 of file variable_and_expressions.h.

◆ operator<=() [5/39]

UpperBoundedLinearExpression operations_research::math_opt::operator<= ( const LinearTerm & term,
double constant )
inline

Definition at line 1843 of file variable_and_expressions.h.

◆ operator<=() [6/39]

LowerBoundedLinearExpression operations_research::math_opt::operator<= ( double constant,
const LinearTerm & term )
inline

Definition at line 1818 of file variable_and_expressions.h.

◆ operator<=() [7/39]

LowerBoundedLinearExpression operations_research::math_opt::operator<= ( double constant,
LinearExpression expression )
inline

Definition at line 1808 of file variable_and_expressions.h.

◆ operator<=() [8/39]

LowerBoundedLinearExpression operations_research::math_opt::operator<= ( double constant,
Variable variable )
inline

Definition at line 1828 of file variable_and_expressions.h.

◆ operator<=() [9/39]

LowerBoundedQuadraticExpression operations_research::math_opt::operator<= ( double lhs,
QuadraticExpression rhs )
inline

Definition at line 2858 of file variable_and_expressions.h.

◆ operator<=() [10/39]

LowerBoundedQuadraticExpression operations_research::math_opt::operator<= ( double lhs,
QuadraticTerm rhs )
inline

Definition at line 2862 of file variable_and_expressions.h.

◆ operator<=() [11/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( double lhs,
UpperBoundedLinearExpression rhs )
inline

Definition at line 1884 of file variable_and_expressions.h.

◆ operator<=() [12/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( double lhs,
UpperBoundedQuadraticExpression rhs )
inline

Definition at line 2899 of file variable_and_expressions.h.

◆ operator<=() [13/39]

UpperBoundedLinearExpression operations_research::math_opt::operator<= ( LinearExpression expression,
double constant )
inline

Definition at line 1833 of file variable_and_expressions.h.

◆ operator<=() [14/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( LinearExpression lhs,
const LinearExpression & rhs )
inline

We intentionally pass one LinearExpression argument by value so that we don't make unnecessary copies of temporary objects by using the move constructor and the returned values optimization (RVO).

Definition at line 1891 of file variable_and_expressions.h.

◆ operator<=() [15/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( LinearExpression lhs,
const LinearTerm & rhs )
inline

Definition at line 1907 of file variable_and_expressions.h.

◆ operator<=() [16/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( LinearExpression lhs,
QuadraticTerm rhs )
inline

Definition at line 3091 of file variable_and_expressions.h.

◆ operator<=() [17/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( LinearExpression lhs,
Variable rhs )
inline

Definition at line 1939 of file variable_and_expressions.h.

◆ operator<=() [18/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( LinearTerm lhs,
QuadraticExpression rhs )
inline

Definition at line 3117 of file variable_and_expressions.h.

◆ operator<=() [19/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( LinearTerm lhs,
QuadraticTerm rhs )
inline

Definition at line 3123 of file variable_and_expressions.h.

◆ operator<=() [20/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( LowerBoundedLinearExpression lhs,
double rhs )
inline

We intentionally pass the UpperBoundedLinearExpression and LowerBoundedLinearExpression arguments by value so that we don't make unnecessary copies of temporary objects by using the move constructor and the returned values optimization (RVO).

Definition at line 1863 of file variable_and_expressions.h.

◆ operator<=() [21/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( LowerBoundedQuadraticExpression lhs,
double rhs )
inline

Definition at line 2894 of file variable_and_expressions.h.

◆ operator<=() [22/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 2947 of file variable_and_expressions.h.

◆ operator<=() [23/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticExpression lhs,
const QuadraticExpression & rhs )
inline

Definition at line 2935 of file variable_and_expressions.h.

◆ operator<=() [24/39]

UpperBoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticExpression lhs,
double rhs )
inline

Definition at line 2875 of file variable_and_expressions.h.

◆ operator<=() [25/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticExpression lhs,
LinearTerm rhs )
inline

Definition at line 2953 of file variable_and_expressions.h.

◆ operator<=() [26/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticExpression lhs,
QuadraticTerm rhs )
inline

Definition at line 2941 of file variable_and_expressions.h.

◆ operator<=() [27/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticExpression lhs,
Variable rhs )
inline

Definition at line 2959 of file variable_and_expressions.h.

◆ operator<=() [28/39]

UpperBoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticTerm lhs,
double rhs )
inline

Definition at line 2879 of file variable_and_expressions.h.

◆ operator<=() [29/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticTerm lhs,
LinearExpression rhs )
inline

Definition at line 3033 of file variable_and_expressions.h.

◆ operator<=() [30/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticTerm lhs,
LinearTerm rhs )
inline

Definition at line 3038 of file variable_and_expressions.h.

◆ operator<=() [31/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticTerm lhs,
QuadraticExpression rhs )
inline

Definition at line 3022 of file variable_and_expressions.h.

◆ operator<=() [32/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticTerm lhs,
QuadraticTerm rhs )
inline

Definition at line 3028 of file variable_and_expressions.h.

◆ operator<=() [33/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( QuadraticTerm lhs,
Variable rhs )
inline

Definition at line 3043 of file variable_and_expressions.h.

◆ operator<=() [34/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( Variable lhs,
const LinearTerm & rhs )
inline

Definition at line 1978 of file variable_and_expressions.h.

◆ operator<=() [35/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( Variable lhs,
LinearExpression rhs )
inline

Definition at line 1947 of file variable_and_expressions.h.

◆ operator<=() [36/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( Variable lhs,
QuadraticExpression rhs )
inline

Definition at line 3149 of file variable_and_expressions.h.

◆ operator<=() [37/39]

BoundedQuadraticExpression operations_research::math_opt::operator<= ( Variable lhs,
QuadraticTerm rhs )
inline

Definition at line 3155 of file variable_and_expressions.h.

◆ operator<=() [38/39]

BoundedLinearExpression operations_research::math_opt::operator<= ( Variable lhs,
Variable rhs )
inline

Definition at line 1986 of file variable_and_expressions.h.

◆ operator<=() [39/39]

UpperBoundedLinearExpression operations_research::math_opt::operator<= ( Variable variable,
double constant )
inline

Definition at line 1853 of file variable_and_expressions.h.

◆ operator==() [1/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( double lhs,
QuadraticExpression rhs )
inline

Double –.

Definition at line 3171 of file variable_and_expressions.h.

◆ operator==() [2/43]

bool operations_research::math_opt::operator== ( const IndicatorConstraint & lhs,
const IndicatorConstraint & rhs )

Definition at line 124 of file indicator_constraint.h.

◆ operator==() [3/43]

bool operations_research::math_opt::operator== ( const LinearConstraint & lhs,
const LinearConstraint & rhs )

Definition at line 163 of file linear_constraint.h.

◆ operator==() [4/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( const LinearExpression & lhs,
QuadraticExpression rhs )
inline

Definition at line 3096 of file variable_and_expressions.h.

◆ operator==() [5/43]

BoundedLinearExpression operations_research::math_opt::operator== ( const LinearTerm & lhs,
const LinearTerm & rhs )
inline

Definition at line 2035 of file variable_and_expressions.h.

◆ operator==() [6/43]

BoundedLinearExpression operations_research::math_opt::operator== ( const LinearTerm & lhs,
double rhs )
inline

Definition at line 2050 of file variable_and_expressions.h.

◆ operator==() [7/43]

BoundedLinearExpression operations_research::math_opt::operator== ( const LinearTerm & lhs,
LinearExpression rhs )
inline

Definition at line 2008 of file variable_and_expressions.h.

◆ operator==() [8/43]

BoundedLinearExpression operations_research::math_opt::operator== ( const LinearTerm & lhs,
Variable rhs )
inline

Definition at line 2042 of file variable_and_expressions.h.

◆ operator==() [9/43]

bool operations_research::math_opt::operator== ( const Objective & lhs,
const Objective & rhs )

Definition at line 204 of file objective.h.

◆ operator==() [10/43]

bool operations_research::math_opt::operator== ( const QuadraticConstraint & lhs,
const QuadraticConstraint & rhs )

Definition at line 178 of file quadratic_constraint.h.

◆ operator==() [11/43]

bool operations_research::math_opt::operator== ( const SecondOrderConeConstraint & lhs,
const SecondOrderConeConstraint & rhs )

Definition at line 114 of file second_order_cone_constraint.h.

◆ operator==() [12/43]

bool operations_research::math_opt::operator== ( const Sos1Constraint & lhs,
const Sos1Constraint & rhs )

Definition at line 116 of file sos1_constraint.h.

◆ operator==() [13/43]

bool operations_research::math_opt::operator== ( const Sos2Constraint & lhs,
const Sos2Constraint & rhs )

Definition at line 117 of file sos2_constraint.h.

◆ operator==() [14/43]

internal::VariablesEquality operations_research::math_opt::operator== ( const Variable & lhs,
const Variable & rhs )
inline

Definition at line 1745 of file variable_and_expressions.h.

◆ operator==() [15/43]

BoundedLinearExpression operations_research::math_opt::operator== ( double lhs,
const LinearTerm & rhs )
inline

Definition at line 2055 of file variable_and_expressions.h.

◆ operator==() [16/43]

BoundedLinearExpression operations_research::math_opt::operator== ( double lhs,
LinearExpression rhs )
inline

Definition at line 2029 of file variable_and_expressions.h.

◆ operator==() [17/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( double lhs,
QuadraticTerm rhs )
inline

Comparisons with lhs = Double.

Definition at line 3176 of file variable_and_expressions.h.

◆ operator==() [18/43]

BoundedLinearExpression operations_research::math_opt::operator== ( double lhs,
Variable rhs )
inline

Definition at line 2064 of file variable_and_expressions.h.

◆ operator==() [19/43]

BoundedLinearExpression operations_research::math_opt::operator== ( LinearExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 1994 of file variable_and_expressions.h.

◆ operator==() [20/43]

BoundedLinearExpression operations_research::math_opt::operator== ( LinearExpression lhs,
const LinearTerm & rhs )
inline

Definition at line 2001 of file variable_and_expressions.h.

◆ operator==() [21/43]

BoundedLinearExpression operations_research::math_opt::operator== ( LinearExpression lhs,
double rhs )
inline

Definition at line 2023 of file variable_and_expressions.h.

◆ operator==() [22/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( LinearExpression lhs,
QuadraticTerm rhs )
inline

Definition at line 3101 of file variable_and_expressions.h.

◆ operator==() [23/43]

BoundedLinearExpression operations_research::math_opt::operator== ( LinearExpression lhs,
Variable rhs )
inline

Definition at line 2015 of file variable_and_expressions.h.

◆ operator==() [24/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( LinearTerm lhs,
QuadraticExpression rhs )
inline

Definition at line 3128 of file variable_and_expressions.h.

◆ operator==() [25/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( LinearTerm lhs,
QuadraticTerm rhs )
inline

Definition at line 3133 of file variable_and_expressions.h.

◆ operator==() [26/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 2975 of file variable_and_expressions.h.

◆ operator==() [27/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticExpression lhs,
const QuadraticExpression & rhs )
inline

Definition at line 2965 of file variable_and_expressions.h.

◆ operator==() [28/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticExpression lhs,
double rhs )
inline

Definition at line 2990 of file variable_and_expressions.h.

◆ operator==() [29/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticExpression lhs,
LinearTerm rhs )
inline

Definition at line 2980 of file variable_and_expressions.h.

◆ operator==() [30/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticExpression lhs,
QuadraticTerm rhs )
inline

Definition at line 2970 of file variable_and_expressions.h.

◆ operator==() [31/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticExpression lhs,
Variable rhs )
inline

Definition at line 2985 of file variable_and_expressions.h.

◆ operator==() [32/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticTerm lhs,
double rhs )
inline

Definition at line 3069 of file variable_and_expressions.h.

◆ operator==() [33/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticTerm lhs,
LinearExpression rhs )
inline

Definition at line 3057 of file variable_and_expressions.h.

◆ operator==() [34/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticTerm lhs,
LinearTerm rhs )
inline

Definition at line 3061 of file variable_and_expressions.h.

◆ operator==() [35/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticTerm lhs,
QuadraticExpression rhs )
inline

Definition at line 3048 of file variable_and_expressions.h.

◆ operator==() [36/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticTerm lhs,
QuadraticTerm rhs )
inline

Definition at line 3053 of file variable_and_expressions.h.

◆ operator==() [37/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( QuadraticTerm lhs,
Variable rhs )
inline

Definition at line 3065 of file variable_and_expressions.h.

◆ operator==() [38/43]

bool operations_research::math_opt::operator== ( QuadraticTermKey lhs,
QuadraticTermKey rhs )
inline

Definition at line 2108 of file variable_and_expressions.h.

◆ operator==() [39/43]

BoundedLinearExpression operations_research::math_opt::operator== ( Variable lhs,
const LinearTerm & rhs )
inline

Definition at line 2046 of file variable_and_expressions.h.

◆ operator==() [40/43]

BoundedLinearExpression operations_research::math_opt::operator== ( Variable lhs,
double rhs )
inline

Definition at line 2060 of file variable_and_expressions.h.

◆ operator==() [41/43]

BoundedLinearExpression operations_research::math_opt::operator== ( Variable lhs,
LinearExpression rhs )
inline

Definition at line 2019 of file variable_and_expressions.h.

◆ operator==() [42/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( Variable lhs,
QuadraticExpression rhs )
inline

Definition at line 3160 of file variable_and_expressions.h.

◆ operator==() [43/43]

BoundedQuadraticExpression operations_research::math_opt::operator== ( Variable lhs,
QuadraticTerm rhs )
inline

Definition at line 3165 of file variable_and_expressions.h.

◆ operator>=() [1/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( const LinearExpression & lhs,
QuadraticExpression rhs )
inline

Comparisons with lhs = LinearExpression.

Definition at line 3074 of file variable_and_expressions.h.

◆ operator>=() [2/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( const LinearTerm & lhs,
const LinearTerm & rhs )
inline

Definition at line 1963 of file variable_and_expressions.h.

◆ operator>=() [3/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( const LinearTerm & lhs,
LinearExpression rhs )
inline

Definition at line 1931 of file variable_and_expressions.h.

◆ operator>=() [4/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( const LinearTerm & lhs,
Variable rhs )
inline

Definition at line 1974 of file variable_and_expressions.h.

◆ operator>=() [5/39]

LowerBoundedLinearExpression operations_research::math_opt::operator>= ( const LinearTerm & term,
double constant )
inline

Definition at line 1813 of file variable_and_expressions.h.

◆ operator>=() [6/39]

UpperBoundedLinearExpression operations_research::math_opt::operator>= ( double constant,
const LinearTerm & term )
inline

Definition at line 1848 of file variable_and_expressions.h.

◆ operator>=() [7/39]

UpperBoundedLinearExpression operations_research::math_opt::operator>= ( double constant,
LinearExpression expression )
inline

Definition at line 1838 of file variable_and_expressions.h.

◆ operator>=() [8/39]

UpperBoundedLinearExpression operations_research::math_opt::operator>= ( double constant,
Variable variable )
inline

Definition at line 1858 of file variable_and_expressions.h.

◆ operator>=() [9/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( double lhs,
LowerBoundedLinearExpression rhs )
inline

Definition at line 1870 of file variable_and_expressions.h.

◆ operator>=() [10/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( double lhs,
LowerBoundedQuadraticExpression rhs )
inline

Definition at line 2889 of file variable_and_expressions.h.

◆ operator>=() [11/39]

UpperBoundedQuadraticExpression operations_research::math_opt::operator>= ( double lhs,
QuadraticExpression rhs )
inline

Definition at line 2867 of file variable_and_expressions.h.

◆ operator>=() [12/39]

UpperBoundedQuadraticExpression operations_research::math_opt::operator>= ( double lhs,
QuadraticTerm rhs )
inline

Definition at line 2871 of file variable_and_expressions.h.

◆ operator>=() [13/39]

LowerBoundedLinearExpression operations_research::math_opt::operator>= ( LinearExpression expression,
double constant )
inline

We intentionally pass the LinearExpression argument by value so that we don't make unnecessary copies of temporary objects by using the move constructor and the returned values optimization (RVO).

Definition at line 1803 of file variable_and_expressions.h.

◆ operator>=() [14/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( LinearExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 1899 of file variable_and_expressions.h.

◆ operator>=() [15/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( LinearExpression lhs,
const LinearTerm & rhs )
inline

Definition at line 1915 of file variable_and_expressions.h.

◆ operator>=() [16/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( LinearExpression lhs,
QuadraticTerm rhs )
inline

Definition at line 3080 of file variable_and_expressions.h.

◆ operator>=() [17/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( LinearExpression lhs,
Variable rhs )
inline

Definition at line 1943 of file variable_and_expressions.h.

◆ operator>=() [18/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( LinearTerm lhs,
QuadraticExpression rhs )
inline

Comparisons with lhs = LinearTerm.

LinearTerm –.

Definition at line 3106 of file variable_and_expressions.h.

◆ operator>=() [19/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( LinearTerm lhs,
QuadraticTerm rhs )
inline

Definition at line 3112 of file variable_and_expressions.h.

◆ operator>=() [20/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticExpression lhs,
const LinearExpression & rhs )
inline

Definition at line 2917 of file variable_and_expressions.h.

◆ operator>=() [21/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticExpression lhs,
const QuadraticExpression & rhs )
inline

Comparisons with lhs = QuadraticExpression.

We intentionally pass one QuadraticExpression argument by value so that we don't make unnecessary copies of temporary objects by using the move constructor and the returned values optimization (RVO).

Definition at line 2905 of file variable_and_expressions.h.

◆ operator>=() [22/39]

LowerBoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticExpression lhs,
double rhs )
inline

We intentionally pass the QuadraticExpression argument by value so that we don't make unnecessary copies of temporary objects by using the move constructor and the returned values optimization (RVO).

Definition at line 2850 of file variable_and_expressions.h.

◆ operator>=() [23/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticExpression lhs,
LinearTerm rhs )
inline

Definition at line 2923 of file variable_and_expressions.h.

◆ operator>=() [24/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticExpression lhs,
QuadraticTerm rhs )
inline

Definition at line 2911 of file variable_and_expressions.h.

◆ operator>=() [25/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticExpression lhs,
Variable rhs )
inline

Definition at line 2929 of file variable_and_expressions.h.

◆ operator>=() [26/39]

LowerBoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticTerm lhs,
double rhs )
inline

Definition at line 2854 of file variable_and_expressions.h.

◆ operator>=() [27/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticTerm lhs,
LinearExpression rhs )
inline

Definition at line 3007 of file variable_and_expressions.h.

◆ operator>=() [28/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticTerm lhs,
LinearTerm rhs )
inline

Definition at line 3012 of file variable_and_expressions.h.

◆ operator>=() [29/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticTerm lhs,
QuadraticExpression rhs )
inline

Comparisons with lhs = QuadraticTerm.

Definition at line 2996 of file variable_and_expressions.h.

◆ operator>=() [30/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticTerm lhs,
QuadraticTerm rhs )
inline

Definition at line 3002 of file variable_and_expressions.h.

◆ operator>=() [31/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( QuadraticTerm lhs,
Variable rhs )
inline

Definition at line 3017 of file variable_and_expressions.h.

◆ operator>=() [32/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( UpperBoundedLinearExpression lhs,
double rhs )
inline

Definition at line 1877 of file variable_and_expressions.h.

◆ operator>=() [33/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( UpperBoundedQuadraticExpression lhs,
double rhs )
inline

We intentionally pass the UpperBoundedQuadraticExpression and LowerBoundedQuadraticExpression arguments by value so that we don't make unnecessary copies of temporary objects by using the move constructor and the returned values optimization (RVO).

Definition at line 2884 of file variable_and_expressions.h.

◆ operator>=() [34/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( Variable lhs,
const LinearTerm & rhs )
inline

Definition at line 1982 of file variable_and_expressions.h.

◆ operator>=() [35/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( Variable lhs,
LinearExpression rhs )
inline

Definition at line 1951 of file variable_and_expressions.h.

◆ operator>=() [36/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( Variable lhs,
QuadraticExpression rhs )
inline

Comparisons with lhs = Variable.

Variable –.

Definition at line 3138 of file variable_and_expressions.h.

◆ operator>=() [37/39]

BoundedQuadraticExpression operations_research::math_opt::operator>= ( Variable lhs,
QuadraticTerm rhs )
inline

Definition at line 3144 of file variable_and_expressions.h.

◆ operator>=() [38/39]

BoundedLinearExpression operations_research::math_opt::operator>= ( Variable lhs,
Variable rhs )
inline

Definition at line 1990 of file variable_and_expressions.h.

◆ operator>=() [39/39]

LowerBoundedLinearExpression operations_research::math_opt::operator>= ( Variable variable,
double constant )
inline

Definition at line 1823 of file variable_and_expressions.h.

◆ OptimalTerminationProto()

TerminationProto operations_research::math_opt::OptimalTerminationProto ( double finite_primal_objective,
double dual_objective,
absl::string_view detail = {} )

Returns a TERMINATION_REASON_OPTIMAL termination with the provided objective bounds and FEASIBILITY_STATUS_FEASIBLE primal and dual statuses.

finite_primal_objective must be finite for a valid TerminationProto to be returned.

Todo
(b/290359402): additionally require dual_objective to be finite.

Definition at line 220 of file math_opt_proto_utils.cc.

◆ OptionalFormatFlagPossibleValuesList()

std::string operations_research::math_opt::OptionalFormatFlagPossibleValuesList ( )

Get the lines for each format and the introduction doc.

Add the doc of what happen when format is not specified.

Builds a map from formats to their extensions.

Here we iterate on all formats so that we list them in the same order as in the enum.

Here we use operator[] as it is not an issue to create new empty entries in the map.

Definition at line 143 of file file_format_flags.cc.

◆ PrimalRayIsNear()

testing::Matcher< PrimalRay > operations_research::math_opt::PrimalRayIsNear ( VariableMap< double > expected_var_values,
double tolerance = kMatcherDefaultTolerance )

Checks variables match and that after rescaling, variable values are within tolerance.

Definition at line 538 of file matchers.cc.

◆ PrinterMessageCallback()

MessageCallback operations_research::math_opt::PrinterMessageCallback ( std::ostream & output_stream = std::cout,
absl::string_view prefix = "" )

Returns a message callback function that prints its output to the given output stream, prefixing each line with the given prefix.

For each call to the returned message callback, the output_stream is flushed.

Usage:

SolveArguments args; args.message_callback = PrinterMessageCallback(std::cerr, "solver logs> ");

Here we must use an std::shared_ptr since std::function requires that its input is copyable. And PrinterMessageCallbackImpl can't be copyable since it uses an absl::Mutex that is not.

Definition at line 82 of file message_callback.cc.

◆ PrintTo() [1/8]

template<typename K , typename V , typename = std::enable_if_t<is_key_type_v<K>>>
void operations_research::math_opt::PrintTo ( const absl::flat_hash_map< K, V > & id_map,
std::ostream *const os )

We do not want to rely on ::testing::internal::ContainerPrinter because we want to sort the keys.

Definition at line 553 of file matchers.h.

◆ PrintTo() [2/8]

void operations_research::math_opt::PrintTo ( const Basis & basis,
std::ostream *const os )

Definition at line 114 of file matchers.cc.

◆ PrintTo() [3/8]

void operations_research::math_opt::PrintTo ( const DualRay & dual_ray,
std::ostream *const os )

Definition at line 109 of file matchers.cc.

◆ PrintTo() [4/8]

void operations_research::math_opt::PrintTo ( const DualSolution & dual_solution,
std::ostream *const os )

Definition at line 95 of file matchers.cc.

◆ PrintTo() [5/8]

void operations_research::math_opt::PrintTo ( const PrimalRay & primal_ray,
std::ostream *const os )

Definition at line 105 of file matchers.cc.

◆ PrintTo() [6/8]

void operations_research::math_opt::PrintTo ( const PrimalSolution & primal_solution,
std::ostream * os )

Implementation details

Definition at line 88 of file matchers.cc.

◆ PrintTo() [7/8]

void operations_research::math_opt::PrintTo ( const Solution & solution,
std::ostream *const os )

Definition at line 121 of file matchers.cc.

◆ PrintTo() [8/8]

void operations_research::math_opt::PrintTo ( const SolveResult & result,
std::ostream *const os )

Definition at line 127 of file matchers.cc.

◆ ProblemStatusIs()

testing::Matcher< ProblemStatus > operations_research::math_opt::ProblemStatusIs ( const ProblemStatus & expected)

Definition at line 726 of file matchers.cc.

◆ QuadraticConstraintFilterFromProto()

absl::StatusOr< MapFilter< QuadraticConstraint > > operations_research::math_opt::QuadraticConstraintFilterFromProto ( const Model & model,
const SparseVectorFilterProto & proto )

Returns the MapFilter<QuadraticConstraint> equivalent to proto.

Requires that (or returns a status error):

  • proto.filtered_ids has elements that are quadratic constraints in model.

Definition at line 67 of file map_filter.cc.

◆ QuadraticConstraintValuesFromProto()

absl::StatusOr< absl::flat_hash_map< QuadraticConstraint, double > > operations_research::math_opt::QuadraticConstraintValuesFromProto ( const ModelStorage * model,
const SparseDoubleVectorProto & quad_cons_proto )

Returns the absl::flat_hash_map<QuadraticConstraint, double> equivalent to quad_cons_proto.

Requires that (or returns a status error):

  • quad_cons_proto.ids and quad_cons_proto.values have equal size.
  • quad_cons_proto.ids is sorted.
  • quad_cons_proto.ids has elements that are quadratic constraints in model (this implies that each id is in [0, max(int64_t))).
Note
the values of quad_cons_proto.values are not checked (it may have NaNs).

Definition at line 203 of file sparse_containers.cc.

◆ QuadraticConstraintValuesToProto()

SparseDoubleVectorProto operations_research::math_opt::QuadraticConstraintValuesToProto ( const absl::flat_hash_map< QuadraticConstraint, double > & quadratic_constraint_values)

Returns the proto equivalent of quadratic_constraint_values.

Definition at line 211 of file sparse_containers.cc.

◆ ReadModel()

absl::StatusOr< std::pair< ModelProto, std::optional< SolutionHintProto > > > operations_research::math_opt::ReadModel ( const absl::string_view file_path,
const FileFormat format )

Definition at line 198 of file file_format_flags.cc.

◆ ReadMpsFile()

absl::StatusOr< ModelProto > operations_research::math_opt::ReadMpsFile ( absl::string_view filename)

Reads an MPS file and converts it to a ModelProto (like MpsToModelProto above, but takes a file name instead of the file contents and reads the file.

The file can be stored as plain text or gzipped (with the .gz extension).

Definition at line 36 of file mps_converter.cc.

◆ ReasonIs()

testing::Matcher< Termination > operations_research::math_opt::ReasonIs ( TerminationReason reason)

Matchers for a Termination

Definition at line 718 of file matchers.cc.

◆ ReasonIsOptimal()

testing::Matcher< Termination > operations_research::math_opt::ReasonIsOptimal ( )

Checks that the termination reason is optimal, but does not check the other fields of Termination are consistent with optimality.

Definition at line 722 of file matchers.cc.

◆ RemoveNames() [1/2]

void operations_research::math_opt::RemoveNames ( ModelProto & model)

Removes the model, variables and constraints names of the provided model.

Definition at line 32 of file names_removal.cc.

◆ RemoveNames() [2/2]

void operations_research::math_opt::RemoveNames ( ModelUpdateProto & update)

Removes the variables and constraints names of the provided update.

Definition at line 44 of file names_removal.cc.

◆ RemoveSparseDoubleVectorZeros()

void operations_research::math_opt::RemoveSparseDoubleVectorZeros ( SparseDoubleVectorProto & sparse_vector)

Removes the items in the sparse double vector for all indices whose value is exactly 0.0.

NaN values are kept in place.

The function asserts that input is a valid sparse vector, i.e. that the number of values and ids match.

Keep track of the next index that has not yet been used for a non zero value.

Se use !(== 0.0) here so that we keep NaN values for which both v == / 0 and v != 0 returns false.

At the end of the iteration, next contains the index of the first unused index. This means it contains the number of used elements.

Definition at line 70 of file math_opt_proto_utils.cc.

◆ RepeatedPtrFieldMessageCallback()

MessageCallback operations_research::math_opt::RepeatedPtrFieldMessageCallback ( google::protobuf::RepeatedPtrField< std::string > * sink)

Returns a message callback function that aggregates all messages in the provided RepeatedPtrField.

Usage:

google::protobuf::RepeatedPtrField<std::string> msgs; SolveArguments args; args.message_callback = RepeatedPtrFieldMessageCallback(&msgs);

Here we must use an std::shared_ptr since std::function requires that its input is copyable. And VectorMessageCallbackImpl can't be copyable since it uses an absl::Mutex that is not.

Definition at line 123 of file message_callback.cc.

◆ ResultForIntegerInfeasible()

SolveResultProto operations_research::math_opt::ResultForIntegerInfeasible ( bool is_maximize,
int64_t bad_variable_id,
double lb,
double ub )

Returns an "infeasible" result for models where the infeasibility is caused by an integer variable whose bounds are nonempty but contain no integers.

Callers should make sure to set the SolveResultProto.solve_stats.solve_time field before returning the result.

Definition at line 26 of file empty_bounds.cc.

◆ RoundedLowerBound()

double operations_research::math_opt::RoundedLowerBound ( const Variable v,
const double tolerance )
inline

Returns the lower bound of the variable, rounding it up when the variable is integral and the bound's fractional value is outside the tolerance.

For example if the lower bound of an integer variable is 1.0000000000000002 and the tolerance is 0.0 this function will return 2.0. If the tolerance is 1e-6 though this function will return 1.0.

Tolerance should be a non-negative value < kMaxIntegralityTolerance (usually much smaller). A negative input value (or NaN) will be considered 0.0, a value >= kMaxIntegralityTolerance will be considered kMaxIntegralityTolerance (using a tolerance like 0.5 would lead to odd behavior for ties as integral bounds could be rounded to the next integer. For example with the integer 2^53 - 1, 2^53 - 1 + 0.5 = 2^53)

We use std::fmax() to treat NaN as 0.0.

Definition at line 101 of file solution_improvement.h.

◆ RoundedUpperBound()

double operations_research::math_opt::RoundedUpperBound ( const Variable v,
const double tolerance )
inline

Same as RoundedLowerBound() but for upper-bound.

See comment in RoundedLowerBound().

Definition at line 109 of file solution_improvement.h.

◆ SmallModel()

std::unique_ptr< Model > operations_research::math_opt::SmallModel ( const bool integer)

Definition at line 25 of file test_models.cc.

◆ SolutionStatusIs()

Matcher< SolutionStatus > operations_research::math_opt::SolutionStatusIs ( const SolutionStatus expected,
const bool allow_undetermined )

Matchers for Solutions

Definition at line 415 of file matchers.cc.

◆ Solve()

absl::StatusOr< SolveResult > operations_research::math_opt::Solve ( const Model & model,
SolverType solver_type,
const SolveArguments & solve_args = {},
const SolverInitArguments & init_args = {} )

Solves the input model.

A Status error will be returned if the inputs are invalid or there is an unexpected failure in an underlying solver or for some internal math_opt errors. Otherwise, check SolveResult::termination.reason to see if an optimal solution was found.

Memory model: the returned SolveResult owns its own memory (for solutions, solve stats, etc.), EXCEPT for a pointer back to the model. As a result:

  • Keep the model alive to access SolveResult,
  • Avoid unnecessarily copying SolveResult,
  • The result is generally accessible after mutating the model, but some care is needed if variables or linear constraints are added or deleted.

Thread-safety: this method is safe to call concurrently on the same Model.

Some solvers may add more restrictions regarding threading. Please see SolverType::kXxx documentation for details.

Definition at line 62 of file solve.cc.

◆ SolveWithoutUpdate()

<=x<=1 IncrementalMipTest::IncrementalMipTest() :model_("incremental_solve_test"), x_(model_.AddContinuousVariable(0.0, 1.0, "x")), y_(model_.AddIntegerVariable(0.0, 2.0, "y")), c_(model_.AddLinearConstraint(0<=x_+y_<=1.5, "c")) { model_.Maximize(3.0 *x_+2.0 *y_+0.1);solver_=NewIncrementalSolver(&model_, TestedSolver()).value();const SolveResult first_solve=solver_->Solve().value();CHECK(first_solve.has_primal_feasible_solution());CHECK_LE(std::abs(first_solve.objective_value() - 3.6), kTolerance)<< first_solve.objective_value();} namespace { TEST_P(SimpleMipTest, OneVarMax) { Model model;const Variable x=model.AddVariable(0.0, 4.0, false, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, OneVarMin) { Model model;const Variable x=model.AddVariable(-2.4, 4.0, false, "x");model.Minimize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(-4.8));EXPECT_THAT(result.variable_values(), IsNear({{x, -2.4}}));} TEST_P(SimpleMipTest, OneIntegerVar) { Model model;const Variable x=model.AddVariable(0.0, 4.5, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(8.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 4.0}}));} TEST_P(SimpleMipTest, SimpleLinearConstraint) { Model model;const Variable x=model.AddBinaryVariable("x");const Variable y=model.AddBinaryVariable("y");model.Maximize(2.0 *x+y);model.AddLinearConstraint(0.0<=x+y<=1.5, "c");ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, IsOptimal(2.0));EXPECT_THAT(result.variable_values(), IsNear({{x, 1}, {y, 0}}));} TEST_P(SimpleMipTest, Unbounded) { Model model;const Variable x=model.AddVariable(0.0, kInf, true, "x");model.Maximize(2.0 *x);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));if(GetParam().report_unboundness_correctly) { ASSERT_THAT(result, TerminatesWithOneOf({TerminationReason::kUnbounded, TerminationReason::kInfeasibleOrUnbounded}));} else { ASSERT_THAT(result, TerminatesWith(TerminationReason::kOtherError));} } TEST_P(SimpleMipTest, Infeasible) { Model model;const Variable x=model.AddVariable(0.0, 3.0, true, "x");model.Maximize(2.0 *x);model.AddLinearConstraint(x >=4.0);ASSERT_OK_AND_ASSIGN(const SolveResult result, Solve(model, GetParam().solver_type));ASSERT_THAT(result, TerminatesWith(TerminationReason::kInfeasible));} TEST_P(SimpleMipTest, FractionalBoundsContainNoInteger) { if(GetParam().solver_type==SolverType::kGurobi) { GTEST_SKIP()<< "TODO(b/272298816): Gurobi bindings are broken here.";} Model model;const Variable x=model.AddIntegerVariable(0.5, 0.6, "x");model.Maximize(x);EXPECT_THAT(Solve(model, GetParam().solver_type), IsOkAndHolds(TerminatesWith(TerminationReason::kInfeasible)));} TEST_P(IncrementalMipTest, EmptyUpdate) { ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(3.6));EXPECT_THAT(result.variable_values(), IsNear({{x_, 0.5}, {y_, 1.0}}));} TEST_P(IncrementalMipTest, MakeContinuous) { model_.set_continuous(y_);ASSERT_THAT(solver_->Update(), IsOkAndHolds(DidUpdate()));ASSERT_OK_AND_ASSIGN(const SolveResult result, solver_->SolveWithoutUpdate());ASSERT_THAT(result, IsOptimal(4.1));EXPECT_THAT(result.variable_values(), IsNear({{x_, 1.0}, {y_, 0.5}}));} TEST_P(IncrementalMipTest, DISABLED_MakeContinuousWithNonIntegralBounds) { solver_.reset();Model model("bounds");const Variable x=model.AddIntegerVariable(0.5, 1.5, "x");model.Maximize(x);ASSERT_OK_AND_ASSIGN(const auto solver, NewIncrementalSolver(&model, TestedSolver()));ASSERT_THAT(solver->Solve(), IsOkAndHolds(IsOptimal(1.0))); model.set_continuous(x);ASSERT_THAT(solver->Update(), IsOkAndHolds(DidUpdate()));ASSERT_THAT(solver-> operations_research::math_opt::SolveWithoutUpdate ( )

max 3.0 *x + 2.0 * y + 0.1 s.t. 0 <= x + y <= 1.5 (c)

◆ SortedAtomicConstraints()

template<typename ConstraintType >
std::vector< ConstraintType > operations_research::math_opt::SortedAtomicConstraints ( const ModelStorage & storage)
  • Duck-types on ConstraintType having a typed_id() getter.

Definition at line 69 of file model_util.h.

◆ SortedElements()

template<typename Set , typename = std::enable_if_t<is_key_type_v<typename Set::key_type>>>
std::vector< typename Set::key_type > operations_research::math_opt::SortedElements ( const Set & set)

Returns the elements of the set sorted by their (storage(), type_id()).

Implementation note: here we must use std::enable_if to prevent Argument Dependent Lookup (ADL) from selecting this overload for maps which values are in MathOpt but keys are not.

Definition at line 110 of file key_types.h.

◆ SortedKeys()

template<typename Map , typename = std::enable_if_t<is_key_type_v<typename Map::key_type>>>
std::vector< typename Map::key_type > operations_research::math_opt::SortedKeys ( const Map & map)

Returns the keys of the map sorted by their (storage(), type_id()).

Implementation note: here we must use std::enable_if to prevent Argument Dependent Lookup (ADL) from selecting this overload for maps which values are in MathOpt but keys are not.

Definition at line 87 of file key_types.h.

◆ SortedMapKeys() [1/2]

template<typename K , typename V >
std::vector< K > operations_research::math_opt::SortedMapKeys ( const absl::flat_hash_map< K, V > & in_map)

Definition at line 55 of file sorted.h.

◆ SortedMapKeys() [2/2]

template<typename K , typename V >
std::vector< K > operations_research::math_opt::SortedMapKeys ( const google::protobuf::Map< K, V > & in_map)

Definition at line 62 of file sorted.h.

◆ SortedSetElements()

template<typename T >
std::vector< T > operations_research::math_opt::SortedSetElements ( const absl::flat_hash_set< T > & elements)

Definition at line 28 of file sorted.h.

◆ SparseBasisStatusVectorIsValid()

absl::Status operations_research::math_opt::SparseBasisStatusVectorIsValid ( const SparseVectorView< int > & status_vector_view)

Basis

Definition at line 241 of file solution_validator.cc.

◆ SparseMatrixIdsAreKnown()

absl::Status operations_research::math_opt::SparseMatrixIdsAreKnown ( const SparseDoubleMatrixProto & matrix,
const IdNameBiMap & row_ids,
const IdNameBiMap & column_ids )

Verifies that:

  1. matrix.row_ids is a subset of row_ids.
  2. matrix.column_ids is a subset of column_ids.

Definition at line 91 of file sparse_matrix_validator.cc.

◆ SparseMatrixValid()

absl::Status operations_research::math_opt::SparseMatrixValid ( const SparseDoubleMatrixProto & matrix,
bool enforce_upper_triangular = false )

Validates that the input satisfies the following invariants:

  1. matrix.row_ids, matrix.column_ids, and matrix.coefficients are all the same length.
  2. matrix.row_ids and matrix.column_ids are nonnegative.
  3. The matrix is in row major ordering with no repeats.
  4. Each entry in matrix.coefficients is finite and not NaN.
  5. If enforce_upper_triangular=true, then matrix must be upper triangular.

When row > previous_row, we have a new row, nothing to check.

Definition at line 30 of file sparse_matrix_validator.cc.

◆ SparseSubmatrixByRows()

SparseSubmatrixRowsView operations_research::math_opt::SparseSubmatrixByRows ( const SparseDoubleMatrixProto & matrix,
int64_t start_row_id,
std::optional< int64_t > end_row_id,
int64_t start_col_id,
std::optional< int64_t > end_col_id )

Returns the coefficients of columns in the range [start_col_id, end_col_id) for each row in the range [start_row_id, end_row_id).

Returns a vector that contains one pair (row_id, columns_coefficients) per row. It CHECKs that the input matrix is valid. The coefficients are returned in a views that points to the input matrix's data. Therefore they should not be used after the proto is modified/deleted.

When end_(col|row)_id is nullopt, includes all indices greater or equal to start_(col|row)_id.

This functions runs in O(size of matrix).

Use TransposeSparseSubmatrix() to transpose the submatrix and get the columns instead of the rows.

Usage example:

///< With this input sparse matrix: ///< |0 1 2 3 4 5 6 ///< -+----------— ///< 0|2 - - - 3 4 - ///< 1|- - - - - - - ///< 2|- 5 - 1 - - 3 ///< 3|9 - - 8 - - 7 const SparseDoubleMatrixProto matrix = ...;

///< Keeping coefficients of lines >= 1 and columns in [1, 6). const auto rows = SparseSubmatrixByRows( matrix, /*start_row_id=*‍/1, /*end_row_id=*‍/std::nullopt, /*start_col_id=*‍/1, /*end_col_id=*‍/6);

///< The returned rows and coefficients will be: ///< {2, {{1, 5.0}, {3, 1.0}}} ///< {3, { {3, 8.0}}}

row_start, next_row_start and row_end are indices into the matrix data.

next_row_start is set from row_end once found at the start of the loop below.

Find the end of the current row such that all index in [start, end) are for the same row.

Prepare the next iteration.

Ignore rows not in the expected range.

Finds the first column or the row in the col_range.

Finds the first column greater of equal to row_cols_start that is not in the col_range.

Definition at line 47 of file sparse_submatrix.cc.

◆ StreamToString()

template<typename T >
std::string operations_research::math_opt::StreamToString ( const T & value)

Writes the input value to a string using the operator<< overload and returns it.

Definition at line 25 of file stream.h.

◆ Sum()

template<typename Iterable >
LinearExpression operations_research::math_opt::Sum ( const Iterable & items)
inline

Returns the sum of the elements of items as a LinearExpression.

Specifically, letting (i_1, i_2, ..., i_n) = items returns i_1 + i_2 + ... + i_n.

Example: const Variable a = ...; const Variable b = ...; const std::vector<Variable> vars = {a, b, a}; Sum(vars) => 2.0 * a + b Note, instead of: LinearExpression expr(3.0); expr += Sum(items); Prefer: expr.AddSum(items);

See LinearExpression::AddSum() for a precise contract on the type Iterable.

If the inner product cannot be represented as a LinearExpression, consider instead QuadraticExpression::Sum().

Definition at line 1676 of file variable_and_expressions.h.

◆ TerminateForLimit()

TerminationProto operations_research::math_opt::TerminateForLimit ( LimitProto limit,
bool feasible,
absl::string_view detail = {} )

Sets the reason to TERMINATION_REASON_FEASIBLE if feasible = true and TERMINATION_REASON_NO_SOLUTION_FOUND otherwise.

Definition at line 153 of file math_opt_proto_utils.cc.

◆ TerminateForReason() [1/2]

TerminationProto operations_research::math_opt::TerminateForReason ( bool is_maximize,
TerminationReasonProto reason,
absl::string_view detail = {} )

Returns a TerminationProto with the provided reason and details along with trivial bounds and FEASIBILITY_STATUS_UNDETERMINED statuses.

Definition at line 204 of file math_opt_proto_utils.cc.

◆ TerminateForReason() [2/2]

TerminationProto operations_research::math_opt::TerminateForReason ( const TerminationReasonProto reason,
const absl::string_view detail )

Definition at line 178 of file math_opt_proto_utils.cc.

◆ TerminatesWith()

testing::Matcher< SolveResult > operations_research::math_opt::TerminatesWith ( TerminationReason expected)

Checks the following:

  • The result has the expected termination reason.

Definition at line 621 of file matchers.cc.

◆ TerminatesWithLimit()

testing::Matcher< SolveResult > operations_research::math_opt::TerminatesWithLimit ( Limit expected,
bool allow_limit_undetermined = false )

Checks the following:

  • The result has termination reason kFeasible or kNoSolutionFound.
  • The limit is expected, or is kUndetermined if allow_limit_undetermined.

See LimitIs() for a matcher for Termination only.

Definition at line 648 of file matchers.cc.

◆ TerminatesWithOneOf()

testing::Matcher< SolveResult > operations_research::math_opt::TerminatesWithOneOf ( const std::vector< TerminationReason > & allowed)

Checks that the result has one of the allowed termination reasons.

Definition at line 615 of file matchers.cc.

◆ TerminatesWithReasonFeasible()

testing::Matcher< SolveResult > operations_research::math_opt::TerminatesWithReasonFeasible ( Limit expected,
bool allow_limit_undetermined = false )

Checks the following:

  • The result has termination reason kFeasible.
  • The limit is expected, or is kUndetermined if allow_limit_undetermined.

Definition at line 657 of file matchers.cc.

◆ TerminatesWithReasonNoSolutionFound()

testing::Matcher< SolveResult > operations_research::math_opt::TerminatesWithReasonNoSolutionFound ( Limit expected,
bool allow_limit_undetermined = false )

Checks the following:

  • The result has termination reason kNoSolutionFound.
  • The limit is expected, or is kUndetermined if allow_limit_undetermined.

Definition at line 665 of file matchers.cc.

◆ TerminationIsIgnoreDetail()

testing::Matcher< Termination > operations_research::math_opt::TerminationIsIgnoreDetail ( const Termination & expected)

Definition at line 757 of file matchers.cc.

◆ TerminationIsOptimal() [1/2]

testing::Matcher< Termination > operations_research::math_opt::TerminationIsOptimal ( )

Checks that the termination reason is optimal and that problem status is consistent with optimality (i.e. status is primal and dual feasible).

Definition at line 736 of file matchers.cc.

◆ TerminationIsOptimal() [2/2]

testing::Matcher< Termination > operations_research::math_opt::TerminationIsOptimal ( double primal_objective_value,
std::optional< double > dual_objective_value = std::nullopt,
double tolerance = kMatcherDefaultTolerance )

Checks that the termination reason is optimal, that the objective bounds match the provided ones and that problem status is consistent with optimality (i.e. status is primal and dual feasible).

If dual_objective_value is not set, use the primal_objective_value.

Definition at line 745 of file matchers.cc.

◆ TEST_P() [1/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
AddLinearConstraint  )

Definition at line 305 of file mip_tests.cc.

◆ TEST_P() [2/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
AddVariable  )

Definition at line 294 of file mip_tests.cc.

◆ TEST_P() [3/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
ChangeBoundsWithTemporaryInversion  )

At this point x_ lower bound is 3.0 and upper bound is 1.0.

At this point x_ upper bound is 5.0 and so is greater than the new lower bound.

To make the problem feasible we update the bound of the constraint that contains x_; we take this opportunity to also test inverting bounds of constraints.

At this point c_ lower bound is 4.0 and upper bound is 1.5.

We restore valid bounds by setting c_ upper bound to 5.5.

Definition at line 329 of file mip_tests.cc.

◆ TEST_P() [4/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
DeleteLinearConstraint  )

Definition at line 321 of file mip_tests.cc.

◆ TEST_P() [5/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
DeleteVariable  )

Definition at line 313 of file mip_tests.cc.

◆ TEST_P() [6/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
LinearConstraintCoefficient  )

Definition at line 286 of file mip_tests.cc.

◆ TEST_P() [7/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
LinearConstraintLb  )

For this change, feasibility is preserved, so the solver should do no extra work (SCIP enumerates one node, though).

Definition at line 263 of file mip_tests.cc.

◆ TEST_P() [8/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
LinearConstraintUb  )

Definition at line 278 of file mip_tests.cc.

◆ TEST_P() [9/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
LinearObjCoef  )

Definition at line 239 of file mip_tests.cc.

◆ TEST_P() [10/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
MakeInteger  )

Definition at line 215 of file mip_tests.cc.

◆ TEST_P() [11/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
MakeIntegralWithNonIntegralBounds  )

With Gurobi we can only have one solver at a time.

Definition at line 194 of file mip_tests.cc.

◆ TEST_P() [12/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
ObjDir  )

Definition at line 223 of file mip_tests.cc.

◆ TEST_P() [13/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
ObjOffset  )

Definition at line 231 of file mip_tests.cc.

◆ TEST_P() [14/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
VariableLb  )

Definition at line 247 of file mip_tests.cc.

◆ TEST_P() [15/34]

operations_research::math_opt::TEST_P ( IncrementalMipTest ,
VariableUb  )

Definition at line 255 of file mip_tests.cc.

◆ TEST_P() [16/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
CanComputeInfeasibleSubsystem  )

Definition at line 58 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [17/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentEqualityLinearConstraint  )

The model is: min 0 s.t. 1 == 0

The entire model is an IIS.

Definition at line 159 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [18/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentEqualityQuadraticConstraint  )

The model is: min 0 s.t. 1 == 0 (quadratic constraint)

The entire model is an IIS.

Definition at line 265 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [19/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentGreaterThanLinearConstraint  )

The model is: min 0 s.t. 1 ≤ 0 ≤ ∞

An IIS is:

Definition at line 139 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [20/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentGreaterThanQuadraticConstraint  )

The model is: min 0 s.t. 1 ≤ 0 ≤ ∞ (quadratic constraint)

An IIS is:

Definition at line 245 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [21/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentLessThanLinearConstraint  )

The model is: min 0 s.t. -∞ ≤ 1 ≤ 0

An IIS is:

Definition at line 118 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [22/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentLessThanQuadraticConstraint  )

The model is: min 0 s.t. -∞ ≤ 1 ≤ 0 (quadratic constraint)

An IIS is:

Definition at line 224 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [23/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentRangedLinearConstraint  )

The model is: min 0 s.t. 0 ≤ 2 ≤ 1

The entire model is an IIS.

Definition at line 179 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [24/34]

y y operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentSos1Constraint  )

Definition at line 395 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [25/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentSos1ConstraintWithExpressions  )

The model is: min 0 s.t. {1, 1} is SOS1

The entire problem is an IIS.

Definition at line 419 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [26/34]

z z y operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentSos2Constraint  )

Definition at line 440 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [27/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InconsistentSos2ConstraintWithExpressions  )

The model is: min 0 s.t. {1, 0, 1} is SOS2

The entire model is an IIS.

Definition at line 465 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [28/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
IndicatorConstraintOkInconsistentImpliedNullIndicator  )

The model is: min 0 s.t. {null} --> 1 ≤ 0

The model is feasible.

To get a null indicator variable, we: add a placeholder indicator variable, add the indicator constraint, and then delete the variable.

Definition at line 510 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [29/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
IntegerVariableWithInfeasibleBounds  )

The model is: min 0 s.t. 0.2 ≤ x ≤ 0.8 (variable bounds) x is integer

The entire model is an IIS.

Definition at line 96 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [30/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
InvertedVariableBounds  )

The model is: min 0 s.t. 1 ≤ x ≤ 0 (variable bounds)

The entire model is an IIS.

Definition at line 76 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [31/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
NontrivialInfeasibleIpSolveInterruptedBeforeStartIsUndetermined  )

Definition at line 584 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [32/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
NontrivialInfeasibleIpSolveTimeLimitZeroIsUndetermined  )

Definition at line 572 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [33/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
NontrivialInfeasibleIpSolveWithMessageCallbackIsInvoked  )

Definition at line 597 of file infeasible_subsystem_tests.cc.

◆ TEST_P() [34/34]

operations_research::math_opt::TEST_P ( InfeasibleSubsystemTest ,
NontrivialInfeasibleIpSolveWithoutLimitsFindsIIS  )

Definition at line 555 of file infeasible_subsystem_tests.cc.

◆ ToGlopBasisStatus()

template<typename ValueType >
ValueType operations_research::math_opt::ToGlopBasisStatus ( const BasisStatusProto basis_status)

ValueType should be glop's VariableStatus or ConstraintStatus.

Definition at line 512 of file glop_solver.cc.

◆ ToLinearExpression()

LinearExpression operations_research::math_opt::ToLinearExpression ( const ModelStorage & storage,
const LinearExpressionData & expr_data )

Converts data from "raw ID" format to a LinearExpression, in the C++ API, associated with storage.

Definition at line 25 of file model_util.cc.

◆ ToString()

std::string operations_research::math_opt::ToString ( QpSupportType qp_support)

Definition at line 64 of file qp_tests.cc.

◆ TransposeSparseSubmatrix()

std::vector< std::pair< int64_t, SparseVector< double > > > operations_research::math_opt::TransposeSparseSubmatrix ( const SparseSubmatrixRowsView & submatrix_by_rows)

Returns a vector that contains one pair (row_id, rows_coefficients) per column.

The coefficients are returned as copies of the input views.

This functions runs in: O(num_non_zeros + num_non_empty_cols * lg(num_non_empty_cols)).

Extract the columns by iterating on the filtered views of the rows (the matrix is row major).

The output should be sorted by column id.

Definition at line 108 of file sparse_submatrix.cc.

◆ UnboundedTerminationProto()

TerminationProto operations_research::math_opt::UnboundedTerminationProto ( bool is_maximize,
absl::string_view detail = {} )

Returns a TERMINATION_REASON_UNBOUNDED termination with a FEASIBILITY_STATUS_FEASIBLE primal status and FEASIBILITY_STATUS_INFEASIBLE dual one along with corresponding trivial bounds.

Definition at line 236 of file math_opt_proto_utils.cc.

◆ UpdateIdIndexMap()

template<typename IndexType >
void operations_research::math_opt::UpdateIdIndexMap ( glop::StrictITIVector< IndexType, bool > indices_to_delete,
IndexType num_indices,
absl::flat_hash_map< int64_t, IndexType > & id_index_map )
Note
this relies on the fact that when variable/constraint are deleted, Glop re-index everything by compacting the index domain in a stable way.

Mark deleted index

This safely deletes the entry and moves the iterator one step ahead.

Definition at line 187 of file glop_solver.cc.

◆ UpdateIsSupported()

bool operations_research::math_opt::UpdateIsSupported ( const ModelUpdateProto & update,
const SupportedProblemStructures & support_menu )

Returns false if a problem structure is present in update and not not implemented or supported according to support_menu.

Duck-types that the proto parameter contains fields named new_constraints and deleted_constraint_ids. This is standard for "mapped" constraints.

Definition at line 463 of file math_opt_proto_utils.cc.

◆ UpgradeSolveResultProtoForStatsMigration()

void operations_research::math_opt::UpgradeSolveResultProtoForStatsMigration ( SolveResultProto & solve_result_proto)

Definition at line 545 of file math_opt_proto_utils.cc.

◆ UpperBound()

double operations_research::math_opt::UpperBound ( const LinearExpression & linear_expression)

Computes an upper bound on the value a linear expression can take based on the variable bounds.

The returned value will be in (-inf, +inf] on valid input (see LowerBound() above, the requirements are the same).

See LowerBound() above for more details.

Definition at line 56 of file linear_expr_util.cc.

◆ ValidateBasis()

absl::Status operations_research::math_opt::ValidateBasis ( const BasisProto & basis,
const ModelSummary & model_summary,
const bool check_dual_feasibility )

Definition at line 257 of file solution_validator.cc.

◆ ValidateBoundStatusConsistency()

absl::Status operations_research::math_opt::ValidateBoundStatusConsistency ( const ObjectiveBoundsProto & objective_bounds,
const ProblemStatusProto & status,
bool is_maximize )

Definition at line 215 of file bounds_and_status_validator.cc.

◆ ValidateCallbackDataProto()

absl::Status operations_research::math_opt::ValidateCallbackDataProto ( const CallbackDataProto & cb_data,
const CallbackRegistrationProto & callback_registration,
const ModelSummary & model_summary )

Checks that CallbackDataProto is valid given a valid model summary and CallbackRegistrationProto.

Check PresolveStats.

Check SimplexStats.

Check BarrierStats.

Check MipStats.

Check runtime.

Ensure required fields are available depending on event.

This can not happen as a valid callback_registration can not register a CALLBACK_EVENT_UNSPECIFIED.

The remaining events are just for information collection. No further test required.

Definition at line 152 of file callback_validator.cc.

◆ ValidateCallbackRegistration()

absl::Status operations_research::math_opt::ValidateCallbackRegistration ( const CallbackRegistrationProto & callback_registration,
const ModelSummary & model_summary )

Checks that CallbackRegistrationProto is valid given a valid model summary.

Unfortunately the range iterator return ints and not CallbackEventProtos.

Definition at line 107 of file callback_validator.cc.

◆ ValidateCallbackResultProto()

absl::Status operations_research::math_opt::ValidateCallbackResultProto ( const CallbackResultProto & callback_result,
CallbackEventProto event,
const CallbackRegistrationProto & callback_registration,
const ModelSummary & model_summary )

Checks that CallbackResultProto is valid given a valid model summary, CallbackEventProto (which since it is assumed to be valid, can not be CALLBACK_EVENT_UNSPECIFIED) and a CallbackRegistrationProto.

We assume that all arguments but the first are valid and concordant with each other. Otherwise this is an internal implementation error.

Definition at line 258 of file callback_validator.cc.

◆ ValidateComputeInfeasibleSubsystemResult()

absl::Status operations_research::math_opt::ValidateComputeInfeasibleSubsystemResult ( const ComputeInfeasibleSubsystemResultProto & result,
const ModelSummary & model_summary )

Definition at line 80 of file infeasible_subsystem_validator.cc.

◆ ValidateComputeInfeasibleSubsystemResultNoModel()

absl::Status operations_research::math_opt::ValidateComputeInfeasibleSubsystemResultNoModel ( const ComputeInfeasibleSubsystemResultProto & result)

Validates the internal consistency of the fields.

Check that the infeasible_subsystem is empty by validating against an empty ModelSummary.

Definition at line 91 of file infeasible_subsystem_validator.cc.

◆ ValidateConstraint() [1/4]

absl::Status operations_research::math_opt::ValidateConstraint ( const IndicatorConstraintProto & constraint,
const IdNameBiMap & variable_universe )

Definition at line 27 of file validator.cc.

◆ ValidateConstraint() [2/4]

absl::Status operations_research::math_opt::ValidateConstraint ( const QuadraticConstraintProto & constraint,
const IdNameBiMap & variable_universe )

Step 1: Validate linear terms.

Step 2: Validate quadratic terms.

Step 3: Validate bounds.

Definition at line 32 of file validator.cc.

◆ ValidateConstraint() [3/4]

absl::Status operations_research::math_opt::ValidateConstraint ( const SecondOrderConeConstraintProto & constraint,
const IdNameBiMap & variable_universe )

Definition at line 29 of file validator.cc.

◆ ValidateConstraint() [4/4]

absl::Status operations_research::math_opt::ValidateConstraint ( const SosConstraintProto & constraint,
const IdNameBiMap & variable_universe )

Check weights for uniqueness.

Definition at line 28 of file validator.cc.

◆ ValidateDualRay()

absl::Status operations_research::math_opt::ValidateDualRay ( const DualRayProto & dual_ray,
const ModelSolveParametersProto & parameters,
const ModelSummary & model_summary )

Definition at line 221 of file solution_validator.cc.

◆ ValidateDualSolution()

absl::Status operations_research::math_opt::ValidateDualSolution ( const DualSolutionProto & dual_solution,
const ModelSolveParametersProto & parameters,
const ModelSummary & model_summary )

Definition at line 203 of file solution_validator.cc.

◆ ValidateFeasibilityStatus()

absl::Status operations_research::math_opt::ValidateFeasibilityStatus ( const FeasibilityStatusProto & status)

Problem status validators and utilities.

Definition at line 33 of file bounds_and_status_validator.cc.

◆ ValidateLinearExpression()

absl::Status operations_research::math_opt::ValidateLinearExpression ( const LinearExpressionProto & expression,
const IdNameBiMap & variable_universe )

Definition at line 28 of file linear_expression_validator.cc.

◆ ValidateModel()

absl::StatusOr< ModelSummary > operations_research::math_opt::ValidateModel ( const ModelProto & model,
const bool check_names )

Model

Runs in O(size of model) and allocates O(#variables + #linear constraints) memory.

Definition at line 232 of file model_validator.cc.

◆ ValidateModelSolveParameters()

absl::Status operations_research::math_opt::ValidateModelSolveParameters ( const ModelSolveParametersProto & parameters,
const ModelSummary & model_summary )

Definition at line 114 of file model_parameters_validator.cc.

◆ ValidateModelSubset()

absl::Status operations_research::math_opt::ValidateModelSubset ( const ModelSubsetProto & model_subset,
const ModelSummary & model_summary )

Definition at line 51 of file infeasible_subsystem_validator.cc.

◆ ValidateModelUpdate()

absl::Status operations_research::math_opt::ValidateModelUpdate ( const ModelUpdateProto & model_update,
ModelSummary & model_summary )

Model Update

Validates the update is consistent both internally and with current model (as given by model_summary) and updates the model_summary.

Performance: runs in O(size of update), allocates at most O(#new or deleted variables + #new or deleted linear constraints).

If the function returns an error, no guarantees are made on the state of model_summary.

Definition at line 279 of file model_validator.cc.

◆ ValidateObjectiveBounds()

absl::Status operations_research::math_opt::ValidateObjectiveBounds ( const ObjectiveBoundsProto & bounds)

Objective bounds validators and utilities.

Definition at line 128 of file bounds_and_status_validator.cc.

◆ ValidatePrimalRay()

absl::Status operations_research::math_opt::ValidatePrimalRay ( const PrimalRayProto & primal_ray,
const SparseVectorFilterProto & filter,
const ModelSummary & model_summary )

Definition at line 194 of file solution_validator.cc.

◆ ValidatePrimalSolution()

absl::Status operations_research::math_opt::ValidatePrimalSolution ( const PrimalSolutionProto & primal_solution,
const SparseVectorFilterProto & filter,
const ModelSummary & model_summary )

Definition at line 171 of file solution_validator.cc.

◆ ValidatePrimalSolutionVector()

absl::Status operations_research::math_opt::ValidatePrimalSolutionVector ( const SparseDoubleVectorProto & vector,
const SparseVectorFilterProto & filter,
const ModelSummary & model_summary )

Used to validate callback solutions, which are represented by a SparseDoubleVectorProto and not the full PrimalSolutionProto message. Does the same checks on a SparseDoubleVectorProto that ValidatePrimalSolution does on the variable_values sub-message of a PrimalSolutionProto.

Definition at line 163 of file solution_validator.cc.

◆ ValidateProblemStatus()

absl::Status operations_research::math_opt::ValidateProblemStatus ( const ProblemStatusProto & status)

Definition at line 44 of file bounds_and_status_validator.cc.

◆ ValidateResult()

absl::Status operations_research::math_opt::ValidateResult ( const SolveResultProto & result,
const ModelSolveParametersProto & parameters,
const ModelSummary & model_summary )

Validates the input result.

Todo
(b/290091715): Remove once problem_status and objective bounds are removed from solve_stats and their presence is guaranteed in termination.
Todo
(b/290091715): Replace by TerminationProto termination = result.termination(); once problem_status and objective bounds are removed from solve_stats and their presence is guaranteed in termination.

Definition at line 278 of file result_validator.cc.

◆ ValidateSolution()

absl::Status operations_research::math_opt::ValidateSolution ( const SolutionProto & solution,
const ModelSolveParametersProto & parameters,
const ModelSummary & model_summary )
Todo
(b/204457524): consider checking equality of statuses for single-sided LPs.

Definition at line 119 of file solution_validator.cc.

◆ ValidateSolutions()

absl::Status operations_research::math_opt::ValidateSolutions ( const google::protobuf::RepeatedPtrField< SolutionProto > & solutions,
const ModelSolveParametersProto & parameters,
const ModelSummary & model_summary )

Validate individual solutions

Validate solution order.

Todo
(b/204457524): check objective ordering when possible.

Primal-feasible solutions must appear first.

Dual-feasible solutions must appear first within the groups of primal-feasible and other solutions. Equivalently, a dual-feasible solution must be preceded by a dual-feasible solution, except when we switch from the group of primal-feasible solutions to the group of other solutions.

Definition at line 66 of file result_validator.cc.

◆ ValidateSolveParameters()

absl::Status operations_research::math_opt::ValidateSolveParameters ( const SolveParametersProto & parameters)
Todo
(b/213697045): some parameters are still not validated.

Definition at line 48 of file solve_parameters_validator.cc.

◆ ValidateSolveStats()

absl::Status operations_research::math_opt::ValidateSolveStats ( const SolveStatsProto & solve_stats)

Definition at line 26 of file solve_stats_validator.cc.

◆ ValidateSparseVectorFilter()

absl::Status operations_research::math_opt::ValidateSparseVectorFilter ( const SparseVectorFilterProto & v,
const IdNameBiMap & valid_ids )

Definition at line 99 of file model_parameters_validator.cc.

◆ ValidateTermination()

absl::Status operations_research::math_opt::ValidateTermination ( const TerminationProto & termination,
const bool is_maximize )

Checks all messages are valid and compatible.

Definition at line 127 of file termination_validator.cc.

◆ Values()

template<typename Map , typename Keys , typename = std::enable_if_t<is_key_type_v<typename Map::key_type>>>
std::vector< typename Map::mapped_type > operations_research::math_opt::Values ( const Map & map,
const Keys & keys )

Returns the values corresponding to the keys. Keys must be present in the input map.

The keys must be in a type convertible to absl::Span<const K>.

Implementation note: here we must use std::enable_if to prevent Argument Dependent Lookup (ADL) from selecting this overload for maps which values are in MathOpt but keys are not.

Definition at line 136 of file key_types.h.

◆ VariableBasisFromProto()

absl::StatusOr< VariableMap< BasisStatus > > operations_research::math_opt::VariableBasisFromProto ( const ModelStorage * model,
const SparseBasisStatusVector & basis_proto )

Returns the VariableMap<BasisStatus> equivalent to basis_proto.

Requires that (or returns a status error):

  • basis_proto.ids and basis_proto.values have equal size.
  • basis_proto.ids is sorted.
  • basis_proto.ids has elements that are variables in model (this implies that each id is in [0, max(int64_t))).
  • basis_proto.values does not contain UNSPECIFIED and has valid enum values.

Definition at line 217 of file sparse_containers.cc.

◆ VariableBasisToProto()

SparseBasisStatusVector operations_research::math_opt::VariableBasisToProto ( const VariableMap< BasisStatus > & basis_values)

Returns the proto equivalent of basis_values.

Definition at line 225 of file sparse_containers.cc.

◆ VariableFilterFromProto()

absl::StatusOr< MapFilter< Variable > > operations_research::math_opt::VariableFilterFromProto ( const Model & model,
const SparseVectorFilterProto & proto )

Returns the MapFilter<Variable> equivalent to proto.

Requires that (or returns a status error):

  • proto.filtered_ids has elements that are variables in model.

Definition at line 28 of file map_filter.cc.

◆ VariableValuesFromProto() [1/2]

absl::StatusOr< VariableMap< double > > operations_research::math_opt::VariableValuesFromProto ( const ModelStorage * model,
const SparseDoubleVectorProto & vars_proto )

Returns the VariableMap<double> equivalent to vars_proto.

Requires that (or returns a status error):

  • vars_proto.ids and vars_proto.values have equal size.
  • vars_proto.ids is sorted.
  • vars_proto.ids has elements that are variables in model (this implies that each id is in [0, max(int64_t))).
Note
the values of vars_proto.values are not checked (it may have NaNs).

Definition at line 142 of file sparse_containers.cc.

◆ VariableValuesFromProto() [2/2]

absl::StatusOr< VariableMap< int32_t > > operations_research::math_opt::VariableValuesFromProto ( const ModelStorage * model,
const SparseInt32VectorProto & vars_proto )

Returns the VariableMap<int32_t> equivalent to vars_proto.

Requires that (or returns a status error):

  • vars_proto.ids and vars_proto.values have equal size.
  • vars_proto.ids is sorted.
  • vars_proto.ids has elements that are variables in model (this implies that each id is in [0, max(int64_t))).

Definition at line 150 of file sparse_containers.cc.

◆ VariableValuesToProto()

SparseDoubleVectorProto operations_research::math_opt::VariableValuesToProto ( const VariableMap< double > & variable_values)

Returns the proto equivalent of variable_values.

Definition at line 157 of file sparse_containers.cc.

◆ VectorMessageCallback()

MessageCallback operations_research::math_opt::VectorMessageCallback ( std::vector< std::string > * sink)

Returns a message callback function that aggregates all messages in the provided vector.

Usage:

std::vector<std::string> msgs; SolveArguments args; args.message_callback = VectorMessageCallback(&msgs);

Here we must use an std::shared_ptr since std::function requires that its input is copyable. And VectorMessageCallbackImpl can't be copyable since it uses an absl::Mutex that is not.

Definition at line 111 of file message_callback.cc.

◆ ViolatedConstraintsAsStrings()

absl::StatusOr< std::vector< std::string > > operations_research::math_opt::ViolatedConstraintsAsStrings ( const Model & model,
const ModelSubset & violated_constraints,
const VariableMap< double > & variable_values )

Returns a collection of strings that provide a human-readable representation of the violated_constraints (one string for each violated constraint). Useful for logging.

Returns an InvalidArgument error if variable_values does not contain an entry for each variable in model (and no extras).

Definition at line 329 of file solution_feasibility_checker.cc.

◆ VLoggerMessageCallback()

MessageCallback operations_research::math_opt::VLoggerMessageCallback ( int level,
absl::string_view prefix = "",
absl::SourceLocation loc = absl::SourceLocation::current() )

Returns a message callback function that prints each line to VLOG(level), prefixing each line with the given prefix.

Usage:

SolveArguments args; args.message_callback = VLoggerMessageCallback(1, "[solver] ");

Definition at line 102 of file message_callback.cc.

◆ WorstGLPKDualBound()

double operations_research::math_opt::WorstGLPKDualBound ( bool is_maximize,
double objective_value,
double relative_gap_limit )

Returns the worst dual bound corresponding to the given objective value and relative gap limit. This should be used when glp_intopt() returns GLP_EMIPGAP (i.e. stopped because of the gap limit) but the best_dual_bound is not available.

GLPK define the relative gap as:

|best_objective_value − best_dual_bound|

gap := -------------------------------------— best_objective_value + DBL_EPSILON

This function thus returns the value of best_dual_bound that makes gap match the relative_gap_limit.

Negative or NaN relative_gap_limit is considered 0. If the relative_gap_limit is +inf, returns the infinite dual bound corresponding to the is_maximize.

If the objective_value is infinite or NaN, returns the same value as the worst dual bound (in practice the objective_value should be finite).

Definition at line 23 of file gap.cc.

◆ WriteModel()

absl::Status operations_research::math_opt::WriteModel ( const absl::string_view file_path,
const ModelProto & model_proto,
const std::optional< SolutionHintProto > & hint_proto,
const FileFormat format )

Definition at line 237 of file file_format_flags.cc.

Variable Documentation

◆ bound

* If primal operations_research::math_opt::bound

Status-Bounds consistency validators. Checks both bound-status compatibility rules. That is:

Definition at line 73 of file bounds_and_status_validator.h.

◆ c

const IndicatorConstraint operations_research::math_opt::c = model.AddLinearConstraint(x >= 1.0)

Definition at line 206 of file infeasible_subsystem_tests.cc.

◆ check_dual

For infeasible and unbounded see Not checked if options check_solutions_if_inf_or_unbounded and the If options first_solution_only is check the entire list of Dual solution is not checked if options operations_research::math_opt::check_dual
Initial value:
=false
- Not checked if options.check_rays=false
- If options.first_solution_only is false

solutions matches in the same order.

Definition at line 470 of file matchers.h.

◆ default

When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by operations_research::math_opt::default

Definition at line 175 of file parameters.h.

◆ detail

absl::string_view operations_research::math_opt::detail = {})

Definition at line 165 of file math_opt_proto_utils.h.

◆ false

For infeasible and unbounded see Not checked if options check_solutions_if_inf_or_unbounded and the If options first_solution_only is operations_research::math_opt::false

problem is infeasible or unbounded (default).

options.inf_or_unb_soft_match.

  • The solve stats are ignored.
  • For both primal and dual solutions, either expected and actual are both empty, or their first entries satisfy IsNear() at options.tolerance.

Definition at line 468 of file matchers.h.

◆ finite

* If primal * dual status is and* dual bound is equal to primal bound* is operations_research::math_opt::finite

Definition at line 79 of file bounds_and_status_validator.h.

◆ InconsistentIndicatorConstraint

x operations_research::math_opt::InconsistentIndicatorConstraint
Initial value:
{
if (!GetParam().support_menu.supports_infeasible_subsystems) {
return;
}
GRBmodel * model

Definition at line 486 of file infeasible_subsystem_tests.cc.

◆ InconsistentSecondOrderConeConstraint

x operations_research::math_opt::InconsistentSecondOrderConeConstraint
Initial value:
{
if (!GetParam().support_menu.supports_infeasible_subsystems) {
return;
}

Definition at line 315 of file infeasible_subsystem_tests.cc.

◆ InconsistentSecondOrderConeConstraintWithExpressionInUpperBound

x operations_research::math_opt::InconsistentSecondOrderConeConstraintWithExpressionInUpperBound
Initial value:
{
if (!GetParam().support_menu.supports_infeasible_subsystems) {
return;
}

Definition at line 369 of file infeasible_subsystem_tests.cc.

◆ InconsistentSecondOrderConeConstraintWithExpressionUnderNorm

x operations_research::math_opt::InconsistentSecondOrderConeConstraintWithExpressionUnderNorm
Initial value:
{
if (!GetParam().support_menu.supports_infeasible_subsystems) {
return;
}

Definition at line 342 of file infeasible_subsystem_tests.cc.

◆ InconsistentVariableBoundsAndLinearConstraint

x operations_research::math_opt::InconsistentVariableBoundsAndLinearConstraint
Initial value:
{
if (!GetParam().support_menu.supports_infeasible_subsystems) {
return;
}

Definition at line 200 of file infeasible_subsystem_tests.cc.

◆ InconsistentVariableBoundsAndQuadraticConstraint

x operations_research::math_opt::InconsistentVariableBoundsAndQuadraticConstraint
Initial value:
{
if (!GetParam().support_menu.supports_infeasible_subsystems) {
return;
}

Definition at line 289 of file infeasible_subsystem_tests.cc.

◆ infeasible

* If primal * dual status is operations_research::math_opt::infeasible

Definition at line 77 of file bounds_and_status_validator.h.

◆ is_key_type_v

template<typename T >
bool operations_research::math_opt::is_key_type_v
inlineconstexpr
Initial value:
=
(std::is_same_v<T, Variable> || std::is_same_v<T, LinearConstraint> ||
std::is_same_v<T, QuadraticConstraint> ||
std::is_same_v<T, SecondOrderConeConstraint> ||
std::is_same_v<T, Sos1Constraint> || std::is_same_v<T, Sos2Constraint> ||
std::is_same_v<T, IndicatorConstraint> ||
std::is_same_v<T, QuadraticTermKey> || std::is_same_v<T, Objective>)

True for types in MathOpt that implements the keys interface defined at the top of this file.

This is used in conjunction with std::enable_if_t<> to prevent Argument Dependent Lookup (ADL) from selecting some overload defined in MathOpt because one of the template type is in MathOpt. For example the SortedKeys() function below could be selected as a valid overload in another namespace if the values in the hash map are in the math_opt namespace.

Definition at line 72 of file key_types.h.

◆ kDeletedConstraintDefaultDescription

absl::string_view operations_research::math_opt::kDeletedConstraintDefaultDescription
constexpr
Initial value:
=
"[constraint deleted from model]"

A default way to describe a constraint that has been deleted from its associated model.

Definition at line 30 of file model_util.h.

◆ kDeletedObjectiveDefaultDescription

absl::string_view operations_research::math_opt::kDeletedObjectiveDefaultDescription
constexpr
Initial value:
=
"[objective deleted from model]"

Definition at line 36 of file objective.h.

◆ kHigh

When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is operations_research::math_opt::kHigh

Definition at line 177 of file parameters.h.

◆ kInf

double operations_research::math_opt::kInf = std::numeric_limits<double>::infinity()
constexpr

Definition at line 24 of file empty_bounds.cc.

◆ kLow

When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is operations_research::math_opt::kLow

Definition at line 177 of file parameters.h.

◆ kMatcherDefaultTolerance

double operations_research::math_opt::kMatcherDefaultTolerance = 1e-5
constexpr

Definition at line 113 of file matchers.h.

◆ kMaxIntegralityTolerance

double operations_research::math_opt::kMaxIntegralityTolerance = 0.25
inlineconstexpr

Maximum value for integrality_tolerance and for RoundedLowerBound() and RoundedUpperBound().

Definition at line 30 of file solution_improvement.h.

◆ kMaxInvertedBounds

std::size_t operations_research::math_opt::kMaxInvertedBounds = 10
constexpr

The maximum number of variables/constraints with inverted bounds to report.

Definition at line 25 of file inverted_bounds.h.

◆ kMaxNonBinaryIndicatorVariables

std::size_t operations_research::math_opt::kMaxNonBinaryIndicatorVariables = 10
constexpr

The maximum number of non-binary indicator variables to report.

Definition at line 25 of file invalid_indicators.h.

◆ kMedium

When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is operations_research::math_opt::kMedium

Definition at line 177 of file parameters.h.

◆ kNoMultiObjectiveSupportMessage

absl::string_view operations_research::math_opt::kNoMultiObjectiveSupportMessage
constexpr
Initial value:
=
"This test is disabled as the solver does not support multiple objective "
"models"

Definition at line 40 of file multi_objective_tests.cc.

◆ kNoNonDiagonalQpSupportMessage

std::string_view operations_research::math_opt::kNoNonDiagonalQpSupportMessage
constexpr
Initial value:
=
"This test is disabled as the solver does not support non-diagonal "
"quadratic objectives"

Definition at line 44 of file qp_tests.cc.

◆ kNoQpSupportMessage

std::string_view operations_research::math_opt::kNoQpSupportMessage
constexpr
Initial value:
=
"This test is disabled as the solver does not support quadratic objectives"

Definition at line 41 of file qp_tests.cc.

◆ kPrimaryObjectiveId

ObjectiveId operations_research::math_opt::kPrimaryObjectiveId
constexpr
Initial value:
=
std::nullopt

Definition at line 32 of file model_storage_types.h.

◆ kTolerance

double operations_research::math_opt::kTolerance = 1e-6
constexpr

Definition at line 79 of file lp_incomplete_solve_tests.cc.

◆ off

When the underlying default is used When the feature cannot be turned operations_research::math_opt::off

Definition at line 174 of file parameters.h.

◆ problems

For infeasible and unbounded operations_research::math_opt::problems

Tests that two SolveResults are equivalent. Basic use:

SolveResult expected; ///< Fill in expected... ASSERT_OK_AND_ASSIGN(SolveResult actual, Solve(model, solver_type)); EXPECT_THAT(actual, IsConsistentWith(expected));

Equivalence is defined as follows:

  • The termination reasons are the same.

Definition at line 461 of file matchers.h.

◆ supported

When the underlying default is used When the feature cannot be turned kOff will return an error If the feature is enabled by the solver default is typically If the feature is operations_research::math_opt::supported

mapped to kMedium.

Definition at line 177 of file parameters.h.

◆ unset

When operations_research::math_opt::unset

Effort level applied to an optional task while solving (see SolveParameters for use).

Typically used as a std::optional<Emphasis>. It's used to configure a solver feature as follows:

  • If a solver doesn't support the feature, only nullopt will always be valid, any other setting will give an invalid argument error (some solvers may also accept kOff).
  • If the solver supports the feature:

Definition at line 173 of file parameters.h.

◆ x

const Variable operations_research::math_opt::x = model.AddContinuousVariable(-kInf, 0.0)

The model is: min 0 s.t. {x, y} is SOS1

The model is: min 0 s.t. {x, y, z} is SOS2

Definition at line 205 of file infeasible_subsystem_tests.cc.