Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
attr_diff.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_ATTR_DIFF_H_
15#define OR_TOOLS_MATH_OPT_ELEMENTAL_ATTR_DIFF_H_
16
17#include <cstdint>
18#include <utility>
19
20#include "absl/container/flat_hash_set.h"
22
24
25// Tracks modifications to an Attribute with a key size of n (e.g., variable
26// lower bound has a key size of 1).
27template <int n, typename Symmetry>
28class AttrDiff {
29 public:
31
32 // On creation, the attribute is not modified for any key.
33 AttrDiff() = default;
34
35 // Clear all tracked modifications.
36 void Advance() { modified_keys_.clear(); }
37
38 // Mark the attribute as modified for `key`.
39 void SetModified(const Key key) { modified_keys_.insert(key); }
40
41 // Returns the attribute keys that have been modified for this attribute (the
42 // elements where set_modified() was called without a subsequent call to
43 // Advance()).
44 const AttrKeyHashSet<Key>& modified_keys() const { return modified_keys_; }
45
46 bool has_modified_keys() const { return !modified_keys_.empty(); }
47
48 // Stop tracking modifications for this attribute key. (Typically invoked when
49 // an element in the key was deleted from the model.)
50 void Erase(const Key key) { modified_keys_.erase(key); }
51
52 private:
53 AttrKeyHashSet<Key> modified_keys_;
54};
55
56} // namespace operations_research::math_opt
57
58#endif // OR_TOOLS_MATH_OPT_ELEMENTAL_ATTR_DIFF_H_
const AttrKeyHashSet< Key > & modified_keys() const
Definition attr_diff.h:44
AttrDiff()=default
On creation, the attribute is not modified for any key.
void Advance()
Clear all tracked modifications.
Definition attr_diff.h:36
void SetModified(const Key key)
Mark the attribute as modified for key.
Definition attr_diff.h:39
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
std::conditional_t<(AttrKeyT::size() > 0), absl::flat_hash_set< AttrKeyT >, detail::AttrKey0RawSet< typename AttrKeyT::SymmetryT, AttrKeyT > > AttrKeyHashSet
A hash set of AttrKeyT, where AttrKeyT is an AttrKey<n, Symmetry>.
Definition attr_key.h:347