OR-Tools  9.2
ids_validator.h
Go to the documentation of this file.
1// Copyright 2010-2021 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 "absl/status/status.h"
20#include "absl/strings/string_view.h"
21#include "absl/types/span.h"
23
24namespace operations_research {
25namespace math_opt {
26
28 absl::Span<const int64_t> ids);
29
30// Checks that the elements of ids are a subset of universe.
31//
32// Assumed: ids and universe are sorted in increasing order, repeats allowed.
33absl::Status CheckSortedIdsSubset(const absl::Span<const int64_t> ids,
34 const absl::Span<const int64_t> universe);
35
36// Checks that the elements of ids are a subset of universe.
37//
38// Assumed: universe are sorted in strictly increasing order (no repeats). No
39// assumptions on ids.
40absl::Status CheckUnsortedIdsSubset(const absl::Span<const int64_t> ids,
41 const absl::Span<const int64_t> universe);
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.
45absl::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.
51absl::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// Provides a unified view of the id sets:
57// * NOT_DELETED = old - deleted
58// * FINAL = old - deleted + new
59// so users can validate if a list of ids (sorted or unsorted) is a subset of
60// either of the sets above.
61//
62// Implementation note: this class does not allocate by default, but some
63// functions will allocate at most O(#deleted + #new).
65 public:
66 // deleted_ids and new_ids must be sorted with unique strictly increasing
67 // entries.
69 const absl::Span<const int64_t> deleted_ids,
70 const absl::Span<const int64_t> new_ids)
71 : old_ids_(old_ids), deleted_ids_(deleted_ids), new_ids_(new_ids) {}
72
73 absl::Status IsValid() const;
74
75 // Checks that ids is a subset of NOT_DELETED = old_ids_ - deleted_ids_.
76 //
77 // ids must be sorted in increasing order (repeats are allowed).
79 const absl::Span<const int64_t> ids) const;
80
81 // Checks that ids is a subset of FINAL = old_ids_ - deleted_ids_ + new_ids_.
82 //
83 // ids must be sorted in increasing order (repeats are allowed).
84 absl::Status CheckSortedIdsSubsetOfFinal(
85 const absl::Span<const int64_t> ids) const;
86
87 // Checks that ids is a subset of FINAL = old_ids_ - deleted_ids_ + new_ids_.
88 //
89 // If ids is sorted, prefer CheckSortedIdsSubsetOfFinal.
90 absl::Status CheckIdsSubsetOfFinal(const absl::Span<const int64_t> ids) const;
91
92 private:
93 // NOT OWNED
94 const IdNameBiMap& old_ids_;
95 absl::Span<const int64_t> deleted_ids_;
96 absl::Span<const int64_t> new_ids_;
97};
98
99} // namespace math_opt
100} // namespace operations_research
101
102#endif // OR_TOOLS_MATH_OPT_VALIDATORS_IDS_VALIDATOR_H_
absl::Status CheckSortedIdsSubsetOfFinal(const absl::Span< const int64_t > ids) const
absl::Status CheckIdsSubsetOfFinal(const absl::Span< const int64_t > ids) const
IdUpdateValidator(const IdNameBiMap &old_ids, const absl::Span< const int64_t > deleted_ids, const absl::Span< const int64_t > new_ids)
Definition: ids_validator.h:68
absl::Status CheckSortedIdsSubsetOfNotDeleted(const absl::Span< const int64_t > ids) const
absl::Status CheckUnsortedIdsSubset(const absl::Span< const int64_t > ids, const absl::Span< const int64_t > universe)
absl::Status CheckIdsNonnegativeAndStrictlyIncreasing(absl::Span< const int64_t > ids)
absl::Status CheckSortedIdsSubset(const absl::Span< const int64_t > ids, const absl::Span< const int64_t > universe)
absl::Status CheckIdsSubset(absl::Span< const int64_t > ids, const IdNameBiMap &universe, absl::string_view ids_description, absl::string_view universe_description)
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.