OR-Tools  9.6
model_solve_parameters.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 // IWYU pragma: private, include "ortools/math_opt/cpp/math_opt.h"
15 // IWYU pragma: friend "ortools/math_opt/cpp/.*"
16 
17 #ifndef OR_TOOLS_MATH_OPT_CPP_MODEL_SOLVE_PARAMETERS_H_
18 #define OR_TOOLS_MATH_OPT_CPP_MODEL_SOLVE_PARAMETERS_H_
19 
20 #include <sys/types.h>
21 
22 #include <initializer_list>
23 #include <optional>
24 #include <vector>
25 
26 #include "absl/status/status.h"
28 #include "ortools/math_opt/cpp/map_filter.h" // IWYU pragma: export
31 #include "ortools/math_opt/model_parameters.pb.h"
33 
34 namespace operations_research {
35 namespace math_opt {
36 
37 // Parameters to control a single solve that are specific to the input
38 // model (see SolveParametersProto for model independent parameters).
40  // Returns the parameters that empty DualSolution and DualRay, only keep the
41  // values of all variables in PrimalSolution and PrimalRay.
42  //
43  // This is a shortcut method that is equivalent to setting the dual filters
44  // with MakeSkipAllFilter().
46 
47  // Returns the parameters that empty DualSolution and DualRay, only keep the
48  // values of the specified variables in PrimalSolution and PrimalRay.
49  //
50  // The input Collection must be usable in a for-range loop with Variable
51  // values. This will be typically a std::vector<Variable> or and
52  // std::initializer_list<Variable> (see the other overload).
53  //
54  // This is a shortcut method that is equivalent to setting the dual filters
55  // with MakeSkipAllFilter() and the variable_values_filter with
56  // MakeKeepKeysFilter(variables).
57  //
58  // Example:
59  // std::vector<Variable> decision_vars = ...;
60  // const auto params =
61  // ModelSolveParameters::OnlySomePrimalVariables(decision_vars);
62  template <typename Collection>
64  const Collection& variables);
65 
66  // Returns the parameters that empty DualSolution and DualRay, only keeping
67  // the values of the specified variables in PrimalSolution and PrimalRay.
68  //
69  // See the other overload's documentation for details. This overload is needed
70  // since C++ can't guess the type when using an initializer list expression.
71  //
72  // Example:
73  // const Variable a = ...;
74  // const Variable b = ...;
75  // const auto params =
76  // ModelSolveParameters::OnlySomePrimalVariables({a, b});
78  std::initializer_list<Variable> variables);
79 
80  // The filter that is applied to variable_values of both PrimalSolution and
81  // PrimalRay.
83 
84  // The filter that is applied to dual_values of DualSolution and DualRay.
86 
87  // The filter that is applied to reduced_costs of DualSolution and DualRay.
89 
90  // Optional initial basis for warm starting simplex LP solvers. If set, it is
91  // expected to be valid.
92  std::optional<Basis> initial_basis;
93 
94  // A solution hint. It can be partial and does not need to be feasible; see
95  // solution_hints for details.
96  struct SolutionHint {
98  };
99 
100  // Optional solution hints. If set, they are expected to consist of
101  // assignments of finite values to primal or dual variables in the model (some
102  // variables may lack assignments and the assignment does not necessarily have
103  // to lead to a feasible solution).
104  std::vector<SolutionHint> solution_hints;
105 
106  // Optional branching priorities. Variables with higher values will be
107  // branched on first. Variables for which priorities are not set get the
108  // solver's default priority (usualy zero). If set, they are expected to
109  // consist of finite priorities for primal variables in the model.
111 
112  // Returns a failure if the referenced variables don't belong to the input
113  // expected_storage (which must not be nullptr).
114  absl::Status CheckModelStorage(const ModelStorage* expected_storage) const;
115 
116  // Returns the proto equivalent of this object.
117  //
118  // The caller should use CheckModelStorage() as this function does not check
119  // internal consistency of the referenced variables and constraints.
120  ModelSolveParametersProto Proto() const;
121 };
122 
124 // Inline functions implementations.
126 
127 template <typename Collection>
129  const Collection& variables) {
131  parameters.variable_values_filter = MakeKeepKeysFilter(variables);
132  return parameters;
133 }
134 
135 } // namespace math_opt
136 } // namespace operations_research
137 
138 #endif // OR_TOOLS_MATH_OPT_CPP_MODEL_SOLVE_PARAMETERS_H_
SatParameters parameters
MapFilter< ValueType > MakeKeepKeysFilter(const Collection &keys)
Definition: map_filter.h:135
Collection of objects used to extend the Constraint Solver library.
static ModelSolveParameters OnlySomePrimalVariables(const Collection &variables)
absl::Status CheckModelStorage(const ModelStorage *expected_storage) const