Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ip_model_solve_parameters_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_IP_MODEL_SOLVE_PARAMETERS_TESTS_H_
15#define OR_TOOLS_MATH_OPT_SOLVER_TESTS_IP_MODEL_SOLVE_PARAMETERS_TESTS_H_
16
17#include <iosfwd>
18#include <optional>
19#include <ostream>
20#include <string>
21
22#include "gtest/gtest.h"
25
26namespace operations_research {
27namespace math_opt {
28
29// Parameterized test suite that validates that an implementation of
30// SolverInterface::Solve() for an Integer Programming solver takes into account
31// correctly the input ModelSolveParametersProto.
32//
33// Usage:
34//
35// INSTANTIATE_TEST_SUITE_P(<Solver>IpModelSolveParametersTest,
36// IpModelSolveParametersTest,
37// testing::Values(SolverType::k<Solver>));
38//
40
41// Parameters for the MipSolutionHintTest suite below.
51
52 // The tested solver.
54
55 // Should be non-null if the solver supports a single hint. Furthermore, it
56 // must ensure that the solve terminates with the hinted solution, rather than
57 // the optimal solution. Some values (e.g. enable_output) may be overridden.
58 std::optional<SolveParameters> single_hint_params;
59
60 // Should be non-null if the solver supports a two hints. Furthermore, it
61 // must ensure that the solve terminates with the two hinted solutions (and
62 // returns both solutions), rather than the optimal solution. Some values
63 // (e.g. enable_output) may be overridden.
64 std::optional<SolveParameters> two_hint_params;
65
66 // A testing::ContainsRegex-compatible regex for the expected hint-acceptance
67 // message. see #regular-expression-syntax)
69
70 friend std::ostream& operator<<(std::ostream& out,
71 const SolutionHintTestParams& params);
72};
73
74// A suite of unit tests to show that an MIP solver handles solution hints
75// correctly.
76//
77// To use these tests, in file <solver>_test.cc write:
78// INSTANTIATE_TEST_SUITE_P(<Solver>MipSolutionHintTest, MipSolutionHintTest,
79// testing::Values(solution_hint_test_params));
81 : public ::testing::TestWithParam<SolutionHintTestParams> {
82 protected:
83 SolverType TestedSolver() const { return GetParam().solver_type; }
84 const std::optional<SolveParameters>& SingleHintParams() const {
85 return GetParam().single_hint_params;
86 }
87 const std::optional<SolveParameters>& TwoHintParams() const {
88 return GetParam().two_hint_params;
89 }
90 const std::string& HintAcceptedMessageRegex() const {
91 return GetParam().hint_accepted_message_regex;
92 }
93};
94
95// Parameters for the BranchPrioritiesTest suite below.
100
101 // The tested solver.
103
104 // Should ensure the solver behaves as close as possible to a pure
105 // branch-and-bound solver (e.g. turn presolve, heuristics and cuts off).
106 // Major deviations from this could cause the test to fail.
108
109 friend std::ostream& operator<<(std::ostream& out,
110 const BranchPrioritiesTestParams& params);
111};
112
113// A suite of unit tests to show that an MIP solver handles branching priorities
114// correctly.
115//
116// To use these tests, in file <solver>_test.cc write:
117// INSTANTIATE_TEST_SUITE_P(<Solver>BranchPrioritiesTest,
118// BranchPrioritiesTest,
119// testing::Values(branching_priorities_test_params));
121 : public ::testing::TestWithParam<BranchPrioritiesTestParams> {
122 protected:
123 SolverType TestedSolver() const { return GetParam().solver_type; }
124 const SolveParameters& SolveParams() const { return GetParam().solve_params; }
125};
126
127// Parameters for the LazyConstraintsTest suite below.
132
133 // The tested solver.
135
136 // Should ensure the solver behaves as close as possible to a pure
137 // branch-and-bound solver (e.g., turn presolve, heuristics and cuts off).
138 // Major deviations from this could cause the test to fail.
140
141 friend std::ostream& operator<<(std::ostream& out,
142 const LazyConstraintsTestParams& params);
143};
144
145// A suite of unit tests to show that an MIP solver handles lazy constraints
146// correctly.
147//
148// To use these tests, in file <solver>_test.cc write:
149// INSTANTIATE_TEST_SUITE_P(<Solver>LazyConstraintsTest,
150// LazyConstraintsTest,
151// testing::Values(lazy_constraints_test_params));
153 : public ::testing::TestWithParam<LazyConstraintsTestParams> {
154 protected:
155 SolverType TestedSolver() const { return GetParam().solver_type; }
157 return GetParam().nerfed_solve_params;
158 }
159};
160
161} // namespace math_opt
162} // namespace operations_research
163
164#endif // OR_TOOLS_MATH_OPT_SOLVER_TESTS_IP_MODEL_SOLVE_PARAMETERS_TESTS_H_
const std::optional< SolveParameters > & TwoHintParams() const
const std::optional< SolveParameters > & SingleHintParams() const
SolverType
The solvers supported by MathOpt.
Definition parameters.h:42
In SWIG mode, we don't want anything besides these top-level includes.
Parameters for the BranchPrioritiesTest suite below.
BranchPrioritiesTestParams(SolverType solver_type, SolveParameters solve_params)
friend std::ostream & operator<<(std::ostream &out, const BranchPrioritiesTestParams &params)
Parameters for the LazyConstraintsTest suite below.
friend std::ostream & operator<<(std::ostream &out, const LazyConstraintsTestParams &params)
LazyConstraintsTestParams(SolverType solver_type, SolveParameters solve_params)
Parameters for the MipSolutionHintTest suite below.
SolutionHintTestParams(SolverType solver_type, std::optional< SolveParameters > single_hint_params, std::optional< SolveParameters > two_hint_params, std::string hint_accepted_message_regex)
friend std::ostream & operator<<(std::ostream &out, const SolutionHintTestParams &params)