Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
qp_tests.h
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14#ifndef OR_TOOLS_MATH_OPT_SOLVER_TESTS_QP_TESTS_H_
15#define OR_TOOLS_MATH_OPT_SOLVER_TESTS_QP_TESTS_H_
16
17#include <iosfwd>
18#include <ostream>
19
20#include "absl/status/statusor.h"
21#include "gtest/gtest.h"
23
25
27
33
34 // The tested solver.
36
38
40
41 // True if the solver supports updates that do not modify existing quadratic
42 // objectives (adding quadratic objectives to LPs are OK).
44
45 // True if the solver supports arbitrary updates that change (add, delete, or
46 // update) quadratic objective coefficients.
48
49 // True if the solver supports integer variables.
51};
52
53std::ostream& operator<<(std::ostream& out, const QpTestParameters& params);
54
55// A suite of unit tests for quadratic objectives. Note that a solver that does
56// not support quadratic objectives should still use this fixture to ensure that
57// it is not silently ignoring one.
58//
59// To use these tests, in file <solver>_test.cc, write:
60// INSTANTIATE_TEST_SUITE_P(
61// <Solver>SimpleQpTest, SimpleQpTest,
62// testing::Values(QpTestParameters(SolverType::k<Solver>, parameters,
63// qp_support,
64// supports_incrementalism_not_modifying_qp,
65// supports_qp_incrementalism,
66// use_integer_variables)));
67class SimpleQpTest : public testing::TestWithParam<QpTestParameters> {
68 protected:
69 SolverType TestedSolver() const { return GetParam().solver_type; }
70 absl::StatusOr<SolveResult> SimpleSolve(const Model& model) {
71 return Solve(model, TestedSolver(), {.parameters = GetParam().parameters});
72 }
73};
74
75// A suite of unit tests focused on incrementalism with quadratic objectives.
76// Note that a solver that does not support quadratic objectives should still
77// use this fixture to ensure that it is not silently ignoring one.
78//
79// To use these tests, in file <solver>_test.cc, write:
80// INSTANTIATE_TEST_SUITE_P(
81// <Solver>IncrementalQpTest, IncrementalQpTest,
82// testing::Values(QpTestParameters(SolverType::k<Solver>, parameters,
83// qp_support,
84// supports_incrementalism_not_modifying_qp,
85// supports_qp_incrementalism,
86// use_integer_variables)));
87class IncrementalQpTest : public testing::TestWithParam<QpTestParameters> {
88 protected:
89 SolverType TestedSolver() const { return GetParam().solver_type; }
90};
91
92// A suite of unit tests focused on testing dual solutions from QP solvers.
93//
94// To use these tests, in file <solver>_test.cc, write:
95// INSTANTIATE_TEST_SUITE_P(
96// <Solver>QpDualsTest, QpDualsTest,
97// testing::Values(QpTestParameters(SolverType::k<Solver>, parameters,
98// qp_support,
99// supports_incrementalism_not_modifying_qp,
100// supports_qp_incrementalism,
101// use_integer_variables)));
102class QpDualsTest : public testing::TestWithParam<QpTestParameters> {
103 protected:
104 SolverType TestedSolver() const { return GetParam().solver_type; }
105 absl::StatusOr<SolveResult> SimpleSolve(const Model& model) {
106 return Solve(model, TestedSolver(), {.parameters = GetParam().parameters});
107 }
108};
109
110} // namespace operations_research::math_opt
111
112#endif // OR_TOOLS_MATH_OPT_SOLVER_TESTS_QP_TESTS_H_
absl::StatusOr< SolveResult > SimpleSolve(const Model &model)
Definition qp_tests.h:105
absl::StatusOr< SolveResult > SimpleSolve(const Model &model)
Definition qp_tests.h:70
GRBmodel * model
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
SolverType
The solvers supported by MathOpt.
Definition parameters.h:42
absl::StatusOr< SolveResult > Solve(const Model &model, const SolverType solver_type, const SolveArguments &solve_args, const SolverInitArguments &init_args)
Definition solve.cc:62
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
bool use_integer_variables
True if the solver supports integer variables.
Definition qp_tests.h:50
QpTestParameters(SolverType solver_type, SolveParameters parameters, QpSupportType qp_support, bool supports_incrementalism_not_modifying_qp, bool supports_qp_incrementalism, bool use_integer_variables)
Definition qp_tests.cc:51
SolverType solver_type
The tested solver.
Definition qp_tests.h:35