91#ifndef OR_TOOLS_MATH_OPT_CPP_MATCHERS_H_
92#define OR_TOOLS_MATH_OPT_CPP_MATCHERS_H_
100#include "absl/container/flat_hash_map.h"
101#include "absl/status/statusor.h"
102#include "gtest/gtest.h"
121testing::Matcher<VariableMap<double>>
IsNear(
134testing::Matcher<LinearConstraintMap<double>>
IsNear(
148testing::Matcher<absl::flat_hash_map<QuadraticConstraint, double>>
IsNear(
149 absl::flat_hash_map<QuadraticConstraint, double> expected,
156testing::Matcher<absl::flat_hash_map<QuadraticConstraint, double>>
210testing::Matcher<PrimalSolution>
IsNear(
212 bool allow_undetermined =
false);
216testing::Matcher<DualSolution>
IsNear(
218 bool allow_undetermined =
false);
263 double primal_objective_value,
264 std::optional<double> dual_objective_value = std::nullopt,
275testing::Matcher<Termination>
LimitIs(
276 Limit limit, testing::Matcher<std::string> detail_matcher = testing::_);
300 std::optional<double> expected_primal_objective = std::nullopt,
314 absl::flat_hash_map<QuadraticConstraint, double>
315 expected_quadratic_dual_values,
325 const std::vector<TerminationReason>& allowed);
333 Limit expected,
bool allow_limit_undetermined =
false);
339 Limit expected,
bool allow_limit_undetermined =
false);
345 Limit expected,
bool allow_limit_undetermined =
false);
436 bool inf_or_unb_soft_match =
true;
484 absl::StatusOr<operations_research::math_opt::SolveResult>(
496testing::Matcher<ComputeInfeasibleSubsystemResult>
IsFeasible();
500testing::Matcher<ComputeInfeasibleSubsystemResult>
IsUndetermined();
506testing::Matcher<ComputeInfeasibleSubsystemResult>
IsInfeasible(
507 std::optional<bool> expected_is_minimal = std::nullopt,
508 std::optional<ModelSubset> expected_infeasible_subsystem = std::nullopt);
515testing::Matcher<UpdateResult>
DidUpdate();
527void PrintTo(
const SolveResult& result, std::ostream* os);
531template <
typename K,
typename V,
typename = std::enable_if_t<is_key_type_v<K>>>
532void PrintTo(
const absl::flat_hash_map<K, V>& id_map, std::ostream*
const os) {
533 constexpr int kMaxPrint = 10;
540 if (num_added >= kMaxPrint) {
541 *os <<
"...(size=" << id_map.size() <<
")";
544 *os <<
"{" << k <<
", " << ::testing::PrintToString(id_map.at(k)) <<
"}";
Matcher< SolveResult > IsOptimalWithSolution(const double expected_objective, const VariableMap< double > expected_variable_values, const double tolerance)
Matcher< SolveResult > HasPrimalRay(PrimalRay expected, const double tolerance)
Matcher< Termination > TerminationIsOptimal()
absl::flat_hash_map< Variable, V > VariableMap
Matcher< Termination > ReasonIsOptimal()
Matcher< ObjectiveBounds > ObjectiveBoundsNear(const ObjectiveBounds &expected, const double tolerance)
SolverType
The solvers supported by MathOpt.
TerminationReason
The reason a call to Solve() terminates.
constexpr double kMatcherDefaultTolerance
absl::flat_hash_map< LinearConstraint, V > LinearConstraintMap
Matcher< Termination > ReasonIs(TerminationReason reason)
Matcher< SolveResult > TerminatesWithOneOf(const std::vector< TerminationReason > &allowed)
Checks that the result has one of the allowed termination reasons.
Matcher< ProblemStatus > ProblemStatusIs(const ProblemStatus &expected)
testing::MockFunction< absl::StatusOr< operations_research::math_opt::SolveResult >( const operations_research::math_opt::Model &, operations_research::math_opt::SolverType, const operations_research::math_opt::SolveArguments &, const operations_research::math_opt::SolverInitArguments &)> MockSolveFunction
testing::Matcher< ComputeInfeasibleSubsystemResult > IsInfeasible(const std::optional< bool > expected_is_minimal, const std::optional< ModelSubset > expected_infeasible_subsystem)
Matcher< Termination > LimitIs(math_opt::Limit limit, const Matcher< std::string > detail_matcher)
testing::Matcher< BoundedLinearExpression > IsNearlyEquivalent(const BoundedLinearExpression &expected, const double tolerance)
Matcher< SolveResult > IsConsistentWith(const SolveResult &expected, const SolveResultMatcherOptions &options)
Matcher< Termination > TerminationIsIgnoreDetail(const Termination &expected)
Matcher< SolveResult > HasSolution(PrimalSolution expected, const double tolerance)
SolveResult has a primal solution matching expected within tolerance.
Matcher< SolveResult > HasDualRay(DualRay expected, const double tolerance)
testing::Matcher< SolveResult > TerminatesWithReasonFeasible(const Limit expected, const bool allow_limit_undetermined)
Matcher< SolveResult > TerminatesWith(const TerminationReason expected)
testing::Matcher< SolveResult > TerminatesWithLimit(const Limit expected, const bool allow_limit_undetermined)
Matcher< PrimalRay > PrimalRayIsNear(VariableMap< double > expected_var_values, const double tolerance)
testing::Matcher< LinearExpression > IsIdentical(LinearExpression expected)
Matcher< VariableMap< double > > IsNear(VariableMap< double > expected, const double tolerance)
Matcher< VariableMap< double > > IsNearlySubsetOf(VariableMap< double > expected, double tolerance)
Matcher< UpdateResult > DidUpdate()
Actual UpdateResult.did_update is true.
void PrintTo(const PrimalSolution &primal_solution, std::ostream *const os)
testing::Matcher< LinearExpression > LinearExpressionIsNear(const LinearExpression expected, 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 > HasDualSolution(DualSolution expected, const double tolerance)
Matcher< Basis > BasisIs(const Basis &expected)
testing::Matcher< ComputeInfeasibleSubsystemResult > IsFeasible()
std::vector< typename Map::key_type > SortedKeys(const Map &map)
testing::Matcher< ComputeInfeasibleSubsystemResult > IsUndetermined()
Matcher< SolveResult > IsOptimal(const std::optional< double > expected_primal_objective, const double tolerance)
testing::Matcher< SolveResult > TerminatesWithReasonNoSolutionFound(const Limit expected, const bool allow_limit_undetermined)
In SWIG mode, we don't want anything besides these top-level includes.
A LinearExpression with upper and lower bounds.
Bounds on the optimal objective value.
Options for IsNear(Solution).
Configures SolveResult matcher IsConsistentWith() below.
bool check_solutions_if_inf_or_unbounded
All information regarding why a call to Solve() terminated.