Google OR-Tools v9.14
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
element_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_ELEMENT_DIFF_H_
15#define OR_TOOLS_MATH_OPT_ELEMENTAL_ELEMENT_DIFF_H_
16
17#include <cstdint>
18
19#include "absl/container/flat_hash_set.h"
20
22
23// Tracks the ids of the elements in a model that:
24// 1. Are less than the checkpoint for this element.
25// 2. Have been deleted since the most recent time the checkpoint was advanced
26// (or creation of the ElementDiff if advance was never called).
27//
28// Generally:
29// * Element ids should be nonnegative.
30// * Each element should be deleted at most once.
31// * Sequential calls to Advance() should be called on non-decreasing
32// checkpoints.
33// However, these are enforced higher up the stack, not in this class.
35 public:
36 // The current checkpoint for this element, generally the next_id for this
37 // element when Advance() was last called (or at creation time if advance was
38 // never called).
39 int64_t checkpoint() const { return checkpoint_; }
40
41 // The elements that have been deleted before the checkpoint.
42 const absl::flat_hash_set<int64_t>& deleted() const { return deleted_; }
43
44 // Tracks the element `id` as deleted if it is less than the checkpoint.
45 void Delete(int64_t id) {
46 if (id < checkpoint_) {
47 deleted_.insert(id);
48 }
49 }
50
51 // Update the checkpoint and clears all tracked deletions.
52 void Advance(int64_t checkpoint) {
53 checkpoint_ = checkpoint;
54 deleted_.clear();
55 }
56
57 private:
58 int64_t checkpoint_ = 0;
59 absl::flat_hash_set<int64_t> deleted_;
60};
61
62} // namespace operations_research::math_opt
63
64#endif // OR_TOOLS_MATH_OPT_ELEMENTAL_ELEMENT_DIFF_H_
void Advance(int64_t checkpoint)
Update the checkpoint and clears all tracked deletions.
const absl::flat_hash_set< int64_t > & deleted() const
The elements that have been deleted before the checkpoint.
void Delete(int64_t id)
Tracks the element id as deleted if it is less than the checkpoint.
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28