14#ifndef OR_TOOLS_MATH_OPT_CONSTRAINTS_UTIL_MODEL_UTIL_H_
15#define OR_TOOLS_MATH_OPT_CONSTRAINTS_UTIL_MODEL_UTIL_H_
19#include "absl/algorithm/container.h"
20#include "absl/strings/string_view.h"
31 "[constraint deleted from model]";
41template <
typename IdType>
43 const ModelStorage& storage,
const IdType
id) {
44 const std::vector<VariableId> raw_vars =
45 storage.constraint_data(
id).RelatedVariables();
46 std::vector<Variable> vars;
47 vars.reserve(raw_vars.size());
48 for (
const VariableId raw_var : raw_vars) {
49 vars.push_back(
Variable(&storage, raw_var));
56template <
typename Constra
intType>
58 using IdType =
typename ConstraintType::IdType;
59 std::vector<ConstraintType> result;
60 result.reserve(storage.num_constraints<IdType>());
61 for (
const IdType con_id : storage.Constraints<IdType>()) {
62 result.push_back(ConstraintType(&storage, con_id));
68template <
typename Constra
intType>
70 const ModelStorage& storage) {
71 std::vector<ConstraintType> constraints =
73 absl::c_sort(constraints,
74 [](
const ConstraintType& l,
const ConstraintType& r) {
75 return l.typed_id() < r.typed_id();
An object oriented wrapper for quadratic constraints in ModelStorage.
std::vector< ConstraintType > AtomicConstraints(const ModelStorage &storage)
constexpr absl::string_view kDeletedConstraintDefaultDescription
std::vector< ConstraintType > SortedAtomicConstraints(const ModelStorage &storage)
LinearExpression ToLinearExpression(const ModelStorage &storage, const LinearExpressionData &expr_data)
std::vector< Variable > AtomicConstraintNonzeroVariables(const ModelStorage &storage, const IdType id)
LinearExpressionData FromLinearExpression(const LinearExpression &expression)
Converts a LinearExpression to the associated "raw ID" format.