Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
testing.h
Go to the documentation of this file.
1// Copyright 2010-2025 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_ELEMENTAL_TESTING_H_
15#define OR_TOOLS_MATH_OPT_ELEMENTAL_TESTING_H_
16
17#include <cstdint>
18#include <random>
19#include <vector>
20
23
24// Creates `num_keys` random `AttrKey<n>`s. Each element is in the range
25// `[0, id_bound)`.
26template <int n, typename Symmetry>
27std::vector<AttrKey<n, Symmetry>> MakeRandomAttrKeys(const int num_keys,
28 const int64_t id_bound) {
29 std::minstd_rand rng;
30 rng.seed(1234); // For reproducibility.
31 std::uniform_int_distribution<int64_t> rand(0, id_bound - 1);
32 std::vector<AttrKey<n, Symmetry>> keys;
33 keys.reserve(num_keys);
34 for (int i = 0; i < num_keys; ++i) {
35 if constexpr (n == 0) {
36 keys.emplace_back();
37 } else if constexpr (n == 1) {
38 keys.emplace_back(rand(rng));
39 } else if constexpr (n == 2) {
40 keys.emplace_back(rand(rng), rand(rng));
41 }
42 }
43 return keys;
44}
45
46} // namespace operations_research::math_opt
47
48#endif // OR_TOOLS_MATH_OPT_ELEMENTAL_TESTING_H_
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
std::vector< AttrKey< n, Symmetry > > MakeRandomAttrKeys(const int num_keys, const int64_t id_bound)
Definition testing.h:27