1// Copyright 2010-2025 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.
17package operations_research.math_opt;
19import "google/protobuf/duration.proto";
20import "ortools/pdlp/solvers.proto";
21import "ortools/glop/parameters.proto";
22import "ortools/math_opt/solvers/glpk.proto";
23import "ortools/math_opt/solvers/gscip/gscip.proto";
24import "ortools/math_opt/solvers/gurobi.proto";
25import "ortools/math_opt/solvers/highs.proto";
26import "ortools/math_opt/solvers/osqp.proto";
27import "ortools/math_opt/solvers/xpress.proto";
28import "ortools/sat/sat_parameters.proto";
30option java_package = "com.google.ortools.mathopt";
31option java_multiple_files = true;
33// The solvers supported by MathOpt.
35 SOLVER_TYPE_UNSPECIFIED = 0;
37 // Solving Constraint Integer Programs (SCIP) solver (third party).
39 // Supports LP, MIP, and nonconvex integer quadratic problems. No dual data
40 // for LPs is returned though. Prefer GLOP for LPs.
41 SOLVER_TYPE_GSCIP = 1;
43 // Gurobi solver (third party).
45 // Supports LP, MIP, and nonconvex integer quadratic problems. Generally the
46 // fastest option, but has special licensing.
47 SOLVER_TYPE_GUROBI = 2;
49 // Google's Glop solver.
51 // Supports LP with primal and dual simplex methods.
54 // Google's CP-SAT solver.
56 // Supports problems where all variables are integer and bounded (or implied
57 // to be after presolve). Experimental support to rescale and discretize
58 // problems with continuous variables.
59 SOLVER_TYPE_CP_SAT = 4;
61 // Google's PDLP solver.
63 // Supports LP and convex diagonal quadratic objectives. Uses first order
64 // methods rather than simplex. Can solve very large problems.
67 // GNU Linear Programming Kit (GLPK) (third party).
69 // Supports MIP and LP.
71 // Thread-safety: GLPK use thread-local storage for memory allocations. As a
72 // consequence Solver instances must be destroyed on the same thread as they
73 // are created or GLPK will crash. It seems OK to call Solver::Solve() from
74 // another thread than the one used to create the Solver but it is not
75 // documented by GLPK and should be avoided.
77 // When solving a LP with the presolver, a solution (and the unbound rays) are
78 // only returned if an optimal solution has been found. Else nothing is
79 // returned. See glpk-5.0/doc/glpk.pdf page #40 available from glpk-5.0.tar.gz
83 // The Operator Splitting Quadratic Program (OSQP) solver (third party).
85 // Supports continuous problems with linear constraints and linear or convex
86 // quadratic objectives. Uses a first-order method.
89 // The Embedded Conic Solver (ECOS) (third party).
91 // Supports LP and SOCP problems. Uses interior point methods (barrier).
94 // The Splitting Conic Solver (SCS) (third party).
96 // Supports LP and SOCP problems. Uses a first-order method.
99 // The HiGHS Solver (third party).
101 // Supports LP and MIP problems (convex QPs are unimplemented).
102 SOLVER_TYPE_HIGHS = 10;
104 // MathOpt's reference implementation of a MIP solver.
106 // Slow/not recommended for production. Not an LP solver (no dual information
108 SOLVER_TYPE_SANTORINI = 11;
112 // Fico XPRESS solver (third party).
114 // Supports LP, MIP, and nonconvex integer quadratic problems.
115 // A fast option, but has special licensing.
116 SOLVER_TYPE_XPRESS = 13;
119// Selects an algorithm for solving linear programs.
120enum LPAlgorithmProto {
121 LP_ALGORITHM_UNSPECIFIED = 0;
123 // The (primal) simplex method. Typically can provide primal and dual
124 // solutions, primal/dual rays on primal/dual unbounded problems, and a basis.
125 LP_ALGORITHM_PRIMAL_SIMPLEX = 1;
127 // The dual simplex method. Typically can provide primal and dual
128 // solutions, primal/dual rays on primal/dual unbounded problems, and a basis.
129 LP_ALGORITHM_DUAL_SIMPLEX = 2;
131 // The barrier method, also commonly called an interior point method (IPM).
132 // Can typically give both primal and dual solutions. Some implementations can
133 // also produce rays on unbounded/infeasible problems. A basis is not given
134 // unless the underlying solver does "crossover" and finishes with simplex.
135 LP_ALGORITHM_BARRIER = 3;
137 // An algorithm based around a first-order method. These will typically
138 // produce both primal and dual solutions, and potentially also certificates
139 // of primal and/or dual infeasibility. First-order methods typically will
140 // provide solutions with lower accuracy, so users should take care to set
141 // solution quality parameters (e.g., tolerances) and to validate solutions.
142 LP_ALGORITHM_FIRST_ORDER = 4;
145// Effort level applied to an optional task while solving (see
146// SolveParametersProto for use).
148// Emphasis is used to configure a solver feature as follows:
149// * If a solver doesn't support the feature, only UNSPECIFIED will always be
150// valid, any other setting will typically an invalid argument error (some
151// solvers may also accept OFF).
152// * If the solver supports the feature:
153// - When set to UNSPECIFIED, the underlying default is used.
154// - When the feature cannot be turned off, OFF will return an error.
155// - If the feature is enabled by default, the solver default is typically
157// - If the feature is supported, LOW, MEDIUM, HIGH, and VERY HIGH will never
158// give an error, and will map onto their best match.
160 EMPHASIS_UNSPECIFIED = 0;
165 EMPHASIS_VERY_HIGH = 5;
168// Configures if potentially bad solver input is a warning or an error.
170// TODO(b/196132970): implement this feature.
171message StrictnessProto {
172 bool bad_parameter = 1;
175// This message contains solver specific data that are used when the solver is
177message SolverInitializerProto {
178 GurobiInitializerProto gurobi = 1;
180 XpressInitializerProto xpress = 3;
183// Parameters to control a single solve.
185// Contains both parameters common to all solvers e.g. time_limit, and
186// parameters for a specific solver, e.g. gscip. If a value is set in both
187// common and solver specific field, the solver specific setting is used.
189// The common parameters that are optional and unset or an enum with value
190// unspecified indicate that the solver default is used.
192// Solver specific parameters for solvers other than the one in use are ignored.
194// Parameters that depends on the model (e.g. branching priority is set for
195// each variable) are passed in ModelSolveParametersProto.
196message SolveParametersProto {
197 //////////////////////////////////////////////////////////////////////////////
198 // Parameters common to all solvers.
199 //////////////////////////////////////////////////////////////////////////////
201 // Maximum time a solver should spend on the problem (or infinite if not set).
203 // This value is not a hard limit, solve time may slightly exceed this value.
204 // This parameter is always passed to the underlying solver, the solver
205 // default is not used.
206 google.protobuf.Duration time_limit = 1;
208 // Limit on the iterations of the underlying algorithm (e.g. simplex pivots).
209 // The specific behavior is dependent on the solver and algorithm used, but
210 // often can give a deterministic solve limit (further configuration may be
211 // needed, e.g. one thread).
213 // Typically supported by LP, QP, and MIP solvers, but for MIP solvers see
215 optional int64 iteration_limit = 2;
217 // Limit on the number of subproblems solved in enumerative search (e.g.
218 // branch and bound). For many solvers this can be used to deterministically
219 // limit computation (further configuration may be needed, e.g. one thread).
221 // Typically for MIP solvers, see also iteration_limit.
222 optional int64 node_limit = 24;
224 // The solver stops early if it can prove there are no primal solutions at
225 // least as good as cutoff.
227 // On an early stop, the solver returns termination reason NO_SOLUTION_FOUND
228 // and with limit CUTOFF and is not required to give any extra solution
229 // information. Has no effect on the return value if there is no early stop.
231 // It is recommended that you use a tolerance if you want solutions with
232 // objective exactly equal to cutoff to be returned.
234 // See the user guide for more details and a comparison with best_bound_limit.
235 optional double cutoff_limit = 20;
237 // The solver stops early as soon as it finds a solution at least this good,
238 // with termination reason FEASIBLE and limit OBJECTIVE.
239 optional double objective_limit = 21;
241 // The solver stops early as soon as it proves the best bound is at least this
242 // good, with termination reason FEASIBLE or NO_SOLUTION_FOUND and limit
245 // See the user guide for more details and a comparison with cutoff_limit.
246 optional double best_bound_limit = 22;
248 // The solver stops early after finding this many feasible solutions, with
249 // termination reason FEASIBLE and limit SOLUTION. Must be greater than zero
250 // if set. It is often used get the solver to stop on the first feasible
251 // solution found. Note that there is no guarantee on the objective value for
252 // any of the returned solutions.
254 // Solvers will typically not return more solutions than the solution limit,
255 // but this is not enforced by MathOpt, see also b/214041169.
257 // Currently supported for Gurobi and SCIP, and for CP-SAT only with value 1.
258 optional int32 solution_limit = 23;
260 // Enables printing the solver implementation traces. The location of those
261 // traces depend on the solver. For SCIP and Gurobi this will be the standard
262 // output streams. For Glop and CP-SAT this will LOG(INFO).
264 // Note that if the solver supports message callback and the user registers a
265 // callback for it, then this parameter value is ignored and no traces are
267 bool enable_output = 3;
269 // If set, it must be >= 1.
270 optional int32 threads = 4;
272 // Seed for the pseudo-random number generator in the underlying
273 // solver. Note that all solvers use pseudo-random numbers to select things
274 // such as perturbation in the LP algorithm, for tie-break-up rules, and for
275 // heuristic fixings. Varying this can have a noticeable impact on solver
278 // Although all solvers have a concept of seeds, note that valid values
279 // depend on the actual solver.
280 // - Gurobi: [0:GRB_MAXINT] (which as of Gurobi 9.0 is 2x10^9).
281 // - GSCIP: [0:2147483647] (which is MAX_INT or kint32max or 2^31-1).
282 // - GLOP: [0:2147483647] (same as above)
283 // In all cases, the solver will receive a value equal to:
284 // MAX(0, MIN(MAX_VALID_VALUE_FOR_SOLVER, random_seed)).
285 optional int32 random_seed = 5;
287 // An absolute optimality tolerance (primarily) for MIP solvers.
289 // The absolute GAP is the absolute value of the difference between:
290 // * the objective value of the best feasible solution found,
291 // * the dual bound produced by the search.
292 // The solver can stop once the absolute GAP is at most absolute_gap_tolerance
293 // (when set), and return TERMINATION_REASON_OPTIMAL.
295 // Must be >= 0 if set.
297 // See also relative_gap_tolerance.
298 optional double absolute_gap_tolerance = 18;
300 // A relative optimality tolerance (primarily) for MIP solvers.
302 // The relative GAP is a normalized version of the absolute GAP (defined on
303 // absolute_gap_tolerance), where the normalization is solver-dependent, e.g.
304 // the absolute GAP divided by the objective value of the best feasible
307 // The solver can stop once the relative GAP is at most relative_gap_tolerance
308 // (when set), and return TERMINATION_REASON_OPTIMAL.
310 // Must be >= 0 if set.
312 // See also absolute_gap_tolerance.
313 optional double relative_gap_tolerance = 17;
315 // Maintain up to `solution_pool_size` solutions while searching. The solution
316 // pool generally has two functions:
317 // (1) For solvers that can return more than one solution, this limits how
318 // many solutions will be returned.
319 // (2) Some solvers may run heuristics using solutions from the solution
320 // pool, so changing this value may affect the algorithm's path.
321 // To force the solver to fill the solution pool, e.g. with the n best
322 // solutions, requires further, solver specific configuration.
323 optional int32 solution_pool_size = 25;
325 // The algorithm for solving a linear program. If LP_ALGORITHM_UNSPECIFIED,
326 // use the solver default algorithm.
328 // For problems that are not linear programs but where linear programming is
329 // a subroutine, solvers may use this value. E.g. MIP solvers will typically
330 // use this for the root LP solve only (and use dual simplex otherwise).
331 LPAlgorithmProto lp_algorithm = 6;
333 // Effort on simplifying the problem before starting the main algorithm, or
334 // the solver default effort level if EMPHASIS_UNSPECIFIED.
335 EmphasisProto presolve = 7;
337 // Effort on getting a stronger LP relaxation (MIP only), or the solver
338 // default effort level if EMPHASIS_UNSPECIFIED.
340 // NOTE: disabling cuts may prevent callbacks from having a chance to add cuts
341 // at MIP_NODE, this behavior is solver specific.
342 EmphasisProto cuts = 8;
344 // Effort in finding feasible solutions beyond those encountered in the
345 // complete search procedure (MIP only), or the solver default effort level if
346 // EMPHASIS_UNSPECIFIED.
347 EmphasisProto heuristics = 9;
349 // Effort in rescaling the problem to improve numerical stability, or the
350 // solver default effort level if EMPHASIS_UNSPECIFIED.
351 EmphasisProto scaling = 10;
353 //////////////////////////////////////////////////////////////////////////////
354 // Solver specific parameters
355 //////////////////////////////////////////////////////////////////////////////
357 GScipParameters gscip = 12;
359 GurobiParametersProto gurobi = 13;
361 glop.GlopParameters glop = 14;
363 sat.SatParameters cp_sat = 15;
365 pdlp.PrimalDualHybridGradientParams pdlp = 16;
367 // Users should prefer the generic MathOpt parameters over OSQP-level
368 // parameters, when available:
369 // * Prefer SolveParametersProto.enable_output to OsqpSettingsProto.verbose.
370 // * Prefer SolveParametersProto.time_limit to OsqpSettingsProto.time_limit.
371 // * Prefer SolveParametersProto.iteration_limit to
372 // OsqpSettingsProto.iteration_limit.
373 // * If a less granular configuration is acceptable, prefer
374 // SolveParametersProto.scaling to OsqpSettingsProto.
375 OsqpSettingsProto osqp = 19;
377 GlpkParametersProto glpk = 26;
379 HighsOptionsProto highs = 27;
381 XpressParametersProto xpress = 28;
383 reserved 11; // Deleted