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
14
#include "
ortools/math_opt/cpp/update_tracker.h
"
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"
22
#include "
ortools/base/logging.h
"
23
#include "
ortools/math_opt/model.pb.h
"
24
#include "
ortools/math_opt/storage/model_storage.h
"
25
26
namespace
operations_research
{
27
namespace
math_opt
{
28
29
UpdateTracker::~UpdateTracker
() {
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
39
UpdateTracker::UpdateTracker
(
const
std::shared_ptr<ModelStorage>& storage)
40
: storage_(ABSL_DIE_IF_NULL(storage)),
41
update_tracker_(storage->NewUpdateTracker()) {}
42
43
absl::StatusOr<std::optional<ModelUpdateProto>>
44
UpdateTracker::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
52
absl::Status
UpdateTracker::AdvanceCheckpoint
() {
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
61
absl::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
logging.h
operations_research::math_opt::UpdateTracker::~UpdateTracker
~UpdateTracker()
Definition
update_tracker.cc:29
operations_research::math_opt::UpdateTracker::ExportModel
absl::StatusOr< ModelProto > ExportModel(bool remove_names=false) const
Definition
update_tracker.cc:61
operations_research::math_opt::UpdateTracker::UpdateTracker
UpdateTracker(const std::shared_ptr< ModelStorage > &storage)
Definition
update_tracker.cc:39
operations_research::math_opt::UpdateTracker::AdvanceCheckpoint
absl::Status AdvanceCheckpoint()
Definition
update_tracker.cc:52
operations_research::math_opt::UpdateTracker::ExportModelUpdate
absl::StatusOr< std::optional< ModelUpdateProto > > ExportModelUpdate(bool remove_names=false)
Definition
update_tracker.cc:44
model.pb.h
model_storage.h
operations_research::math_opt::internal::kModelIsDestroyed
constexpr absl::string_view kModelIsDestroyed
Definition
update_tracker.h:110
operations_research::math_opt
Definition
gurobi_isv.cc:28
operations_research
OR-Tools root namespace.
Definition
binary_indexed_tree.h:21
update_tracker.h
ortools
math_opt
cpp
update_tracker.cc
Generated by
1.15.0