Google OR-Tools
v9.15
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 ORTOOLS_MATH_OPT_ELEMENTAL_ATTR_DIFF_H_
15
#define ORTOOLS_MATH_OPT_ELEMENTAL_ATTR_DIFF_H_
16
17
#include <cstdint>
18
#include <utility>
19
20
#include "absl/container/flat_hash_set.h"
21
#include "
ortools/math_opt/elemental/attr_key.h
"
22
23
namespace
operations_research::math_opt
{
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).
27
template
<
int
n,
typename
Symmetry>
28
class
AttrDiff
{
29
public
:
30
using
Key
=
AttrKey<n, Symmetry>
;
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
// ORTOOLS_MATH_OPT_ELEMENTAL_ATTR_DIFF_H_
attr_key.h
operations_research::math_opt::AttrDiff::Key
AttrKey< n, Symmetry > Key
Definition
attr_diff.h:30
operations_research::math_opt::AttrDiff::modified_keys
const AttrKeyHashSet< Key > & modified_keys() const
Definition
attr_diff.h:44
operations_research::math_opt::AttrDiff::Erase
void Erase(const Key key)
Definition
attr_diff.h:50
operations_research::math_opt::AttrDiff::AttrDiff
AttrDiff()=default
operations_research::math_opt::AttrDiff::Advance
void Advance()
Definition
attr_diff.h:36
operations_research::math_opt::AttrDiff::has_modified_keys
bool has_modified_keys() const
Definition
attr_diff.h:46
operations_research::math_opt::AttrDiff::SetModified
void SetModified(const Key key)
Definition
attr_diff.h:39
operations_research::math_opt::AttrKey
Definition
attr_key.h:39
operations_research::math_opt
Definition
gurobi_isv.cc:28
operations_research::math_opt::AttrKeyHashSet
std::conditional_t<(AttrKeyT::size() > 0), absl::flat_hash_set< AttrKeyT >, detail::AttrKey0RawSet< typename AttrKeyT::SymmetryT, AttrKeyT > > AttrKeyHashSet
Definition
attr_key.h:347
ortools
math_opt
elemental
attr_diff.h
Generated by
1.15.0