14#ifndef OR_TOOLS_MATH_OPT_STORAGE_LINEAR_EXPRESSION_DATA_H_
15#define OR_TOOLS_MATH_OPT_STORAGE_LINEAR_EXPRESSION_DATA_H_
17#include "absl/container/flat_hash_map.h"
19#include "ortools/math_opt/sparse_containers.pb.h"
30 inline LinearExpressionProto
Proto()
const;
34 const LinearExpressionProto& expr_proto);
42 LinearExpressionProto proto_expr;
43 proto_expr.set_offset(
offset);
46 proto_expr.mutable_ids()->Reserve(num_terms);
47 proto_expr.mutable_coefficients()->Reserve(num_terms);
50 proto_expr.add_ids(
id.
value());
51 proto_expr.add_coefficients(
coeffs.
get(
id));
57 const LinearExpressionProto& expr_proto) {
59 for (
int i = 0; i < expr_proto.ids_size(); ++i) {
60 expr_data.coeffs.set(VariableId(expr_proto.ids(i)),
61 expr_proto.coefficients(i));
const absl::flat_hash_map< VariableId, double > & terms() const
double get(VariableId id) const
Returns 0.0 by default if no value is set.
An object oriented wrapper for quadratic constraints in ModelStorage.
std::vector< K > SortedMapKeys(const absl::flat_hash_map< K, V > &in_map)
static LinearExpressionData FromProto(const LinearExpressionProto &expr_proto)
LinearExpressionProto Proto() const
Inline implementations.
SparseCoefficientMap coeffs