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 <sys/types.h>
18
19#include <initializer_list>
20#include <optional>
21#include <vector>
22
25#include "ortools/math_opt/cpp/map_filter.h" // IWYU pragma: export
28#include "ortools/math_opt/model_parameters.pb.h"
29
30namespace operations_research {
31namespace math_opt {
32
33// Parameters to control a single solve that that are specific to the input
34// model (see SolveParametersProto for model independent parameters).
36 // Returns the parameters that empty DualSolution and DualRay, only keep the
37 // values of all variables in PrimalSolution and PrimalRay.
38 //
39 // This is a shortcut method that is equivalent to setting the dual filters
40 // with MakeSkipAllFilter().
42
43 // Returns the parameters that empty DualSolution and DualRay, only keep the
44 // values of the specified variables in PrimalSolution and PrimalRay.
45 //
46 // The input Collection must be usable in a for-range loop with Variable
47 // values. This will be typically a std::vector<Variable> or and
48 // std::initializer_list<Variable> (see the other overload).
49 //
50 // This is a shortcut method that is equivalent to setting the dual filters
51 // with MakeSkipAllFilter() and the variable_values_filter with
52 // MakeKeepKeysFilter(variables).
53 //
54 // Example:
55 // std::vector<Variable> decision_vars = ...;
56 // const auto params =
57 // ModelSolveParameters::OnlySomePrimalVariables(decision_vars);
58 template <typename Collection>
60 const Collection& variables);
61
62 // Returns the parameters that empty DualSolution and DualRay, only keeping
63 // the values of the specified variables in PrimalSolution and 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 PrimalSolution and
77 // PrimalRay.
79
80 // The filter that is applied to dual_values of DualSolution and DualRay.
82
83 // The filter that is applied to reduced_costs of DualSolution and DualRay.
85
86 // Optional initial basis for warm starting simplex LP solvers. If set, it is
87 // expected to be valid.
88 std::optional<Basis> initial_basis;
89
90 struct SolutionHint {
91 SolutionHint() = default;
93 };
94
95 // Optional solution hints. If set, they are expected to consist of
96 // assignments of finite values to primal or dual variables in the model (some
97 // variables may lack assignments and the assignment does not necessarily have
98 // to lead to a feasible solution).
99 std::vector<SolutionHint> solution_hints;
100
101 // Optional branching priorities. Variables with higher values will be
102 // branched on first. Variables for which priorities are not set get the
103 // solver's default priority (usualy zero). If set, they are expected to
104 // consist of finite priorities for primal variables in the model.
106
107 // Returns the model of filtered keys. It returns a non-null value if and only
108 // if one of the filters have a set and non empty filtered_keys().
109 //
110 // Asserts (using CHECK) that all variables and linear constraints referenced
111 // by the filters are in the same model.
112 const ModelStorage* storage() const;
113
114 // Returns a new proto corresponding to these parameters.
115 //
116 // Asserts (using CHECK) that all variables and linear constraints referenced
117 // by the filters are in the same model.
118 ModelSolveParametersProto Proto() const;
119};
120
122// Inline functions implementations.
124
125template <typename Collection>
127 const Collection& variables) {
129 parameters.variable_values_filter = MakeKeepKeysFilter(variables);
130 return parameters;
131}
132
133} // namespace math_opt
134} // namespace operations_research
135
136#endif // OR_TOOLS_MATH_OPT_CPP_MODEL_SOLVE_PARAMETERS_H_
SatParameters parameters
MapFilter< ValueType > MakeKeepKeysFilter(const Collection &keys)
Definition: map_filter.h:133
Collection of objects used to extend the Constraint Solver library.
static ModelSolveParameters OnlySomePrimalVariables(const Collection &variables)