Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
gurobi_init_arguments.h
Go to the documentation of this file.
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
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_SOLVERS_GUROBI_INIT_ARGUMENTS_H_
15#define OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_INIT_ARGUMENTS_H_
16
17#include <optional>
18
19#include "absl/status/statusor.h"
21#include "ortools/math_opt/parameters.pb.h"
22#include "ortools/math_opt/solvers/gurobi.pb.h"
24
25namespace operations_research {
26namespace math_opt {
27
28// Returns a new primary environment.
29//
30// The typical use of this function is to share the same environment between
31// multiple solver instances. This is necessary when a single-use license is
32// used since only one primary environment can exists in that case.
33//
34// A single primary environment is not thread-safe and thus it should only be
35// used in a single thread. Even if the user has a license that authorizes
36// multiple primary environments, Gurobi still recommends to use only one and to
37// share it as it is more efficient (see GRBloadenv() documentation).
38//
39// Of course, if the user wants to run multiple solves in parallel and has a
40// license that authorizes that, one environment should be used per thread.
41//
42// The primary environment can be passed to MathOpt via the
43// NonStreamableGurobiInitArguments structure and its primary_env field.
44//
45// The optional ISV key can be used to build the environment from an ISV key
46// instead of using the default license file. See
47// http://www.gurobi.com/products/licensing-pricing/isv-program for details.
48//
49// Example with default license file:
50//
51// // Solving two models on the same thread, sharing the same primary
52// // environment.
53// Model model_1;
54// Model model_2;
55//
56// ...
57//
58// ASSIGN_OR_RETURN(const GRBenvUniquePtr primary_env,
59// NewPrimaryEnvironment());
60//
61// NonStreamableGurobiInitArguments gurobi_args;
62// gurobi_args.primary_env = primary_env.get();
63//
64// ASSIGN_OR_RETURN(
65// const std::unique_ptr<IncrementalSolver> incremental_solve_1,
66// NewIncrementalSolver(model, SOLVER_TYPE_GUROBI,
67// SolverInitArguments(gurobi_args)));
68// ASSIGN_OR_RETURN(
69// const std::unique_ptr<IncrementalSolver> incremental_solve_2,
70// NewIncrementalSolver(model, SOLVER_TYPE_GUROBI,
71// SolverInitArguments(gurobi_args)));
72//
73// ASSIGN_OR_RETURN(const SolveResult result_1, incremental_solve_1->Solve());
74// ASSIGN_OR_RETURN(const SolveResult result_2, incremental_solve_2->Solve());
75//
76//
77// With ISV key:
78//
79// ASSIGN_OR_RETURN(const GRBenvUniquePtr primary_env,
80// NewPrimaryEnvironment(GurobiISVKey{
81// .name = "the name",
82// .application_name = "the application",
83// .expiration = 0,
84// .key = "...",
85// }.Proto()));
86//
87absl::StatusOr<GRBenvUniquePtr> NewPrimaryEnvironment(
88 std::optional<GurobiInitializerProto::ISVKey> proto_isv_key = {});
89
90// Non-streamable Gurobi specific parameters for solver instantiation.
91//
92// See NonStreamableSolverInitArguments for details.
95 NonStreamableGurobiInitArguments, SOLVER_TYPE_GUROBI> {
96 // Primary environment to use. This is only useful to pass when either the
97 // default primary environment created by the solver implementation is not
98 // enough or when multiple Gurobi solvers are used with a single-use
99 // license. In the latter case, only one primary environment can be created so
100 // it must be shared.
101 //
102 // The solver does not take ownership of the environment, it is the
103 // responsibility of the caller to properly dispose of it after all solvers
104 // that used it have been destroyed.
105 GRBenv* primary_env = nullptr;
106
108 const override {
109 return this;
110 }
111};
112
113} // namespace math_opt
114} // namespace operations_research
115
116#endif // OR_TOOLS_MATH_OPT_SOLVERS_GUROBI_INIT_ARGUMENTS_H_
struct _GRBenv GRBenv
Definition environment.h:32
absl::StatusOr< GRBenvUniquePtr > NewPrimaryEnvironment(std::optional< GurobiInitializerProto::ISVKey > proto_isv_key)
In SWIG mode, we don't want anything besides these top-level includes.
const NonStreamableGurobiInitArguments * ToNonStreamableGurobiInitArguments() const override