Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
solution_feasibility_checker.h
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#ifndef OR_TOOLS_MATH_OPT_LABS_SOLUTION_FEASIBILITY_CHECKER_H_
15#define OR_TOOLS_MATH_OPT_LABS_SOLUTION_FEASIBILITY_CHECKER_H_
16
17#include <string>
18#include <vector>
19
20#include "absl/status/statusor.h"
22
24
26 // Used for evaluating the feasibility of primal solution values with respect
27 // to linear constraints and variable bounds.
28 //
29 // For example, variable values x are considered feasible with respect to a
30 // constraint <a, x> ≤ b iff <a, x> ≤ b + absolute_constraint_tolerance.
31 //
32 // Cannot be negative or NaN.
34
35 // An absolute tolerance used for evaluating the feasibility of a variable's
36 // value with respect to integrality constraints on that variable, if present.
37 //
38 // For example, a value x for an integer variable is considered feasible with
39 // respect to its integrality constraints iff
40 // |x - round(x)| ≤ integrality_tolerance.
41 //
42 // Cannot be negative or NaN.
43 double integrality_tolerance = 1.0e-5;
44
45 // Absolute tolerance for evaluating if an expression is sufficiently close to
46 // a particular value (usually zero, hence the name).
47 //
48 // This is used for evaluating if SOS1 and SOS2 constraints are satisfied, as
49 // well as for evaluating indicator constraint feasibility (i.e., is the
50 // indicator variable at its "activation value").
51 //
52 // For example, variable values x are considered feasible with respect to an
53 // SOS1 constraint {expr_1(x), ..., expr_d(x)}-is-SOS1 iff there is at most
54 // one j such that |expr_j(x)| > nonzero_tolerance.
55 //
56 // Cannot be negative or NaN.
57 double nonzero_tolerance = 1.0e-5;
58};
59
60// Returns a subset of `model`s constraints that are violated at the point in
61// `variable_values`. A point feasible with respect to all constraints will
62// return an empty subset, which can be checked via ModelSubset::empty().
63//
64// Feasibility is checked within tolerances that can be configured in `options`.
65//
66// Returns an InvalidArgument error if `variable_values` does not contain an
67// entry for each variable in `model` (and no extras).
68absl::StatusOr<ModelSubset> CheckPrimalSolutionFeasibility(
69 const Model& model, const VariableMap<double>& variable_values,
70 const FeasibilityCheckerOptions& options = {});
71
72// Returns a collection of strings that provide a human-readable representation
73// of the `violated_constraints` (one string for each violated constraint).
74// Useful for logging.
75//
76// Returns an InvalidArgument error if `variable_values` does not contain an
77// entry for each variable in `model` (and no extras).
78absl::StatusOr<std::vector<std::string>> ViolatedConstraintsAsStrings(
79 const Model& model, const ModelSubset& violated_constraints,
80 const VariableMap<double>& variable_values);
81
82} // namespace operations_research::math_opt
83
84#endif // OR_TOOLS_MATH_OPT_LABS_SOLUTION_FEASIBILITY_CHECKER_H_
GRBmodel * model
An object oriented wrapper for quadratic constraints in ModelStorage.
Definition gurobi_isv.cc:28
absl::flat_hash_map< Variable, V > VariableMap
absl::StatusOr< std::vector< std::string > > ViolatedConstraintsAsStrings(const Model &model, const ModelSubset &violated_constraints, const VariableMap< double > &variable_values)
absl::StatusOr< ModelSubset > CheckPrimalSolutionFeasibility(const Model &model, const VariableMap< double > &variable_values, const FeasibilityCheckerOptions &options)