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
6// http://www.apache.org/licenses/LICENSE-2.0
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.
14// Configures the behavior of a MathOpt solver.
18package operations_research.service.v1.mathopt;
20import "google/protobuf/duration.proto";
22option java_multiple_files = true;
23option java_package = "com.google.ortools.service.v1.mathopt";
24option csharp_namespace = "Google.OrTools.Service";
26// The solvers supported by MathOpt.
28 SOLVER_TYPE_UNSPECIFIED = 0;
30 // Solving Constraint Integer Programs (SCIP) solver (third party).
32 // Supports LP, MIP, and nonconvex integer quadratic problems. No dual data
33 // for LPs is returned though. Prefer GLOP for LPs.
34 SOLVER_TYPE_GSCIP = 1;
36 // Gurobi solver (third party).
38 // Supports LP, MIP, and nonconvex integer quadratic problems. Generally the
39 // fastest option, but has special licensing.
40 SOLVER_TYPE_GUROBI = 2;
42 // Google's Glop solver.
44 // Supports LP with primal and dual simplex methods.
47 // Google's CP-SAT solver.
49 // Supports problems where all variables are integer and bounded (or implied
50 // to be after presolve). Experimental support to rescale and discretize
51 // problems with continuous variables.
52 SOLVER_TYPE_CP_SAT = 4;
54 // Google's PDLP solver.
56 // Supports LP and convex diagonal quadratic objectives. Uses first order
57 // methods rather than simplex. Can solve very large problems.
60 // GNU Linear Programming Kit (GLPK) (third party).
62 // Supports MIP and LP.
64 // Thread-safety: GLPK use thread-local storage for memory allocations. As a
65 // consequence Solver instances must be destroyed on the same thread as they
66 // are created or GLPK will crash. It seems OK to call Solver::Solve() from
67 // another thread than the one used to create the Solver but it is not
68 // documented by GLPK and should be avoided.
70 // When solving a LP with the presolver, a solution (and the unbound rays) are
71 // only returned if an optimal solution has been found. Else nothing is
72 // returned. See glpk-5.0/doc/glpk.pdf page #40 available from glpk-5.0.tar.gz
76 // The Operator Splitting Quadratic Program (OSQP) solver (third party).
78 // Supports continuous problems with linear constraints and linear or convex
79 // quadratic objectives. Uses a first-order method.
82 // The Embedded Conic Solver (ECOS) (third party).
84 // Supports LP and SOCP problems. Uses interior point methods (barrier).
87 // The Splitting Conic Solver (SCS) (third party).
89 // Supports LP and SOCP problems. Uses a first-order method.
92 // The HiGHS Solver (third party).
94 // Supports LP and MIP problems (convex QPs are unimplemented).
95 SOLVER_TYPE_HIGHS = 10;
97 // MathOpt's reference implementation of a MIP solver.
99 // Slow/not recommended for production. Not an LP solver (no dual information
101 SOLVER_TYPE_SANTORINI = 11;
104// Selects an algorithm for solving linear programs.
105enum LPAlgorithmProto {
106 LP_ALGORITHM_UNSPECIFIED = 0;
108 // The (primal) simplex method. Typically can provide primal and dual
109 // solutions, primal/dual rays on primal/dual unbounded problems, and a basis.
110 LP_ALGORITHM_PRIMAL_SIMPLEX = 1;
112 // The dual simplex method. Typically can provide primal and dual
113 // solutions, primal/dual rays on primal/dual unbounded problems, and a basis.
114 LP_ALGORITHM_DUAL_SIMPLEX = 2;
116 // The barrier method, also commonly called an interior point method (IPM).
117 // Can typically give both primal and dual solutions. Some implementations can
118 // also produce rays on unbounded/infeasible problems. A basis is not given
119 // unless the underlying solver does "crossover" and finishes with simplex.
120 LP_ALGORITHM_BARRIER = 3;
122 // An algorithm based around a first-order method. These will typically
123 // produce both primal and dual solutions, and potentially also certificates
124 // of primal and/or dual infeasibility. First-order methods typically will
125 // provide solutions with lower accuracy, so users should take care to set
126 // solution quality parameters (e.g., tolerances) and to validate solutions.
127 LP_ALGORITHM_FIRST_ORDER = 4;
130// Effort level applied to an optional task while solving (see
131// SolveParametersProto for use).
133// Emphasis is used to configure a solver feature as follows:
134// * If a solver doesn't support the feature, only UNSPECIFIED will always be
135// valid, any other setting will typically an invalid argument error (some
136// solvers may also accept OFF).
137// * If the solver supports the feature:
138// - When set to UNSPECIFIED, the underlying default is used.
139// - When the feature cannot be turned off, OFF will return an error.
140// - If the feature is enabled by default, the solver default is typically
142// - If the feature is supported, LOW, MEDIUM, HIGH, and VERY HIGH will never
143// give an error, and will map onto their best match.
145 EMPHASIS_UNSPECIFIED = 0;
150 EMPHASIS_VERY_HIGH = 5;
153// Parameters to control a single solve.
155// Contains both parameters common to all solvers e.g. time_limit, and
156// parameters for a specific solver, e.g. gscip. If a value is set in both
157// common and solver specific field, the solver specific setting is used.
159// The common parameters that are optional and unset or an enum with value
160// unspecified indicate that the solver default is used.
162// Solver specific parameters for solvers other than the one in use are ignored.
164// Parameters that depends on the model (e.g. branching priority is set for
165// each variable) are passed in ModelSolveParametersProto.
166message SolveParametersProto {
167 // Maximum time a solver should spend on the problem (or infinite if not set).
169 // This value is not a hard limit, solve time may slightly exceed this value.
170 // This parameter is always passed to the underlying solver, the solver
171 // default is not used.
172 google.protobuf.Duration time_limit = 1;
174 // Limit on the iterations of the underlying algorithm (e.g. simplex pivots).
175 // The specific behavior is dependent on the solver and algorithm used, but
176 // often can give a deterministic solve limit (further configuration may be
177 // needed, e.g. one thread).
179 // Typically supported by LP, QP, and MIP solvers, but for MIP solvers see
181 optional int64 iteration_limit = 2;
183 // Limit on the number of subproblems solved in enumerative search (e.g.
184 // branch and bound). For many solvers this can be used to deterministically
185 // limit computation (further configuration may be needed, e.g. one thread).
187 // Typically for MIP solvers, see also iteration_limit.
188 optional int64 node_limit = 24;
190 // The solver stops early if it can prove there are no primal solutions at
191 // least as good as cutoff.
193 // On an early stop, the solver returns termination reason NO_SOLUTION_FOUND
194 // and with limit CUTOFF and is not required to give any extra solution
195 // information. Has no effect on the return value if there is no early stop.
197 // It is recommended that you use a tolerance if you want solutions with
198 // objective exactly equal to cutoff to be returned.
200 // See the user guide for more details and a comparison with best_bound_limit.
201 optional double cutoff_limit = 20;
203 // The solver stops early as soon as it finds a solution at least this good,
204 // with termination reason FEASIBLE and limit OBJECTIVE.
205 optional double objective_limit = 21;
207 // The solver stops early as soon as it proves the best bound is at least this
208 // good, with termination reason FEASIBLE or NO_SOLUTION_FOUND and limit
211 // See the user guide for more details and a comparison with cutoff_limit.
212 optional double best_bound_limit = 22;
214 // The solver stops early after finding this many feasible solutions, with
215 // termination reason FEASIBLE and limit SOLUTION. Must be greater than zero
216 // if set. It is often used get the solver to stop on the first feasible
217 // solution found. Note that there is no guarantee on the objective value for
218 // any of the returned solutions.
220 // Solvers will typically not return more solutions than the solution limit,
221 // but this is not enforced by MathOpt, see also b/214041169.
223 // Currently supported for Gurobi and SCIP, and for CP-SAT only with value 1.
224 optional int32 solution_limit = 23;
226 // Enables printing the solver implementation traces. The location of those
227 // traces depend on the solver. For SCIP and Gurobi this will be the standard
228 // output streams. For Glop and CP-SAT this will LOG(INFO).
230 // Note that if the solver supports message callback and the user registers a
231 // callback for it, then this parameter value is ignored and no traces are
233 bool enable_output = 3;
235 // If set, it must be >= 1.
236 optional int32 threads = 4;
238 // Seed for the pseudo-random number generator in the underlying
239 // solver. Note that all solvers use pseudo-random numbers to select things
240 // such as perturbation in the LP algorithm, for tie-break-up rules, and for
241 // heuristic fixings. Varying this can have a noticeable impact on solver
244 // Although all solvers have a concept of seeds, note that valid values
245 // depend on the actual solver.
246 // - Gurobi: [0:GRB_MAXINT] (which as of Gurobi 9.0 is 2x10^9).
247 // - GSCIP: [0:2147483647] (which is MAX_INT or kint32max or 2^31-1).
248 // - GLOP: [0:2147483647] (same as above)
249 // In all cases, the solver will receive a value equal to:
250 // MAX(0, MIN(MAX_VALID_VALUE_FOR_SOLVER, random_seed)).
251 optional int32 random_seed = 5;
253 // An absolute optimality tolerance (primarily) for MIP solvers.
255 // The absolute GAP is the absolute value of the difference between:
256 // * the objective value of the best feasible solution found,
257 // * the dual bound produced by the search.
258 // The solver can stop once the absolute GAP is at most absolute_gap_tolerance
259 // (when set), and return TERMINATION_REASON_OPTIMAL.
261 // Must be >= 0 if set.
263 // See also relative_gap_tolerance.
264 optional double absolute_gap_tolerance = 18;
266 // A relative optimality tolerance (primarily) for MIP solvers.
268 // The relative GAP is a normalized version of the absolute GAP (defined on
269 // absolute_gap_tolerance), where the normalization is solver-dependent, e.g.
270 // the absolute GAP divided by the objective value of the best feasible
273 // The solver can stop once the relative GAP is at most relative_gap_tolerance
274 // (when set), and return TERMINATION_REASON_OPTIMAL.
276 // Must be >= 0 if set.
278 // See also absolute_gap_tolerance.
279 optional double relative_gap_tolerance = 17;
281 // Maintain up to `solution_pool_size` solutions while searching. The solution
282 // pool generally has two functions:
283 // (1) For solvers that can return more than one solution, this limits how
284 // many solutions will be returned.
285 // (2) Some solvers may run heuristics using solutions from the solution
286 // pool, so changing this value may affect the algorithm's path.
287 // To force the solver to fill the solution pool, e.g. with the n best
288 // solutions, requires further, solver specific configuration.
289 optional int32 solution_pool_size = 25;
291 // The algorithm for solving a linear program. If LP_ALGORITHM_UNSPECIFIED,
292 // use the solver default algorithm.
294 // For problems that are not linear programs but where linear programming is
295 // a subroutine, solvers may use this value. E.g. MIP solvers will typically
296 // use this for the root LP solve only (and use dual simplex otherwise).
297 LPAlgorithmProto lp_algorithm = 6;
299 // Effort on simplifying the problem before starting the main algorithm, or
300 // the solver default effort level if EMPHASIS_UNSPECIFIED.
301 EmphasisProto presolve = 7;
303 // Effort on getting a stronger LP relaxation (MIP only), or the solver
304 // default effort level if EMPHASIS_UNSPECIFIED.
306 // NOTE: disabling cuts may prevent callbacks from having a chance to add cuts
307 // at MIP_NODE, this behavior is solver specific.
308 EmphasisProto cuts = 8;
310 // Effort in finding feasible solutions beyond those encountered in the
311 // complete search procedure (MIP only), or the solver default effort level if
312 // EMPHASIS_UNSPECIFIED.
313 EmphasisProto heuristics = 9;
315 // Effort in rescaling the problem to improve numerical stability, or the
316 // solver default effort level if EMPHASIS_UNSPECIFIED.
317 EmphasisProto scaling = 10;
319 reserved 12, 13, 14, 15, 16, 19, 26, 27;
321 reserved 11; // Deleted