Google OR-Tools
v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
linear_expression_validator.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/validators/linear_expression_validator.h
"
15
16
#include <cstdint>
17
18
#include "absl/status/status.h"
19
#include "
ortools/base/status_macros.h
"
20
#include "
ortools/math_opt/core/model_summary.h
"
21
#include "
ortools/math_opt/core/sparse_vector_view.h
"
22
#include "
ortools/math_opt/sparse_containers.pb.h
"
23
#include "
ortools/math_opt/validators/scalar_validator.h
"
24
#include "
ortools/math_opt/validators/sparse_vector_validator.h
"
25
26
namespace
operations_research::math_opt
{
27
28
absl::Status
ValidateLinearExpression
(
const
LinearExpressionProto
& expression,
29
const
IdNameBiMap
& variable_universe) {
30
RETURN_IF_ERROR
(
CheckIdsAndValues
(
31
MakeView
(expression.
ids
(), expression.
coefficients
()),
32
{.allow_positive_infinity = false, .allow_negative_infinity = false}))
33
<<
"invalid linear expression terms"
;
34
for
(
const
int64_t var_id : expression.
ids
()) {
35
if
(!variable_universe.
HasId
(var_id)) {
36
return
util::InvalidArgumentErrorBuilder
()
37
<<
"invalid variable id: "
<< var_id;
38
}
39
}
40
RETURN_IF_ERROR
(
CheckScalarNoNanNoInf
(expression.
offset
()))
41
<<
"invalid linear expression offset"
;
42
return
absl::OkStatus();
43
}
44
45
}
// namespace operations_research::math_opt
status_macros.h
RETURN_IF_ERROR
#define RETURN_IF_ERROR(expr)
Definition
status_macros.h:27
operations_research::math_opt::IdNameBiMap
Definition
model_summary.h:50
operations_research::math_opt::IdNameBiMap::HasId
bool HasId(int64_t id) const
Definition
model_summary.h:196
operations_research::math_opt::LinearExpressionProto
Definition
sparse_containers.pb.h:1225
operations_research::math_opt::LinearExpressionProto::coefficients
double coefficients(int index) const
Definition
sparse_containers.pb.h:2111
operations_research::math_opt::LinearExpressionProto::ids
::int64_t ids(int index) const
Definition
sparse_containers.pb.h:2061
operations_research::math_opt::LinearExpressionProto::offset
double offset() const
Definition
sparse_containers.pb.h:2155
linear_expression_validator.h
model_summary.h
operations_research::math_opt
Definition
gurobi_isv.cc:28
operations_research::math_opt::MakeView
SparseVectorView< T > MakeView(absl::Span< const int64_t > ids, const Collection &values)
Definition
sparse_vector_view.h:148
operations_research::math_opt::CheckIdsAndValues
absl::Status CheckIdsAndValues(const SparseVectorView< T > &vector_view, absl::string_view value_name="values")
Definition
sparse_vector_validator.h:50
operations_research::math_opt::CheckScalarNoNanNoInf
absl::Status CheckScalarNoNanNoInf(const double d)
Definition
scalar_validator.cc:28
operations_research::math_opt::ValidateLinearExpression
absl::Status ValidateLinearExpression(const LinearExpressionProto &expression, const IdNameBiMap &variable_universe)
Definition
linear_expression_validator.cc:28
util::InvalidArgumentErrorBuilder
StatusBuilder InvalidArgumentErrorBuilder()
Definition
status_builder.h:107
scalar_validator.h
sparse_containers.pb.h
sparse_vector_validator.h
sparse_vector_view.h
ortools
math_opt
validators
linear_expression_validator.cc
Generated by
1.15.0