Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
update_tracker.cc
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
15
16#include <memory>
17#include <optional>
18
19#include "absl/log/die_if_null.h"
20#include "absl/status/status.h"
21#include "absl/status/statusor.h"
25
26namespace operations_research {
27namespace math_opt {
28
30 const std::shared_ptr<ModelStorage> storage = storage_.lock();
31
32 // If the model has already been destroyed, the update tracker has been
33 // automatically cleaned.
34 if (storage != nullptr) {
35 storage->DeleteUpdateTracker(update_tracker_);
36 }
37}
38
39UpdateTracker::UpdateTracker(const std::shared_ptr<ModelStorage>& storage)
40 : storage_(ABSL_DIE_IF_NULL(storage)),
41 update_tracker_(storage->NewUpdateTracker()) {}
42
43absl::StatusOr<std::optional<ModelUpdateProto>>
44UpdateTracker::ExportModelUpdate(const bool remove_names) {
45 const std::shared_ptr<ModelStorage> storage = storage_.lock();
46 if (storage == nullptr) {
47 return absl::InvalidArgumentError(internal::kModelIsDestroyed);
48 }
49 return storage->ExportModelUpdate(update_tracker_, remove_names);
50}
51
53 const std::shared_ptr<ModelStorage> storage = storage_.lock();
54 if (storage == nullptr) {
55 return absl::InvalidArgumentError(internal::kModelIsDestroyed);
56 }
57 storage->AdvanceCheckpoint(update_tracker_);
58 return absl::OkStatus();
59}
60
61absl::StatusOr<ModelProto> UpdateTracker::ExportModel(
62 const bool remove_names) const {
63 const std::shared_ptr<ModelStorage> storage = storage_.lock();
64 if (storage == nullptr) {
65 return absl::InvalidArgumentError(internal::kModelIsDestroyed);
66 }
67 return storage->ExportModel(remove_names);
68}
69
70} // namespace math_opt
71} // namespace operations_research
absl::StatusOr< ModelProto > ExportModel(bool remove_names=false) const
UpdateTracker(const std::shared_ptr< ModelStorage > &storage)
absl::StatusOr< std::optional< ModelUpdateProto > > ExportModelUpdate(bool remove_names=false)
constexpr absl::string_view kModelIsDestroyed
OR-Tools root namespace.