Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
|
#include <update_tracker.h>
Public Member Functions | |
UpdateTracker (const std::shared_ptr< ModelStorage > &storage) | |
~UpdateTracker () | |
absl::StatusOr< std::optional< ModelUpdateProto > > | ExportModelUpdate (bool remove_names=false) |
absl::Status | AdvanceCheckpoint () |
absl::StatusOr< ModelProto > | ExportModel (bool remove_names=false) const |
Tracks the changes of the model.
This is an advanced feature that most users won't need. It is used internally to implement incrementalism but users don't have to understand how it works to use incremental solve.
For each update tracker we define a checkpoint that is the starting point used to compute the ModelUpdateProto.
No member function should be called after the destruction of the Model object. Note though that it is safe to call the destructor of UpdateTracker even if the Model object has been destroyed already.
Thread-safety: UpdateTracker methods must not be used while modifying the model (variables, constraints, ...). The user is expected to use proper synchronization primitives to serialize changes to the model and the use of the update trackers. The methods of different instances of UpdateTracker are safe to be called concurrently (i.e. multiple trackers can be called concurrently on ExportModelUpdate() or AdvanceCheckpoint()). The destructor of UpdateTracker is thread-safe.
Example: Model model; ... const std::unique_ptr<UpdateTracker> update_tracker = model.NewUpdateTracker();
model.AddVariable(0.0, 1.0, true, "y"); model.set_maximize(true);
ASSIGN_OR_RETURN(const std::optional<ModelUpdateProto> update_proto, update_tracker.ExportModelUpdate()); RETURN_IF_ERROR(update_tracker.AdvanceCheckpoint());
if (update_proto) { ... use *update_proto here ... }
Definition at line 70 of file update_tracker.h.
|
explicit |
This constructor should not be used directly. Instead use Model::NewUpdateTracker().
Definition at line 38 of file update_tracker.cc.
operations_research::math_opt::UpdateTracker::~UpdateTracker | ( | ) |
If the model has already been destroyed, the update tracker has been automatically cleaned.
Definition at line 28 of file update_tracker.cc.
absl::Status operations_research::math_opt::UpdateTracker::AdvanceCheckpoint | ( | ) |
Uses the current model state as the starting point to calculate the ModelUpdateProto next time ExportModelUpdate() is called.
If fails if the Model has been destroyed.
Definition at line 51 of file update_tracker.cc.
absl::StatusOr< ModelProto > operations_research::math_opt::UpdateTracker::ExportModel | ( | bool | remove_names = false | ) | const |
Returns a proto representation of the whole model.
This is a shortcut method that is equivalent to calling Model::ExportModel(). It is there so that users of the UpdateTracker can avoid having to keep a reference to the Model model.
If fails if the Model has been destroyed.
Definition at line 60 of file update_tracker.cc.
absl::StatusOr< std::optional< ModelUpdateProto > > operations_research::math_opt::UpdateTracker::ExportModelUpdate | ( | bool | remove_names = false | ) |
Returns a proto representation of the changes to the model since the most recent checkpoint (i.e. last time AdvanceCheckpoint() was called); nullopt if the update would have been empty.
If fails if the Model has been destroyed.
Definition at line 43 of file update_tracker.cc.