14#ifndef OR_TOOLS_MATH_OPT_STORAGE_MODEL_STORAGE_H_
15#define OR_TOOLS_MATH_OPT_STORAGE_MODEL_STORAGE_H_
25#include "absl/container/flat_hash_map.h"
26#include "absl/container/flat_hash_set.h"
27#include "absl/log/check.h"
28#include "absl/status/status.h"
29#include "absl/status/statusor.h"
30#include "absl/strings/string_view.h"
35#include "ortools/math_opt/model.pb.h"
36#include "ortools/math_opt/model_update.pb.h"
37#include "ortools/math_opt/sparse_containers.pb.h"
167 static absl::StatusOr<std::unique_ptr<ModelStorage>> FromModelProto(
168 const ModelProto& model_proto);
171 inline explicit ModelStorage(absl::string_view model_name =
"",
172 absl::string_view primary_objective_name =
"");
174 ModelStorage(
const ModelStorage&) =
delete;
175 ModelStorage& operator=(
const ModelStorage&) =
delete;
183 std::unique_ptr<ModelStorage> Clone(
184 std::optional<absl::string_view> new_name = std::nullopt)
const;
186 inline const std::string&
name()
const {
return name_; }
195 inline VariableId AddVariable(absl::string_view
name =
"");
203 bool is_integer, absl::string_view
name =
"");
205 inline double variable_lower_bound(VariableId
id)
const;
206 inline double variable_upper_bound(VariableId
id)
const;
207 inline bool is_variable_integer(VariableId
id)
const;
208 inline const std::string& variable_name(VariableId
id)
const;
210 inline void set_variable_lower_bound(VariableId
id,
double lower_bound);
211 inline void set_variable_upper_bound(VariableId
id,
double upper_bound);
212 inline void set_variable_is_integer(VariableId
id,
bool is_integer);
213 inline void set_variable_as_integer(VariableId
id);
214 inline void set_variable_as_continuous(VariableId
id);
221 void DeleteVariable(VariableId
id);
227 inline int num_variables()
const;
232 inline VariableId next_variable_id()
const;
235 inline void ensure_next_variable_id_at_least(VariableId
id);
238 inline bool has_variable(VariableId
id)
const;
241 std::vector<VariableId> variables()
const;
247 std::vector<VariableId> SortedVariables()
const;
257 inline LinearConstraintId AddLinearConstraint(absl::string_view
name =
"");
265 absl::string_view
name =
"");
267 inline double linear_constraint_lower_bound(LinearConstraintId
id)
const;
268 inline double linear_constraint_upper_bound(LinearConstraintId
id)
const;
269 inline const std::string& linear_constraint_name(LinearConstraintId
id)
const;
271 inline void set_linear_constraint_lower_bound(LinearConstraintId
id,
273 inline void set_linear_constraint_upper_bound(LinearConstraintId
id,
281 void DeleteLinearConstraint(LinearConstraintId
id);
287 inline int num_linear_constraints()
const;
292 inline LinearConstraintId next_linear_constraint_id()
const;
296 inline void ensure_next_linear_constraint_id_at_least(LinearConstraintId
id);
299 inline bool has_linear_constraint(LinearConstraintId
id)
const;
302 std::vector<LinearConstraintId> LinearConstraints()
const;
308 std::vector<LinearConstraintId> SortedLinearConstraints()
const;
315 inline double linear_constraint_coefficient(LinearConstraintId constraint,
316 VariableId variable)
const;
317 inline bool is_linear_constraint_coefficient_nonzero(
318 LinearConstraintId constraint, VariableId variable)
const;
323 inline void set_linear_constraint_coefficient(LinearConstraintId constraint,
329 inline std::vector<std::tuple<LinearConstraintId, VariableId, double>>
330 linear_constraint_matrix()
const;
333 inline std::vector<VariableId> variables_in_linear_constraint(
334 LinearConstraintId constraint)
const;
337 inline std::vector<LinearConstraintId> linear_constraints_with_variable(
338 VariableId variable)
const;
347 inline bool is_maximize(ObjectiveId
id)
const;
348 inline int64_t objective_priority(ObjectiveId
id)
const;
349 inline double objective_offset(ObjectiveId
id)
const;
351 inline double linear_objective_coefficient(ObjectiveId
id,
352 VariableId variable)
const;
354 inline double quadratic_objective_coefficient(
355 ObjectiveId
id, VariableId first_variable,
356 VariableId second_variable)
const;
357 inline bool is_linear_objective_coefficient_nonzero(
358 ObjectiveId
id, VariableId variable)
const;
360 inline bool is_quadratic_objective_coefficient_nonzero(
361 ObjectiveId
id, VariableId first_variable,
362 VariableId second_variable)
const;
363 inline const std::string& objective_name(ObjectiveId
id)
const;
365 inline void set_is_maximize(ObjectiveId
id,
bool is_maximize);
366 inline void set_maximize(ObjectiveId
id);
367 inline void set_minimize(ObjectiveId
id);
368 inline void set_objective_priority(ObjectiveId
id, int64_t
value);
369 inline void set_objective_offset(ObjectiveId
id,
double value);
373 inline void set_linear_objective_coefficient(ObjectiveId
id,
379 inline void set_quadratic_objective_coefficient(ObjectiveId
id,
380 VariableId first_variable,
381 VariableId second_variable,
388 inline void clear_objective(ObjectiveId
id);
391 inline const absl::flat_hash_map<VariableId, double>& linear_objective(
392 ObjectiveId
id)
const;
394 inline int64_t num_linear_objective_terms(ObjectiveId
id)
const;
396 inline int64_t num_quadratic_objective_terms(ObjectiveId
id)
const;
402 inline std::vector<std::tuple<VariableId, VariableId, double>>
403 quadratic_objective_terms(ObjectiveId
id)
const;
417 inline AuxiliaryObjectiveId AddAuxiliaryObjective(
418 int64_t priority, absl::string_view
name =
"");
425 inline void DeleteAuxiliaryObjective(AuxiliaryObjectiveId
id);
431 inline int num_auxiliary_objectives()
const;
436 inline AuxiliaryObjectiveId next_auxiliary_objective_id()
const;
440 inline void ensure_next_auxiliary_objective_id_at_least(
441 AuxiliaryObjectiveId
id);
444 inline bool has_auxiliary_objective(AuxiliaryObjectiveId
id)
const;
447 inline std::vector<AuxiliaryObjectiveId> AuxiliaryObjectives()
const;
454 inline std::vector<AuxiliaryObjectiveId> SortedAuxiliaryObjectives()
const;
470 template <
typename Constra
intData>
471 inline typename ConstraintData::IdType AddAtomicConstraint(
472 ConstraintData data);
478 template <
typename IdType>
479 inline void DeleteAtomicConstraint(IdType
id);
482 template <
typename IdType>
483 inline const typename AtomicConstraintTraits<IdType>::ConstraintData&
484 constraint_data(IdType
id)
const;
491 template <
typename IdType>
492 inline int64_t num_constraints()
const;
496 template <
typename IdType>
497 inline IdType next_constraint_id()
const;
502 template <
typename IdType>
503 inline void ensure_next_constraint_id_at_least(IdType
id);
506 template <
typename IdType>
507 inline bool has_constraint(IdType
id)
const;
510 template <
typename IdType>
511 std::vector<IdType> Constraints()
const;
517 template <
typename IdType>
518 std::vector<IdType> SortedConstraints()
const;
523 template <
typename IdType>
524 inline std::vector<IdType> ConstraintsWithVariable(
525 VariableId variable_id)
const;
528 template <
typename IdType>
529 inline std::vector<VariableId> VariablesInConstraint(IdType
id)
const;
538 ModelProto ExportModel(
bool remove_names =
false)
const;
583 UpdateTrackerId NewUpdateTracker();
599 void DeleteUpdateTracker(UpdateTrackerId update_tracker);
611 std::optional<ModelUpdateProto> ExportModelUpdate(
612 UpdateTrackerId update_tracker,
bool remove_names =
false)
const;
623 void AdvanceCheckpoint(UpdateTrackerId update_tracker);
633 absl::Status ApplyUpdateProto(
const ModelUpdateProto& update_proto);
636 struct UpdateTrackerData {
638 const VariableStorage& variables,
const ObjectiveStorage& objectives,
639 const LinearConstraintStorage& linear_constraints,
640 const AtomicConstraintStorage<QuadraticConstraintData>&
641 quadratic_constraints,
642 const AtomicConstraintStorage<SecondOrderConeConstraintData>
644 const AtomicConstraintStorage<Sos1ConstraintData>& sos1_constraints,
645 const AtomicConstraintStorage<Sos2ConstraintData>& sos2_constraints,
646 const AtomicConstraintStorage<IndicatorConstraintData>&
647 indicator_constraints)
648 : dirty_variables(variables),
649 dirty_objective(objectives, variables.next_id()),
650 dirty_linear_constraints(linear_constraints,
651 dirty_variables.checkpoint),
652 dirty_quadratic_constraints(quadratic_constraints),
653 dirty_soc_constraints(soc_constraints),
654 dirty_sos1_constraints(sos1_constraints),
655 dirty_sos2_constraints(sos2_constraints),
656 dirty_indicator_constraints(indicator_constraints) {}
662 std::optional<ModelUpdateProto> ExportModelUpdate(
663 const ModelStorage& storage,
bool remove_names =
false)
const;
667 void AdvanceCheckpoint(
const ModelStorage& storage);
671 template <
typename Constra
intData>
672 static constexpr typename AtomicConstraintStorage<ConstraintData>::Diff
674 AtomicConstraintDirtyFieldPtr();
682 VariableStorage::Diff dirty_variables;
683 ObjectiveStorage::Diff dirty_objective;
684 LinearConstraintStorage::Diff dirty_linear_constraints;
685 AtomicConstraintStorage<QuadraticConstraintData>::Diff
686 dirty_quadratic_constraints;
687 AtomicConstraintStorage<SecondOrderConeConstraintData>::Diff
688 dirty_soc_constraints;
689 AtomicConstraintStorage<Sos1ConstraintData>::Diff dirty_sos1_constraints;
690 AtomicConstraintStorage<Sos2ConstraintData>::Diff dirty_sos2_constraints;
691 AtomicConstraintStorage<IndicatorConstraintData>::Diff
692 dirty_indicator_constraints;
695 auto UpdateAndGetVariableDiffs() {
696 return MakeUpdateDataFieldRange<&UpdateTrackerData::dirty_variables>(
697 update_trackers_.GetUpdatedTrackers());
700 auto UpdateAndGetObjectiveDiffs() {
701 return MakeUpdateDataFieldRange<&UpdateTrackerData::dirty_objective>(
702 update_trackers_.GetUpdatedTrackers());
705 auto UpdateAndGetLinearConstraintDiffs() {
707 &UpdateTrackerData::dirty_linear_constraints>(
708 update_trackers_.GetUpdatedTrackers());
712 void AddVariables(
const VariablesProto& variables);
715 void AddAuxiliaryObjectives(
716 const google::protobuf::Map<int64_t, ObjectiveProto>& objectives);
719 void AddLinearConstraints(
const LinearConstraintsProto& linear_constraints);
721 void UpdateObjective(ObjectiveId
id,
const ObjectiveUpdatesProto& update);
725 void UpdateLinearObjectiveCoefficients(
726 ObjectiveId
id,
const SparseDoubleVectorProto&
coefficients);
730 void UpdateQuadraticObjectiveCoefficients(
731 ObjectiveId
id,
const SparseDoubleMatrixProto&
coefficients);
735 void UpdateLinearConstraintCoefficients(
740 template <
typename Constra
intData>
741 AtomicConstraintStorage<ConstraintData>& constraint_storage();
745 template <
typename Constra
intData>
746 const AtomicConstraintStorage<ConstraintData>& constraint_storage()
const;
750 VariableStorage variables_;
751 ObjectiveStorage objectives_;
752 LinearConstraintStorage linear_constraints_;
754 AtomicConstraintStorage<QuadraticConstraintData> quadratic_constraints_;
755 AtomicConstraintStorage<SecondOrderConeConstraintData> soc_constraints_;
756 AtomicConstraintStorage<Sos1ConstraintData> sos1_constraints_;
757 AtomicConstraintStorage<Sos2ConstraintData> sos2_constraints_;
758 AtomicConstraintStorage<IndicatorConstraintData> indicator_constraints_;
760 UpdateTrackers<UpdateTrackerData> update_trackers_;
769ModelStorage::ModelStorage(
const absl::string_view model_name,
770 const absl::string_view primary_objective_name)
771 : name_(model_name), objectives_(primary_objective_name) {}
777VariableId ModelStorage::AddVariable(absl::string_view
name) {
778 return AddVariable(-std::numeric_limits<double>::infinity(),
779 std::numeric_limits<double>::infinity(),
false,
name);
782double ModelStorage::variable_lower_bound(
const VariableId
id)
const {
783 return variables_.lower_bound(
id);
786double ModelStorage::variable_upper_bound(
const VariableId
id)
const {
787 return variables_.upper_bound(
id);
790bool ModelStorage::is_variable_integer(VariableId
id)
const {
791 return variables_.is_integer(
id);
794const std::string& ModelStorage::variable_name(
const VariableId
id)
const {
795 return variables_.name(
id);
798void ModelStorage::set_variable_lower_bound(
const VariableId
id,
800 variables_.set_lower_bound(
id,
lower_bound, UpdateAndGetVariableDiffs());
803void ModelStorage::set_variable_upper_bound(
const VariableId
id,
805 variables_.set_upper_bound(
id,
upper_bound, UpdateAndGetVariableDiffs());
808void ModelStorage::set_variable_is_integer(
const VariableId
id,
809 const bool is_integer) {
810 variables_.set_integer(
id, is_integer, UpdateAndGetVariableDiffs());
813void ModelStorage::set_variable_as_integer(VariableId
id) {
814 set_variable_is_integer(
id,
true);
817void ModelStorage::set_variable_as_continuous(VariableId
id) {
818 set_variable_is_integer(
id,
false);
821int ModelStorage::num_variables()
const {
return variables_.size(); }
823VariableId ModelStorage::next_variable_id()
const {
824 return variables_.next_id();
827void ModelStorage::ensure_next_variable_id_at_least(
const VariableId
id) {
828 variables_.ensure_next_id_at_least(
id);
831bool ModelStorage::has_variable(
const VariableId
id)
const {
832 return variables_.contains(
id);
839LinearConstraintId ModelStorage::AddLinearConstraint(absl::string_view
name) {
840 return AddLinearConstraint(-std::numeric_limits<double>::infinity(),
841 std::numeric_limits<double>::infinity(),
name);
844double ModelStorage::linear_constraint_lower_bound(
845 const LinearConstraintId
id)
const {
846 return linear_constraints_.lower_bound(
id);
849double ModelStorage::linear_constraint_upper_bound(
850 const LinearConstraintId
id)
const {
851 return linear_constraints_.upper_bound(
id);
854const std::string& ModelStorage::linear_constraint_name(
855 const LinearConstraintId
id)
const {
856 return linear_constraints_.name(
id);
859void ModelStorage::set_linear_constraint_lower_bound(
860 const LinearConstraintId
id,
const double lower_bound) {
861 linear_constraints_.set_lower_bound(
id,
lower_bound,
862 UpdateAndGetLinearConstraintDiffs());
865void ModelStorage::set_linear_constraint_upper_bound(
866 const LinearConstraintId
id,
const double upper_bound) {
867 linear_constraints_.set_upper_bound(
id,
upper_bound,
868 UpdateAndGetLinearConstraintDiffs());
871int ModelStorage::num_linear_constraints()
const {
872 return linear_constraints_.size();
875LinearConstraintId ModelStorage::next_linear_constraint_id()
const {
876 return linear_constraints_.next_id();
879void ModelStorage::ensure_next_linear_constraint_id_at_least(
880 LinearConstraintId
id) {
881 linear_constraints_.ensure_next_id_at_least(
id);
884bool ModelStorage::has_linear_constraint(
const LinearConstraintId
id)
const {
885 return linear_constraints_.contains(
id);
892double ModelStorage::linear_constraint_coefficient(
893 LinearConstraintId constraint, VariableId variable)
const {
894 return linear_constraints_.matrix().get(constraint, variable);
897bool ModelStorage::is_linear_constraint_coefficient_nonzero(
898 LinearConstraintId constraint, VariableId variable)
const {
899 return linear_constraints_.matrix().contains(constraint, variable);
902void ModelStorage::set_linear_constraint_coefficient(
903 const LinearConstraintId constraint,
const VariableId variable,
904 const double value) {
905 linear_constraints_.set_term(constraint, variable,
value,
906 UpdateAndGetLinearConstraintDiffs());
909std::vector<std::tuple<LinearConstraintId, VariableId, double>>
910ModelStorage::linear_constraint_matrix()
const {
911 return linear_constraints_.matrix().Terms();
914std::vector<VariableId> ModelStorage::variables_in_linear_constraint(
915 LinearConstraintId constraint)
const {
916 return linear_constraints_.matrix().row(constraint);
919std::vector<LinearConstraintId> ModelStorage::linear_constraints_with_variable(
920 VariableId variable)
const {
921 return linear_constraints_.matrix().column(variable);
928bool ModelStorage::is_maximize(
const ObjectiveId
id)
const {
929 return objectives_.maximize(
id);
932int64_t ModelStorage::objective_priority(
const ObjectiveId
id)
const {
933 return objectives_.priority(
id);
936double ModelStorage::objective_offset(
const ObjectiveId
id)
const {
937 return objectives_.offset(
id);
940double ModelStorage::linear_objective_coefficient(
941 const ObjectiveId
id,
const VariableId variable)
const {
942 return objectives_.linear_term(
id, variable);
945double ModelStorage::quadratic_objective_coefficient(
946 const ObjectiveId
id,
const VariableId first_variable,
947 const VariableId second_variable)
const {
948 return objectives_.quadratic_term(
id, first_variable, second_variable);
951bool ModelStorage::is_linear_objective_coefficient_nonzero(
952 const ObjectiveId
id,
const VariableId variable)
const {
953 return objectives_.linear_terms(
id).contains(variable);
956bool ModelStorage::is_quadratic_objective_coefficient_nonzero(
957 const ObjectiveId
id,
const VariableId first_variable,
958 const VariableId second_variable)
const {
959 return objectives_.quadratic_terms(
id).get(first_variable, second_variable) !=
963const std::string& ModelStorage::objective_name(
const ObjectiveId
id)
const {
964 return objectives_.name(
id);
967void ModelStorage::set_is_maximize(
const ObjectiveId
id,
968 const bool is_maximize) {
969 objectives_.set_maximize(
id, is_maximize, UpdateAndGetObjectiveDiffs());
972void ModelStorage::set_maximize(
const ObjectiveId
id) {
973 set_is_maximize(
id,
true);
976void ModelStorage::set_minimize(
const ObjectiveId
id) {
977 set_is_maximize(
id,
false);
980void ModelStorage::set_objective_priority(
const ObjectiveId
id,
981 const int64_t
value) {
982 objectives_.set_priority(
id,
value, UpdateAndGetObjectiveDiffs());
985void ModelStorage::set_objective_offset(
const ObjectiveId
id,
986 const double value) {
987 objectives_.set_offset(
id,
value, UpdateAndGetObjectiveDiffs());
990void ModelStorage::set_linear_objective_coefficient(
const ObjectiveId
id,
991 const VariableId variable,
992 const double value) {
993 objectives_.set_linear_term(
id, variable,
value,
994 UpdateAndGetObjectiveDiffs());
997void ModelStorage::set_quadratic_objective_coefficient(
998 const ObjectiveId
id,
const VariableId first_variable,
999 const VariableId second_variable,
const double value) {
1000 objectives_.set_quadratic_term(
id, first_variable, second_variable,
value,
1001 UpdateAndGetObjectiveDiffs());
1004void ModelStorage::clear_objective(
const ObjectiveId
id) {
1005 objectives_.Clear(
id, UpdateAndGetObjectiveDiffs());
1008const absl::flat_hash_map<VariableId, double>& ModelStorage::linear_objective(
1009 const ObjectiveId
id)
const {
1010 return objectives_.linear_terms(
id);
1013int64_t ModelStorage::num_linear_objective_terms(
const ObjectiveId
id)
const {
1014 return objectives_.linear_terms(
id).size();
1017int64_t ModelStorage::num_quadratic_objective_terms(
1018 const ObjectiveId
id)
const {
1019 return objectives_.quadratic_terms(
id).nonzeros();
1022std::vector<std::tuple<VariableId, VariableId, double>>
1023ModelStorage::quadratic_objective_terms(
const ObjectiveId
id)
const {
1024 return objectives_.quadratic_terms(
id).Terms();
1031AuxiliaryObjectiveId ModelStorage::AddAuxiliaryObjective(
1032 const int64_t priority,
const absl::string_view
name) {
1033 return objectives_.AddAuxiliaryObjective(priority,
name);
1036void ModelStorage::DeleteAuxiliaryObjective(
const AuxiliaryObjectiveId
id) {
1037 objectives_.Delete(
id, UpdateAndGetObjectiveDiffs());
1040int ModelStorage::num_auxiliary_objectives()
const {
1041 return static_cast<int>(objectives_.num_auxiliary_objectives());
1044AuxiliaryObjectiveId ModelStorage::next_auxiliary_objective_id()
const {
1045 return objectives_.next_id();
1048void ModelStorage::ensure_next_auxiliary_objective_id_at_least(
1049 const AuxiliaryObjectiveId
id) {
1050 objectives_.ensure_next_id_at_least(
id);
1053bool ModelStorage::has_auxiliary_objective(
1054 const AuxiliaryObjectiveId
id)
const {
1055 return objectives_.contains(
id);
1058std::vector<AuxiliaryObjectiveId> ModelStorage::AuxiliaryObjectives()
const {
1059 return objectives_.AuxiliaryObjectives();
1062std::vector<AuxiliaryObjectiveId> ModelStorage::SortedAuxiliaryObjectives()
1064 return objectives_.SortedAuxiliaryObjectives();
1071template <
typename Constra
intData>
1072typename ConstraintData::IdType ModelStorage::AddAtomicConstraint(
1073 ConstraintData data) {
1074 return constraint_storage<ConstraintData>().AddConstraint(data);
1077template <
typename IdType>
1078void ModelStorage::DeleteAtomicConstraint(
const IdType
id) {
1079 using ConstraintData =
1080 typename AtomicConstraintTraits<IdType>::ConstraintData;
1081 auto& storage = constraint_storage<ConstraintData>();
1082 CHECK(storage.contains(
id));
1085 MakeUpdateDataFieldRange<
1086 UpdateTrackerData::AtomicConstraintDirtyFieldPtr<ConstraintData>()>(
1087 update_trackers_.GetUpdatedTrackers()));
1090template <
typename IdType>
1091const typename AtomicConstraintTraits<IdType>::ConstraintData&
1092ModelStorage::constraint_data(
const IdType
id)
const {
1093 using ConstraintData =
1094 typename AtomicConstraintTraits<IdType>::ConstraintData;
1095 return constraint_storage<ConstraintData>().data(
id);
1098template <
typename IdType>
1099int64_t ModelStorage::num_constraints()
const {
1100 using ConstraintData =
1101 typename AtomicConstraintTraits<IdType>::ConstraintData;
1102 return constraint_storage<ConstraintData>().size();
1105template <
typename IdType>
1106IdType ModelStorage::next_constraint_id()
const {
1107 using ConstraintData =
1108 typename AtomicConstraintTraits<IdType>::ConstraintData;
1109 return constraint_storage<ConstraintData>().next_id();
1112template <
typename IdType>
1113void ModelStorage::ensure_next_constraint_id_at_least(
const IdType
id) {
1114 using ConstraintData =
1115 typename AtomicConstraintTraits<IdType>::ConstraintData;
1116 return constraint_storage<ConstraintData>().ensure_next_id_at_least(
id);
1119template <
typename IdType>
1120bool ModelStorage::has_constraint(
const IdType
id)
const {
1121 using ConstraintData =
1122 typename AtomicConstraintTraits<IdType>::ConstraintData;
1123 return constraint_storage<ConstraintData>().contains(
id);
1126template <
typename IdType>
1127std::vector<IdType> ModelStorage::Constraints()
const {
1128 using ConstraintData =
1129 typename AtomicConstraintTraits<IdType>::ConstraintData;
1130 return constraint_storage<ConstraintData>().Constraints();
1133template <
typename IdType>
1134std::vector<IdType> ModelStorage::SortedConstraints()
const {
1135 using ConstraintData =
1136 typename AtomicConstraintTraits<IdType>::ConstraintData;
1137 return constraint_storage<ConstraintData>().SortedConstraints();
1140template <
typename IdType>
1141std::vector<IdType> ModelStorage::ConstraintsWithVariable(
1142 const VariableId variable_id)
const {
1143 using ConstraintData =
1144 typename AtomicConstraintTraits<IdType>::ConstraintData;
1145 const absl::flat_hash_set<IdType> constraints =
1146 constraint_storage<ConstraintData>().RelatedConstraints(variable_id);
1147 return {constraints.begin(), constraints.end()};
1150template <
typename IdType>
1151std::vector<VariableId> ModelStorage::VariablesInConstraint(
1152 const IdType
id)
const {
1153 return constraint_data(
id).RelatedVariables();
1163inline AtomicConstraintStorage<QuadraticConstraintData>&
1164ModelStorage::constraint_storage() {
1165 return quadratic_constraints_;
1169inline const AtomicConstraintStorage<QuadraticConstraintData>&
1170ModelStorage::constraint_storage()
const {
1171 return quadratic_constraints_;
1175constexpr typename AtomicConstraintStorage<QuadraticConstraintData>::Diff
1176 ModelStorage::UpdateTrackerData::*
1177 ModelStorage::UpdateTrackerData::AtomicConstraintDirtyFieldPtr<
1178 QuadraticConstraintData>() {
1179 return &UpdateTrackerData::dirty_quadratic_constraints;
1185inline AtomicConstraintStorage<SecondOrderConeConstraintData>&
1186ModelStorage::constraint_storage() {
1187 return soc_constraints_;
1191inline const AtomicConstraintStorage<SecondOrderConeConstraintData>&
1192ModelStorage::constraint_storage()
const {
1193 return soc_constraints_;
1197constexpr typename AtomicConstraintStorage<SecondOrderConeConstraintData>::Diff
1198 ModelStorage::UpdateTrackerData::*
1199 ModelStorage::UpdateTrackerData::AtomicConstraintDirtyFieldPtr<
1200 SecondOrderConeConstraintData>() {
1201 return &UpdateTrackerData::dirty_soc_constraints;
1207inline AtomicConstraintStorage<Sos1ConstraintData>&
1208ModelStorage::constraint_storage() {
1209 return sos1_constraints_;
1213inline const AtomicConstraintStorage<Sos1ConstraintData>&
1214ModelStorage::constraint_storage()
const {
1215 return sos1_constraints_;
1219constexpr typename AtomicConstraintStorage<Sos1ConstraintData>::Diff
1220 ModelStorage::UpdateTrackerData::*
1221 ModelStorage::UpdateTrackerData::AtomicConstraintDirtyFieldPtr<
1223 return &UpdateTrackerData::dirty_sos1_constraints;
1229inline AtomicConstraintStorage<Sos2ConstraintData>&
1230ModelStorage::constraint_storage() {
1231 return sos2_constraints_;
1235inline const AtomicConstraintStorage<Sos2ConstraintData>&
1236ModelStorage::constraint_storage()
const {
1237 return sos2_constraints_;
1241constexpr typename AtomicConstraintStorage<Sos2ConstraintData>::Diff
1242 ModelStorage::UpdateTrackerData::*
1243 ModelStorage::UpdateTrackerData::AtomicConstraintDirtyFieldPtr<
1245 return &UpdateTrackerData::dirty_sos2_constraints;
1251inline AtomicConstraintStorage<IndicatorConstraintData>&
1252ModelStorage::constraint_storage() {
1253 return indicator_constraints_;
1257inline const AtomicConstraintStorage<IndicatorConstraintData>&
1258ModelStorage::constraint_storage()
const {
1259 return indicator_constraints_;
1263constexpr typename AtomicConstraintStorage<IndicatorConstraintData>::Diff
1264 ModelStorage::UpdateTrackerData::*
1265 ModelStorage::UpdateTrackerData::AtomicConstraintDirtyFieldPtr<
1266 IndicatorConstraintData>() {
1267 return &UpdateTrackerData::dirty_indicator_constraints;
const std::string name
A name for logging purposes.
absl::Span< const double > coefficients
internal::SosConstraintData< Sos1ConstraintId > Sos1ConstraintData
auto MakeUpdateDataFieldRange(const UpdateTrackers &trackers)
internal::SosConstraintData< Sos2ConstraintId > Sos2ConstraintData
In SWIG mode, we don't want anything besides these top-level includes.