C++ Reference

C++ Reference: Linear solver

model_validator.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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 #ifndef OR_TOOLS_LINEAR_SOLVER_MODEL_VALIDATOR_H_
15 #define OR_TOOLS_LINEAR_SOLVER_MODEL_VALIDATOR_H_
16 
17 #include <optional>
18 #include <string>
19 
20 #include "absl/types/optional.h"
21 #include "ortools/linear_solver/linear_solver.pb.h"
22 #include "ortools/util/lazy_mutable_copy.h"
23 
24 namespace operations_research {
39  const MPModelProto& model, double abs_value_threshold = 0.0,
40  // If false, variable and constraint bounds like [lb=1.2, ub=0.7] yield an
41  // error, and also integer variable bounds like [0.7, 0.8].
42  bool accept_trivially_infeasible_bounds = false);
43 
50 std::string FindErrorInMPModelDeltaProto(const MPModelDeltaProto& delta,
51  const MPModelProto& model);
52 
57 std::optional<LazyMutableCopy<MPModelProto>>
58 ExtractValidMPModelOrPopulateResponseStatus(const MPModelRequest& request,
59  MPSolutionResponse* response);
60 
67  MPModelRequest* request, MPSolutionResponse* response);
68 
79 std::string FindFeasibilityErrorInSolutionHint(const MPModelProto& model,
80  double tolerance);
81 
82 // Partially merges a MPConstraintProto onto another, skipping only the
83 // repeated fields "var_index" and "coefficients". This is used within
84 // FindErrorInMPModelDeltaProto.
85 // See the unit test MergeMPConstraintProtoExceptTermsTest that explains why we
86 // need this.
87 void MergeMPConstraintProtoExceptTerms(const MPConstraintProto& from,
88  MPConstraintProto* to);
89 
90 // Applies the given model_delta to "model". Assumes that
91 // FindErrorInMPModelDeltaProto() found no error. For full error checking,
92 // please use ExtractValidMPModelOrPopulateResponseStatus() instead.
93 void ApplyVerifiedMPModelDelta(const MPModelDeltaProto& delta,
94  MPModelProto* model);
95 
96 } // namespace operations_research
97 
98 #endif // OR_TOOLS_LINEAR_SOLVER_MODEL_VALIDATOR_H_
std::string FindErrorInMPModelDeltaProto(const MPModelDeltaProto &delta, const MPModelProto &model)
Like FindErrorInMPModelProto, but for a MPModelDeltaProto applied to a given baseline model (assumed ...
void ApplyVerifiedMPModelDelta(const MPModelDeltaProto &delta, MPModelProto *model)
bool ExtractValidMPModelInPlaceOrPopulateResponseStatus(MPModelRequest *request, MPSolutionResponse *response)
Like ExtractValidMPModelOrPopulateResponseStatus(), but works in-place: if the MPModel needed extract...
std::optional< LazyMutableCopy< MPModelProto > > ExtractValidMPModelOrPopulateResponseStatus(const MPModelRequest &request, MPSolutionResponse *response)
If the model is valid and non-empty, returns it (possibly after extracting the model_delta).
std::string FindErrorInMPModelProto(const MPModelProto &model, double abs_value_threshold=0.0, bool accept_trivially_infeasible_bounds=false)
Returns an empty string iff the model is valid and not trivially infeasible.
std::string FindFeasibilityErrorInSolutionHint(const MPModelProto &model, double tolerance)
Returns an empty string if the solution hint given in the model is a feasible solution.
void MergeMPConstraintProtoExceptTerms(const MPConstraintProto &from, MPConstraintProto *to)