OR-Tools  9.6
ids_validator.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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_VALIDATORS_IDS_VALIDATOR_H_
15 #define OR_TOOLS_MATH_OPT_VALIDATORS_IDS_VALIDATOR_H_
16 
17 #include <stdint.h>
18 
19 #include <optional>
20 
21 #include "absl/status/status.h"
22 #include "absl/strings/string_view.h"
23 #include "absl/types/span.h"
25 
26 namespace operations_research {
27 namespace math_opt {
28 
29 // Checks that the input ids are in [0, max(int64_t)) range and that they are
30 // strictly increasing.
31 absl::Status CheckIdsRangeAndStrictlyIncreasing(absl::Span<const int64_t> ids);
32 
33 // Checks that the elements of ids are a subset of universe. Elements of ids
34 // do not need to be sorted or distinct. If upper_bound is set, elements must be
35 // strictly less than upper_bound.
36 //
37 // TODO(b/232526223): try merge this with the CheckIdsSubset overload below, or
38 // at least have one call the other.
39 absl::Status CheckIdsSubset(absl::Span<const int64_t> ids,
40  const IdNameBiMap& universe,
41  std::optional<int64_t> upper_bound = std::nullopt);
42 
43 // Checks that the elements of ids are a subset of universe. Elements of ids
44 // do not need to be sorted or distinct.
45 absl::Status CheckIdsSubset(absl::Span<const int64_t> ids,
46  const IdNameBiMap& universe,
47  absl::string_view ids_description,
48  absl::string_view universe_description);
49 
50 // first_ids and second_ids must include distinct ids.
51 absl::Status CheckIdsIdentical(absl::Span<const int64_t> first_ids,
52  const IdNameBiMap& second_ids,
53  absl::string_view first_description,
54  absl::string_view second_description);
55 
56 } // namespace math_opt
57 } // namespace operations_research
58 
59 #endif // OR_TOOLS_MATH_OPT_VALIDATORS_IDS_VALIDATOR_H_
absl::Status CheckIdsRangeAndStrictlyIncreasing(absl::Span< const int64_t > ids)
absl::Status CheckIdsSubset(absl::Span< const int64_t > ids, const IdNameBiMap &universe, std::optional< int64_t > upper_bound)
absl::Status CheckIdsIdentical(absl::Span< const int64_t > first_ids, const IdNameBiMap &second_ids, absl::string_view first_description, absl::string_view second_description)
Collection of objects used to extend the Constraint Solver library.
IntVar * upper_bound
Definition: routing.cc:1087