OR-Tools  9.2
model_solve_parameters.h
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 
14 #ifndef OR_TOOLS_MATH_OPT_CPP_MODEL_SOLVE_PARAMETERS_H_
15 #define OR_TOOLS_MATH_OPT_CPP_MODEL_SOLVE_PARAMETERS_H_
16 
17 #include <initializer_list>
18 #include <optional>
19 
22 #include "ortools/math_opt/cpp/map_filter.h" // IWYU pragma: export
25 #include "ortools/math_opt/model_parameters.pb.h"
26 
27 namespace operations_research {
28 namespace math_opt {
29 
30 // Parameters to control a single solve that that are specific to the input
31 // model (see SolveParametersProto for model independent parameters).
33  // Returns the parameters that empty Result::DualSolution and Result::DualRay,
34  // only keep the values of all variables in Result::PrimalSolution and
35  // Result::PrimalRay.
36  //
37  // This is a shortcut method that is equivalent to setting the dual filters
38  // with MakeSkipAllFilter().
40 
41  // Returns the parameters that empty Result::DualSolution and Result::DualRay,
42  // only keep the values of the specified variables in Result::PrimalSolution
43  // and Result::PrimalRay.
44  //
45  // The input Collection must be usable in a for-range loop with Variable
46  // values. This will be typically a std::vector<Variable> or and
47  // std::initializer_list<Variable> (see the other overload).
48  //
49  // This is a shortcut method that is equivalent to setting the dual filters
50  // with MakeSkipAllFilter() and the primal_variables_filter with
51  // MakeKeepKeysFilter(variables).
52  //
53  // Example:
54  // std::vector<Variable> decision_vars = ...;
55  // const auto params =
56  // ModelSolveParameters::OnlySomePrimalVariables(decision_vars);
57  template <typename Collection>
59  const Collection& variables);
60 
61  // Returns the parameters that empty Result::DualSolution and Result::DualRay,
62  // only keeping the values of the specified variables in
63  // Result::PrimalSolution and Result::PrimalRay.
64  //
65  // See the other overload's documentation for details. This overload is needed
66  // since C++ can't guess the type when using an initializer list expression.
67  //
68  // Example:
69  // const Variable a = ...;
70  // const Variable b = ...;
71  // const auto params =
72  // ModelSolveParameters::OnlySomePrimalVariables({a, b});
74  std::initializer_list<Variable> variables);
75 
76  // The filter that is applied to variable_values of both
77  // Result::PrimalSolution and Result::PrimalRay.
79 
80  // The filter that is applied to dual_values of Result::DualSolution and
81  // Result::DualRay.
83 
84  // The filter that is applied to reduced_costs of Result::DualSolution and
85  // Result::DualRay.
87 
88  // Optional initial basis for warm starting simplex LP solvers. If set, it is
89  // expected to be valid.
90  absl::optional<Result::Basis> initial_basis;
91 
92  // Returns the model of filtered keys. It returns a non-null value if and only
93  // if one of the filters have a set and non empty filtered_keys().
94  //
95  // Asserts (using CHECK) that all variables and linear constraints referenced
96  // by the filters are in the same model.
97  IndexedModel* model() const;
98 
99  // Returns a new proto corresponding to these parameters.
100  //
101  // Asserts (using CHECK) that all variables and linear constraints referenced
102  // by the filters are in the same model.
103  ModelSolveParametersProto Proto() const;
104 };
105 
107 // Inline functions implementations.
109 
110 template <typename Collection>
112  const Collection& variables) {
114  parameters.primal_variables_filter = MakeKeepKeysFilter(variables);
115  return parameters;
116 }
117 
118 } // namespace math_opt
119 } // namespace operations_research
120 
121 #endif // OR_TOOLS_MATH_OPT_CPP_MODEL_SOLVE_PARAMETERS_H_
MapFilter< ValueType > MakeKeepKeysFilter(const Collection &keys)
Definition: map_filter.h:133
static ModelSolveParameters OnlySomePrimalVariables(const Collection &variables)
Collection of objects used to extend the Constraint Solver library.
SatParameters parameters