Google OR-Tools v9.11
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-2024 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/status/status.h"
20#include "absl/status/statusor.h"
22#include "ortools/math_opt/model.pb.h"
24
25namespace operations_research {
26namespace math_opt {
27
29 const std::shared_ptr<ModelStorage> storage = storage_.lock();
30
31 // If the model has already been destroyed, the update tracker has been
32 // automatically cleaned.
33 if (storage != nullptr) {
34 storage->DeleteUpdateTracker(update_tracker_);
35 }
36}
37
38UpdateTracker::UpdateTracker(const std::shared_ptr<ModelStorage>& storage)
39 : storage_(ABSL_DIE_IF_NULL(storage)),
40 update_tracker_(storage->NewUpdateTracker()) {}
41
42absl::StatusOr<std::optional<ModelUpdateProto>>
43UpdateTracker::ExportModelUpdate(const bool remove_names) {
44 const std::shared_ptr<ModelStorage> storage = storage_.lock();
45 if (storage == nullptr) {
46 return absl::InvalidArgumentError(internal::kModelIsDestroyed);
47 }
48 return storage->ExportModelUpdate(update_tracker_, remove_names);
49}
50
52 const std::shared_ptr<ModelStorage> storage = storage_.lock();
53 if (storage == nullptr) {
54 return absl::InvalidArgumentError(internal::kModelIsDestroyed);
55 }
56 storage->AdvanceCheckpoint(update_tracker_);
57 return absl::OkStatus();
58}
59
60absl::StatusOr<ModelProto> UpdateTracker::ExportModel(
61 const bool remove_names) const {
62 const std::shared_ptr<ModelStorage> storage = storage_.lock();
63 if (storage == nullptr) {
64 return absl::InvalidArgumentError(internal::kModelIsDestroyed);
65 }
66 return storage->ExportModel(remove_names);
67}
68
69} // namespace math_opt
70} // 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
In SWIG mode, we don't want anything besides these top-level includes.