22#include "absl/status/status.h"
23#include "absl/strings/str_join.h"
24#include "gtest/gtest.h"
29#include "ortools/math_opt/model.pb.h"
30#include "ortools/math_opt/model_update.pb.h"
36using ::absl::StatusCode;
37using ::testing::HasSubstr;
38using ::testing::status::StatusIs;
48 : model_(), x_(model_.AddContinuousVariable(0.0, 1.0,
"x")) {
54 std::vector<std::string> expected_error_substrings)
55 : solver_type(solver_type),
56 solve_parameters(
std::move(solve_parameters)),
57 expected_error_substrings(
std::move(expected_error_substrings)) {}
61 out <<
"{ solver_type: " << params.
solver_type <<
" solve_params: "
63 <<
" expected_error_substrings: [ "
72 model.set_name(
"simple_model");
73 model.mutable_variables()->add_ids(3);
74 model.mutable_variables()->add_lower_bounds(2.0);
75 model.mutable_variables()->add_upper_bounds(3.0);
76 model.mutable_variables()->add_upper_bounds(4.0);
77 model.mutable_variables()->add_integers(GetParam().use_integer_variables);
78 model.mutable_variables()->add_names(
"x3");
81 StatusIs(StatusCode::kInvalidArgument));
84TEST_P(InvalidInputTest, InvalidCommonParameters) {
86 const std::unique_ptr<Solver> solver,
88 Solver::SolveArgs solve_args;
89 solve_args.parameters.set_threads(-1);
91 StatusIs(StatusCode::kInvalidArgument));
94TEST_P(InvalidInputTest, InvalidUpdate) {
96 model.set_name(
"simple_model");
97 model.mutable_variables()->add_ids(3);
98 model.mutable_variables()->add_lower_bounds(2.0);
99 model.mutable_variables()->add_upper_bounds(3.0);
100 model.mutable_variables()->add_integers(GetParam().use_integer_variables);
101 model.mutable_variables()->add_names(
"x3");
107 ModelUpdateProto update;
108 update.add_deleted_variable_ids(2);
113TEST_P(InvalidParameterTest, InvalidParameterNameAsError) {
114 SolveArguments args = {.parameters = GetParam().solve_parameters};
115 const auto result = SimpleSolve();
117 for (
const std::string& error : GetParam().expected_error_substrings) {
119 EXPECT_THAT(result.status().message(), HasSubstr(error));
void Maximize(double objective)
Sets the objective to maximize the provided expression.
static absl::StatusOr< std::unique_ptr< Solver > > New(SolverTypeProto solver_type, const ModelProto &model, const InitArgs &arguments)
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, CanComputeInfeasibleSubsystem)
SolverType
The solvers supported by MathOpt.
ASSERT_THAT(solver->Update(), IsOkAndHolds(DidUpdate()))
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
Enum< E >::Proto EnumToProto(std::optional< E > value)
In SWIG mode, we don't want anything besides these top-level includes.
std::string ProtobufShortDebugString(const P &message)
internal::StatusIsMatcher StatusIs(CodeMatcher code_matcher, MessageMatcher message_matcher)
#define ASSERT_OK_AND_ASSIGN(lhs, rexpr)
InvalidParameterTestParams(SolverType solver_type, SolveParameters solve_parameters, std::vector< std::string > expected_error_substrings)
std::vector< std::string > expected_error_substrings
SolveParameters solve_parameters
SolveParametersProto Proto() const