Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
storage.cc
Go to the documentation of this file.
1// Copyright 2010-2024 Google LLC
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
15
16#include <cstdint>
17#include <string>
18#include <vector>
19
20#include "absl/container/flat_hash_set.h"
22#include "ortools/math_opt/sparse_containers.pb.h"
26
28
30 const ProtoType& in_proto) {
32 data.upper_bound = LinearExpressionData::FromProto(in_proto.upper_bound());
33 data.arguments_to_norm.reserve(in_proto.arguments_to_norm_size());
34 for (const LinearExpressionProto& expr_proto : in_proto.arguments_to_norm()) {
35 data.arguments_to_norm.push_back(
37 }
38 data.name = in_proto.name();
39 return data;
40}
41
44 ProtoType constraint;
45 *constraint.mutable_upper_bound() = upper_bound.Proto();
46 for (const LinearExpressionData& expr : arguments_to_norm) {
47 *constraint.add_arguments_to_norm() = expr.Proto();
48 }
49 constraint.set_name(name);
50 return constraint;
51}
52
54 const {
55 absl::flat_hash_set<VariableId> vars;
56 for (const auto& [var, unused] : upper_bound.coeffs.terms()) {
57 vars.insert(var);
58 }
59 for (const LinearExpressionData& expr : arguments_to_norm) {
60 for (const auto& [var, unused] : expr.coeffs.terms()) {
61 vars.insert(var);
62 }
63 }
64 return std::vector<VariableId>(vars.begin(), vars.end());
65}
66
70 expr.coeffs.set(var, 0.0);
71 }
72}
73
74} // namespace operations_research::math_opt
bool set(VariableId id, double coeff)
Returns true if the stored value changes.
const absl::flat_hash_map< VariableId, double > & terms() const
IntVar * var
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
static LinearExpressionData FromProto(const LinearExpressionProto &expr_proto)
LinearExpressionProto Proto() const
Inline implementations.
std::vector< LinearExpressionData > arguments_to_norm
Definition storage.h:46
static SecondOrderConeConstraintData FromProto(const ProtoType &in_proto)
Definition storage.cc:29
std::vector< VariableId > RelatedVariables() const
Definition storage.cc:53