OR-Tools  9.6
streamable_solver_init_arguments.cc
Go to the documentation of this file.
1 // Copyright 2010-2022 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 
15 
16 #include <optional>
17 #include <string>
18 #include <type_traits>
19 
20 #include "absl/status/statusor.h"
21 #include "ortools/math_opt/parameters.pb.h"
22 #include "ortools/math_opt/solvers/gurobi.pb.h"
23 
24 namespace operations_research {
25 namespace math_opt {
26 
27 GurobiInitializerProto::ISVKey GurobiISVKey::Proto() const {
28  GurobiInitializerProto::ISVKey isv_key_proto;
29  isv_key_proto.set_name(name);
30  isv_key_proto.set_application_name(application_name);
31  isv_key_proto.set_expiration(expiration);
32  isv_key_proto.set_key(key);
33  return isv_key_proto;
34 }
35 
37  const GurobiInitializerProto::ISVKey& key_proto) {
38  return GurobiISVKey{
39  .name = key_proto.name(),
40  .application_name = key_proto.application_name(),
41  .expiration = key_proto.expiration(),
42  .key = key_proto.key(),
43  };
44 }
45 
46 GurobiInitializerProto StreamableGurobiInitArguments::Proto() const {
47  GurobiInitializerProto params_proto;
48 
49  if (isv_key) {
50  *params_proto.mutable_isv_key() = isv_key->Proto();
51  }
52 
53  return params_proto;
54 }
55 
57  const GurobiInitializerProto& args_proto) {
59  if (args_proto.has_isv_key()) {
60  args.isv_key = GurobiISVKey::FromProto(args_proto.isv_key());
61  }
62  return args;
63 }
64 
65 SolverInitializerProto StreamableSolverInitArguments::Proto() const {
66  SolverInitializerProto params_proto;
67 
68  if (gurobi) {
69  *params_proto.mutable_gurobi() = gurobi->Proto();
70  }
71 
72  return params_proto;
73 }
74 
75 absl::StatusOr<StreamableSolverInitArguments>
77  const SolverInitializerProto& args_proto) {
79  if (args_proto.has_gurobi()) {
80  args.gurobi = StreamableGurobiInitArguments::FromProto(args_proto.gurobi());
81  }
82  return args;
83 }
84 
85 } // namespace math_opt
86 } // namespace operations_research
Collection of objects used to extend the Constraint Solver library.
static GurobiISVKey FromProto(const GurobiInitializerProto::ISVKey &key_proto)
static StreamableGurobiInitArguments FromProto(const GurobiInitializerProto &args_proto)
static absl::StatusOr< StreamableSolverInitArguments > FromProto(const SolverInitializerProto &args_proto)