Google OR-Tools
v9.12
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-2025 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
14
#include "
ortools/math_opt/constraints/second_order_cone/storage.h
"
15
16
#include <cstdint>
17
#include <string>
18
#include <vector>
19
20
#include "absl/container/flat_hash_set.h"
21
#include "
ortools/base/strong_int.h
"
22
#include "ortools/math_opt/sparse_containers.pb.h"
23
#include "
ortools/math_opt/storage/linear_expression_data.h
"
24
#include "
ortools/math_opt/storage/model_storage_types.h
"
25
#include "
ortools/math_opt/storage/sparse_coefficient_map.h
"
26
27
namespace
operations_research::math_opt
{
28
29
SecondOrderConeConstraintData
SecondOrderConeConstraintData::FromProto
(
30
const
ProtoType
& in_proto) {
31
SecondOrderConeConstraintData
data;
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(
36
LinearExpressionData::FromProto
(expr_proto));
37
}
38
data.
name
= in_proto.name();
39
return
data;
40
}
41
42
typename
SecondOrderConeConstraintData::ProtoType
43
SecondOrderConeConstraintData::Proto
()
const
{
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
53
std::vector<VariableId>
SecondOrderConeConstraintData::RelatedVariables
()
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
67
void
SecondOrderConeConstraintData::DeleteVariable
(
const
VariableId var) {
68
upper_bound
.coeffs.set(var, 0.0);
69
for
(
LinearExpressionData
& expr :
arguments_to_norm
) {
70
expr.coeffs.set(var, 0.0);
71
}
72
}
73
74
}
// namespace operations_research::math_opt
linear_expression_data.h
model_storage_types.h
operations_research::math_opt
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition
gurobi_isv.cc:28
storage.h
sparse_coefficient_map.h
strong_int.h
operations_research::math_opt::LinearExpressionData
Definition
linear_expression_data.h:29
operations_research::math_opt::LinearExpressionData::FromProto
static LinearExpressionData FromProto(const LinearExpressionProto &expr_proto)
Definition
linear_expression_data.h:56
operations_research::math_opt::SecondOrderConeConstraintData
Definition
storage.h:33
operations_research::math_opt::SecondOrderConeConstraintData::upper_bound
LinearExpressionData upper_bound
Definition
storage.h:45
operations_research::math_opt::SecondOrderConeConstraintData::arguments_to_norm
std::vector< LinearExpressionData > arguments_to_norm
Definition
storage.h:46
operations_research::math_opt::SecondOrderConeConstraintData::ProtoType
SecondOrderConeConstraintProto ProtoType
Definition
storage.h:35
operations_research::math_opt::SecondOrderConeConstraintData::FromProto
static SecondOrderConeConstraintData FromProto(const ProtoType &in_proto)
Definition
storage.cc:29
operations_research::math_opt::SecondOrderConeConstraintData::DeleteVariable
void DeleteVariable(VariableId var)
Definition
storage.cc:67
operations_research::math_opt::SecondOrderConeConstraintData::Proto
ProtoType Proto() const
Definition
storage.cc:43
operations_research::math_opt::SecondOrderConeConstraintData::name
std::string name
Definition
storage.h:47
operations_research::math_opt::SecondOrderConeConstraintData::RelatedVariables
std::vector< VariableId > RelatedVariables() const
Definition
storage.cc:53
ortools
math_opt
constraints
second_order_cone
storage.cc
Generated by
1.13.2