Google OR-Tools
v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
quadratic_constraint.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
14
#include "
ortools/math_opt/constraints/quadratic/quadratic_constraint.h
"
15
16
#include <utility>
17
18
#include "
ortools/base/strong_int.h
"
19
#include "
ortools/math_opt/cpp/variable_and_expressions.h
"
20
#include "
ortools/math_opt/storage/model_storage.h
"
21
#include "
ortools/math_opt/storage/sparse_coefficient_map.h
"
22
#include "
ortools/math_opt/storage/sparse_matrix.h
"
23
24
namespace
operations_research::math_opt
{
25
26
BoundedQuadraticExpression
QuadraticConstraint::AsBoundedQuadraticExpression
()
27
const
{
28
QuadraticExpression
expression;
29
const
QuadraticConstraintData
& data =
storage
()->constraint_data(id_);
30
for
(
const
auto
[
var
, coeff] : data.
linear_terms
.
terms
()) {
31
expression += coeff *
Variable
(
storage
(),
var
);
32
}
33
for
(
const
auto
& [first_var, second_var, coeff] :
34
data.
quadratic_terms
.
Terms
()) {
35
expression += coeff *
Variable
(
storage
(), first_var) *
36
Variable
(
storage
(), second_var);
37
}
38
return
data.
lower_bound
<= std::move(expression) <= data.
upper_bound
;
39
}
40
41
}
// namespace operations_research::math_opt
operations_research::math_opt::QuadraticConstraint::storage
const ModelStorage * storage() const
Definition
quadratic_constraint.h:122
operations_research::math_opt::QuadraticConstraint::AsBoundedQuadraticExpression
BoundedQuadraticExpression AsBoundedQuadraticExpression() const
Definition
quadratic_constraint.cc:26
operations_research::math_opt::QuadraticExpression
Definition
variable_and_expressions.h:747
operations_research::math_opt::SparseCoefficientMap::terms
const absl::flat_hash_map< VariableId, double > & terms() const
Definition
sparse_coefficient_map.h:46
operations_research::math_opt::SparseSymmetricMatrix::Terms
std::vector< std::pair< VariableId, double > > Terms(VariableId variable) const
Definition
sparse_matrix.cc:76
operations_research::math_opt::Variable
Definition
variable_and_expressions.h:124
var
IntVar * var
Definition
expr_array.cc:1876
model_storage.h
operations_research::math_opt
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition
gurobi_isv.cc:28
quadratic_constraint.h
sparse_coefficient_map.h
sparse_matrix.h
strong_int.h
operations_research::math_opt::BoundedQuadraticExpression
A QuadraticExpression with upper and lower bounds.
Definition
variable_and_expressions.h:1091
operations_research::math_opt::QuadraticConstraintData
Definition
storage.h:34
operations_research::math_opt::QuadraticConstraintData::quadratic_terms
SparseSymmetricMatrix quadratic_terms
Definition
storage.h:49
operations_research::math_opt::QuadraticConstraintData::linear_terms
SparseCoefficientMap linear_terms
Definition
storage.h:48
operations_research::math_opt::QuadraticConstraintData::lower_bound
double lower_bound
Definition
storage.h:46
operations_research::math_opt::QuadraticConstraintData::upper_bound
double upper_bound
Definition
storage.h:47
variable_and_expressions.h
ortools
math_opt
constraints
quadratic
quadratic_constraint.cc
Generated by
1.12.0