21#include "absl/algorithm/container.h"
22#include "absl/container/flat_hash_map.h"
23#include "absl/container/flat_hash_set.h"
24#include "absl/strings/string_view.h"
25#include "absl/types/span.h"
28#include "ortools/math_opt/model.pb.h"
29#include "ortools/math_opt/model_update.pb.h"
30#include "ortools/math_opt/sparse_containers.pb.h"
38 const absl::string_view
name) {
41 Data& lin_con_data = linear_constraints_[id];
44 lin_con_data.name = std::string(
name);
50 std::vector<LinearConstraintId> result;
51 for (
const auto& [lin_con, _] : linear_constraints_) {
52 result.push_back(lin_con);
57std::vector<LinearConstraintId>
64std::vector<LinearConstraintId> LinearConstraintStorage::ConstraintsFrom(
66 std::vector<LinearConstraintId> result;
68 util_intops::MakeStrongIntRange(start, next_id_)) {
69 if (linear_constraints_.contains(
c)) {
76std::pair<LinearConstraintsProto, SparseDoubleMatrixProto>
78 LinearConstraintsProto constraints;
79 const std::vector<LinearConstraintId> sorted_constraints =
82 AppendConstraint(
id, &constraints);
84 return {constraints, matrix_.Proto()};
87void LinearConstraintStorage::AppendConstraint(
89 LinearConstraintsProto*
const proto)
const {
90 proto->add_ids(constraint.
value());
91 const Data& data = linear_constraints_.at(constraint);
92 proto->add_lower_bounds(data.lower_bound);
93 proto->add_upper_bounds(data.upper_bound);
95 proto->add_names(data.name);
100 LinearConstraintsProto result;
102 util_intops::MakeStrongIntRange(start,
end)) {
103 if (linear_constraints_.contains(
id)) {
104 AppendConstraint(
id, &result);
126 const Diff& diff,
const absl::flat_hash_set<VariableId>& deleted_variables,
127 absl::Span<const VariableId> new_variables)
const {
135 result.
updates.mutable_lower_bounds()->add_ids(
c.value());
140 result.
updates.mutable_upper_bounds()->add_ids(
c.value());
148 deleted_variables, new_variables, diff.
matrix_keys);
int64_t value() const
Returns the raw id value.
double lower_bound(LinearConstraintId id) const
LinearConstraintId next_id() const
UpdateResult Update(const Diff &diff, const absl::flat_hash_set< VariableId > &deleted_variables, absl::Span< const VariableId > new_variables) const
double upper_bound(LinearConstraintId id) const
std::pair< LinearConstraintsProto, SparseDoubleMatrixProto > Proto() const
Returns an equivalent proto of this.
void AdvanceCheckpointInDiff(VariableId variable_checkpoint, Diff &diff) const
Updates the checkpoint and clears all stored changes in diff.
const std::string & name(LinearConstraintId id) const
LinearConstraintId Add(double lower_bound, double upper_bound, absl::string_view name)
std::vector< LinearConstraintId > LinearConstraints() const
The LinearConstraintsIds in use (not deleted), order not defined.
std::vector< LinearConstraintId > SortedLinearConstraints() const
An object oriented wrapper for quadratic constraints in ModelStorage.
ElementId< ElementType::kVariable > VariableId
std::vector< T > SortedSetElements(const absl::flat_hash_set< T > &elements)
ElementId< ElementType::kLinearConstraint > LinearConstraintId
ClosedInterval::Iterator end(ClosedInterval interval)
absl::flat_hash_set< LinearConstraintId > lower_bounds
absl::flat_hash_set< LinearConstraintId > upper_bounds
absl::flat_hash_set< std::pair< LinearConstraintId, VariableId > > matrix_keys
LinearConstraintId checkpoint
Diff(const LinearConstraintStorage &storage, VariableId variable_checkpoint)
VariableId variable_checkpoint
absl::flat_hash_set< LinearConstraintId > deleted
LinearConstraintsProto creates
google::protobuf::RepeatedField< int64_t > deleted
LinearConstraintUpdatesProto updates
SparseDoubleMatrixProto matrix_updates