OR-Tools  9.0
model_parameters_validator.cc
Go to the documentation of this file.
1 // Copyright 2010-2021 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 <stdint.h>
17 
18 #include <string>
19 
21 #include "absl/status/status.h"
22 #include "absl/strings/str_cat.h"
23 #include "ortools/math_opt/model_parameters.pb.h"
25 #include "ortools/math_opt/sparse_containers.pb.h"
29 
30 namespace operations_research {
31 namespace math_opt {
32 
33 absl::Status ValidateSparseVectorFilter(const SparseVectorFilterProto& v,
34  const IdNameBiMap& valid_ids) {
37  CheckIdsSubset(v.filtered_ids(), valid_ids, "filtered_ids", "model IDs"));
38  if (!v.filter_by_ids() && !v.filtered_ids().empty()) {
39  return absl::InvalidArgumentError(
40  "Invalid SparseVectorFilterProto.filter_by_id* specification. To "
41  "filter by "
42  "IDs you must set SparseVectorFilterProto.filter_by_ids to 'true'.");
43  }
44 
45  return absl::OkStatus();
46 }
47 
49  const ModelSolveParametersProto& parameters,
50  const ModelSummary& model_summary) {
52  parameters.primal_variables_filter(), model_summary.variables))
53  << "invalid primal_variables_filter";
55  model_summary.variables))
56  << "invalid dual_variables_filter";
58  ValidateSparseVectorFilter(parameters.dual_linear_constraints_filter(),
59  model_summary.linear_constraints))
60  << "invalid dual_linear_constraints_filter";
61  if (parameters.has_initial_basis()) {
62  RETURN_IF_ERROR(ValidateBasis(parameters.initial_basis(), model_summary));
63  }
64 
65  return absl::OkStatus();
66 }
67 
68 } // namespace math_opt
69 } // namespace operations_research
SatParameters parameters
absl::Status CheckIdsNonnegativeAndStrictlyIncreasing(absl::Span< const int64_t > ids)
absl::Status ValidateSparseVectorFilter(const SparseVectorFilterProto &v, const IdNameBiMap &valid_ids)
absl::Status CheckIdsSubset(absl::Span< const int64_t > ids, const IdNameBiMap &universe, absl::string_view ids_description, absl::string_view universe_description)
absl::Status ValidateBasis(const BasisProto &basis, const ModelSummary &model_summary)
absl::Status ValidateModelSolveParameters(const ModelSolveParametersProto &parameters, const ModelSummary &model_summary)
Collection of objects used to extend the Constraint Solver library.
#define RETURN_IF_ERROR(expr)
Definition: status_macros.h:29