19#include "absl/algorithm/container.h"
20#include "absl/container/flat_hash_map.h"
21#include "absl/container/flat_hash_set.h"
22#include "absl/strings/string_view.h"
25#include "ortools/math_opt/model.pb.h"
26#include "ortools/math_opt/model_update.pb.h"
27#include "ortools/math_opt/sparse_containers.pb.h"
34 const absl::string_view
name) {
35 const VariableId
id = next_variable_id_;
36 VariableData& var_data = variables_[id];
40 var_data.name = std::string(
name);
46 std::vector<VariableId> result;
47 result.reserve(variables_.size());
48 for (
const auto& [
var, _] : variables_) {
49 result.push_back(
var);
55 std::vector<VariableId> result =
Variables();
61 const VariableId
start)
const {
62 std::vector<VariableId> result;
63 for (
const VariableId v :
65 if (variables_.contains(v)) {
72void VariableStorage::AppendVariable(
const VariableId variable,
73 VariablesProto*
proto)
const {
74 const VariableData& data = variables_.at(variable);
75 proto->add_ids(variable.value());
76 proto->add_lower_bounds(data.lower_bound);
77 proto->add_upper_bounds(data.upper_bound);
78 proto->add_integers(data.is_integer);
79 proto->add_names(data.name);
83 VariablesProto result;
85 AppendVariable(v, &result);
100 for (
const VariableId v : diff.
deleted) {
105 result.
updates.mutable_lower_bounds()->add_ids(v.value());
109 result.
updates.mutable_upper_bounds()->add_ids(v.value());
113 result.
updates.mutable_integers()->add_ids(v.value());
116 for (
const VariableId v :
118 if (variables_.contains(v)) {
119 AppendVariable(v, &result.
creates);
VariablesProto Proto() const
An equivalent proto of this.
std::vector< VariableId > Variables() const
The VariableIds in use (not deleted), order not defined.
bool is_integer(VariableId id) const
void AdvanceCheckpointInDiff(Diff &diff) const
Updates the checkpoint and clears all stored changes in diff.
std::vector< VariableId > SortedVariables() const
std::vector< VariableId > VariablesFrom(VariableId start) const
VariableId Add(double lower_bound, double upper_bound, bool is_integer, absl::string_view name)
UpdateResult Update(const Diff &diff) const
CpModelProto proto
The output proto.
const std::string name
A name for logging purposes.
An object oriented wrapper for quadratic constraints in ModelStorage.
std::vector< T > SortedSetElements(const absl::flat_hash_set< T > &elements)
StrongIntRange< IntType > MakeStrongIntRange(IntType end)
absl::flat_hash_set< VariableId > integer
absl::flat_hash_set< VariableId > lower_bounds
absl::flat_hash_set< VariableId > upper_bounds
absl::flat_hash_set< VariableId > deleted
google::protobuf::RepeatedField< int64_t > deleted
Variables before the checkpoint that have been deleted.
VariablesProto creates
Variables created at or after the checkpoint that have not been deleted.
VariableUpdatesProto updates
Variables before the checkpoint that have been modified and not deleted.