Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
ip_parameter_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_PARAMETER_TESTS_H_
15#define OR_TOOLS_MATH_OPT_SOLVER_TESTS_IP_PARAMETER_TESTS_H_
16
17#include <iosfwd>
18#include <memory>
19#include <optional>
20#include <ostream>
21#include <string>
22#include <utility>
23
24#include "absl/status/statusor.h"
25#include "gtest/gtest.h"
27
28namespace operations_research {
29namespace math_opt {
30
31// Unless otherwise noted, each field indicates if setting an analogous field in
32// SolveParameters is supported.
33//
34// Note that "supported" may be context dependent, i.e. a parameter might be
35// supported for LP but not MIP with the same solver.
36//
37// Implementation note: keep parameters in the order they appear in
38// SolveParameters.
41 bool supports_node_limit = false;
42 bool supports_cutoff = false;
45
46 // Indicates if setting solution_limit with value 1 is supported.
48
49 // Supports setting threads = 1 (all but HiGHS support this).
50 bool supports_one_thread = false;
51
52 // Supports setting threads to an arbitrary value.
53 bool supports_n_threads = false;
54
59 bool supports_presolve = false;
60 bool supports_cuts = false;
61 bool supports_heuristics = false;
62 bool supports_scaling = false;
63};
64
65std::ostream& operator<<(std::ostream& ostr,
66 const ParameterSupport& param_support);
67
68// Indicates what data will be present in a SolveResult.
69//
70// Like ParameterSupport above, what data is "supported" by a solver may be
71// context dependent, i.e. a statistic might be supported for LP but not MIP
72// with the same solver.
74 // When the solve terminates from reaching a limit, if the specific limit
75 // reached is reported in Termination.
76 //
77 // This is very coarse, if we have solvers that report some limits but not
78 // others we may want to make this more granular for better testing.
79 bool termination_limit = false;
80 // If SolveStats reports iteration stats for LP/IPM/FOM.
81 bool iteration_stats = false;
82 // If SolveStats reports the node count.
83 bool node_count = false;
84};
85
86std::ostream& operator<<(std::ostream& ostr,
87 const SolveResultSupport& solve_result_support);
88
90 // Used as a suffix for the gUnit test name in parametric tests, use with the
91 // ParamName functor.
92 std::string name;
93
94 // The tested solver.
96
98 bool hint_supported = false;
100
101 // Contains a regexp found in the solver logs when presolve is enabled and
102 // the problem is completely solved in presolve, AND that is not found in
103 // the solver logs when presolve is disabled for the same model.
104 //
105 // It uses testing::ContainsRegex().
106 std::string presolved_regexp;
107
108 // Parameters to try and get the solver to stop early without completely
109 // solving the problem.
111};
112
113std::ostream& operator<<(std::ostream& ostr,
114 const IpParameterTestParameters& params);
115
116// A suite of unit tests to show that an IP solver handles parameters correctly.
117//
118// To use these tests, in file <solver>_test.cc write:
119// INSTANTIATE_TEST_SUITE_P(<Solver>IpParameterTest, IpParameterTest,
120// testing::Values(IpParameterTestParameters(
121// SolverType::k<Solver>,
122// /*supports_iteration_stats=*/true,
123// /*presolved_string=*/"presolved problem has 0 variables")));
125 : public ::testing::TestWithParam<IpParameterTestParameters> {
126 public:
127 SolverType TestedSolver() const { return GetParam().solver_type; }
128};
129
131 // Used as a suffix for the gUnit test name in parametric tests, use with the
132 // ParamName functor.
133 std::string name;
134
135 // The tested solver.
137
138 // Note: the test will further customize these.
140
142
143 // When we stop from hitting a limit, if the solver returns which limit was
144 // the cause in the Termination object. This parameter is very coarse, make
145 // it more specific if we have solvers that can return the limit some of the
146 // time.
148};
149
150std::ostream& operator<<(std::ostream& out,
151 const LargeInstanceTestParams& params);
152
153// Tests MIP parameters on the MIPLIB instance 23588, which has optimal solution
154// 8090 and LP relaxation of 7649.87. This instance was selected because every
155// supported solver can solve it quickly (a few seconds), but no solver can
156// solve it in one node (so we can test node limit) or too quickly (so we can
157// test time limit).
158//
159// The cut test uses beavma instead of 23588 (this made the test less brittle,
160// see cl/581963920 for details).
162 : public ::testing::TestWithParam<LargeInstanceTestParams> {
163 protected:
164 absl::StatusOr<std::unique_ptr<Model>> Load23588();
165 absl::StatusOr<std::unique_ptr<Model>> LoadBeavma();
166
167 static constexpr double kOptimalObjective = 8090.0;
168 // Computed with the command:
169 // blaze-bin/ortools/math_opt/tools/mathopt_solve \
170 // --input_file \
171 // operations_research_data/MIP_MIPLIB/miplib2017/23588.mps.gz \
172 // --solver_type glop --solver_logs --lp_relaxation
173 static constexpr double kLpRelaxationObjective = 7649.87;
174};
175
176} // namespace math_opt
177} // namespace operations_research
178
179#endif // OR_TOOLS_MATH_OPT_SOLVER_TESTS_IP_PARAMETER_TESTS_H_
absl::StatusOr< std::unique_ptr< Model > > LoadBeavma()
absl::StatusOr< std::unique_ptr< Model > > Load23588()
SolverType
The solvers supported by MathOpt.
Definition parameters.h:42
std::ostream & operator<<(std::ostream &ostr, const IndicatorConstraint &constraint)
In SWIG mode, we don't want anything besides these top-level includes.
bool supports_n_threads
Supports setting threads to an arbitrary value.
bool supports_one_thread
Supports setting threads = 1 (all but HiGHS support this).
bool supports_solution_limit_one
Indicates if setting solution_limit with value 1 is supported.
bool node_count
If SolveStats reports the node count.
bool iteration_stats
If SolveStats reports iteration stats for LP/IPM/FOM.