Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
qc_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_QC_TESTS_H_
15#define OR_TOOLS_MATH_OPT_SOLVER_TESTS_QC_TESTS_H_
16
17#include <ostream>
18
19#include "absl/status/statusor.h"
20#include "gtest/gtest.h"
22
24
27 bool supports_qc,
31
32 // The tested solver.
34
36
37 // True if the solver supports quadratic constraints.
39
40 // True if the solver supports incremental updates that add and/or delete
41 // quadratic constraints.
43
44 // True if the solver supports updates that delete variables involved in
45 // quadratic constraints.
47
48 // True if the solver supports integer variables.
50};
51
52std::ostream& operator<<(std::ostream& out, const QcTestParameters& params);
53
54// A suite of unit tests for (convex) quadratic constraints.
55//
56// To use these tests, in file <solver>_test.cc, write:
57// INSTANTIATE_TEST_SUITE_P(
58// <Solver>SimpleQcTest, SimpleQcTest,
59// testing::Values(QcTestParameters(SolverType::k<Solver>,
60// parameters, supports_qc,
61// supports_incremental_add_and_deletes,
62// supports_incremental_variable_deletions,
63// use_integer_variables)));
64class SimpleQcTest : public testing::TestWithParam<QcTestParameters> {
65 protected:
66 absl::StatusOr<SolveResult> SimpleSolve(const Model& model) {
67 return Solve(model, GetParam().solver_type,
68 {.parameters = GetParam().parameters});
69 }
70};
71
72// A suite of unit tests focused on incrementalism with quadratic constraints.
73// Note that a solver that does not support quadratic constraints should still
74// use this fixture to ensure that it is not silently ignoring one.
75//
76// To use these tests, in file <solver>_test.cc, write:
77// INSTANTIATE_TEST_SUITE_P(
78// <Solver>IncrementalQcTest, IncrementalQcTest,
79// testing::Values(QcTestParameters(SolverType::k<Solver>,
80// parameters, supports_qc,
81// supports_incremental_add_and_deletes,
82// supports_incremental_variable_deletions,
83// use_integer_variables)));
84class IncrementalQcTest : public testing::TestWithParam<QcTestParameters> {};
85
86// A suite of unit tests focused on testing dual solutions from QC solvers.
87//
88// To use these tests, in file <solver>_test.cc, write:
89// INSTANTIATE_TEST_SUITE_P(
90// <Solver>QcDualsTest, QcDualsTest,
91// testing::Values(QcTestParameters(SolverType::k<Solver>,
92// parameters, supports_qc,
93// supports_incremental_add_and_deletes,
94// supports_incremental_variable_deletions,
95// use_integer_variables)));
96class QcDualsTest : public testing::TestWithParam<QcTestParameters> {
97 protected:
98 absl::StatusOr<SolveResult> SimpleSolve(const Model& model) {
99 return Solve(model, GetParam().solver_type,
100 {.parameters = GetParam().parameters});
101 }
102};
103} // namespace operations_research::math_opt
104
105#endif // OR_TOOLS_MATH_OPT_SOLVER_TESTS_QC_TESTS_H_
absl::StatusOr< SolveResult > SimpleSolve(const Model &model)
Definition qc_tests.h:98
absl::StatusOr< SolveResult > SimpleSolve(const Model &model)
Definition qc_tests.h:66
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 qc_tests.h:49
SolverType solver_type
The tested solver.
Definition qc_tests.h:33
bool supports_qc
True if the solver supports quadratic constraints.
Definition qc_tests.h:38
QcTestParameters(SolverType solver_type, SolveParameters parameters, bool supports_qc, bool supports_incremental_add_and_deletes, bool supports_incremental_variable_deletions, bool use_integer_variables)
Definition qc_tests.cc:31