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