OR-Tools  9.2
update_tracker.cc
Go to the documentation of this file.
1// Copyright 2010-2021 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
21#include "ortools/math_opt/model.pb.h"
22
23namespace operations_research {
24namespace math_opt {
25
27 const std::shared_ptr<ModelStorage> storage = storage_.lock();
28
29 // If the model has already been destroyed, the update tracker has been
30 // automatically cleaned.
31 if (storage != nullptr) {
32 storage->DeleteUpdateTracker(update_tracker_);
33 }
34}
35
36UpdateTracker::UpdateTracker(const std::shared_ptr<ModelStorage>& storage)
37 : storage_(ABSL_DIE_IF_NULL(storage)),
38 update_tracker_(storage->NewUpdateTracker()) {}
39
40std::optional<ModelUpdateProto> UpdateTracker::ExportModelUpdate() {
41 const std::shared_ptr<ModelStorage> storage = storage_.lock();
42 CHECK(storage != nullptr) << internal::kModelIsDestroyed;
43 return storage->ExportModelUpdate(update_tracker_);
44}
45
47 const std::shared_ptr<ModelStorage> storage = storage_.lock();
48 CHECK(storage != nullptr) << internal::kModelIsDestroyed;
49 storage->Checkpoint(update_tracker_);
50}
51
52ModelProto UpdateTracker::ExportModel() const {
53 const std::shared_ptr<ModelStorage> storage = storage_.lock();
54 CHECK(storage != nullptr) << internal::kModelIsDestroyed;
55 return storage->ExportModel();
56}
57
58} // namespace math_opt
59} // namespace operations_research
#define CHECK(condition)
Definition: base/logging.h:495
#define ABSL_DIE_IF_NULL
Definition: base/logging.h:43
std::optional< ModelUpdateProto > ExportModelUpdate()
UpdateTracker(const std::shared_ptr< ModelStorage > &storage)
constexpr absl::string_view kModelIsDestroyed
Collection of objects used to extend the Constraint Solver library.