20#include "absl/container/flat_hash_set.h"
23#include "ortools/math_opt/model.pb.h"
24#include "ortools/math_opt/sparse_containers.pb.h"
34 data.
name = in_proto.name();
36 if (in_proto.has_indicator_id()) {
37 data.
indicator = VariableId(in_proto.indicator_id());
39 for (
int i = 0; i < in_proto.expression().ids_size(); ++i) {
41 in_proto.expression().values(i));
51 constraint.set_name(
name);
54 constraint.set_indicator_id(
indicator->value());
57 constraint.mutable_expression()->add_ids(
var.value());
64 absl::flat_hash_set<VariableId> vars;
71 return std::vector<VariableId>(vars.begin(), vars.end());
bool set(VariableId id, double coeff)
Returns true if the stored value changes.
const absl::flat_hash_map< VariableId, double > & terms() const
double get(VariableId id) const
Returns 0.0 by default if no value is set.
void erase(VariableId id)
Has no effect if id is not set.
An object oriented wrapper for quadratic constraints in ModelStorage.
std::vector< K > SortedMapKeys(const absl::flat_hash_map< K, V > &in_map)
SparseCoefficientMap linear_terms
IndicatorConstraintProto ProtoType
std::optional< VariableId > indicator
static IndicatorConstraintData FromProto(const ProtoType &in_proto)
std::vector< VariableId > RelatedVariables() const
void DeleteVariable(VariableId var)