OR-Tools  9.6
non_streamable_solver_init_arguments.h
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 
14 #ifndef OR_TOOLS_MATH_OPT_CORE_NON_STREAMABLE_SOLVER_INIT_ARGUMENTS_H_
15 #define OR_TOOLS_MATH_OPT_CORE_NON_STREAMABLE_SOLVER_INIT_ARGUMENTS_H_
16 
17 #include <memory>
18 
19 #include "ortools/math_opt/parameters.pb.h"
20 
21 namespace operations_research {
22 namespace math_opt {
23 
24 struct NonStreamableCpSatInitArguments;
25 struct NonStreamableGScipInitArguments;
26 struct NonStreamableGlopInitArguments;
27 struct NonStreamableGlpkInitArguments;
28 struct NonStreamableGurobiInitArguments;
29 struct NonStreamablePdlpInitArguments;
30 
31 // Interface for solver specific parameters used at the solver instantiation
32 // that can't be streamed (for example instances of C/C++ types that only exist
33 // in the process memory).
34 //
35 // Since implementations of this interface usually depend on solver specific
36 // C/C++ types, they are in a dedicated header in the solver library.
37 //
38 // This class is the interface shared by the parameters of each solver, users
39 // should instantiate the solver specific class below.
40 //
41 // To enable safe cast of a pointer to this interface, there is an
42 // ToNonStreamableXxxInitArguments() function for each solver. Only one of these
43 // function will return a non-null value, depending on the type of the
44 // implementation class.
45 //
46 // Implementation should use NonStreamableSolverInitArgumentsHelper to
47 // automatically implements some methods.
49  virtual ~NonStreamableSolverInitArguments() = default;
50 
51  // Returns the type of solver that the implementation is for.
52  virtual SolverTypeProto solver_type() const = 0;
53 
54  // Returns this for the NonStreamableCpSatInitArguments class, nullptr for
55  // other classes.
56  virtual const NonStreamableCpSatInitArguments*
58  return nullptr;
59  }
60 
61  // Returns this for the NonStreamableGScipInitArguments class, nullptr for
62  // other classes.
63  virtual const NonStreamableGScipInitArguments*
65  return nullptr;
66  }
67 
68  // Returns this for the NonStreamableGlopInitArguments class, nullptr for
69  // other classes.
70  virtual const NonStreamableGlopInitArguments*
72  return nullptr;
73  }
74 
75  // Returns this for the NonStreamableGlpkInitArguments class, nullptr for
76  // other classes.
77  virtual const NonStreamableGlpkInitArguments*
79  return nullptr;
80  }
81 
82  // Returns this for the NonStreamableGurobiInitArguments class, nullptr for
83  // other classes.
86  return nullptr;
87  }
88 
89  // Returns this for the NonStreamablePdlpInitArguments class, nullptr for
90  // other classes.
91  virtual const NonStreamablePdlpInitArguments*
93  return nullptr;
94  }
95 
96  // Return a copy of this.
97  //
98  // The NonStreamableSolverInitArgumentsHelper implements this automatically
99  // using the copy constructor (this base class is copyable intentionally).
100  virtual std::unique_ptr<const NonStreamableSolverInitArguments> Clone()
101  const = 0;
102 };
103 
104 // Base struct for implementations that automatically implements solver_type()
105 // and Clone() virtual methods.
106 //
107 // The Clone() method is implemented with the copy constructor of the struct.
108 //
109 // All that is left to the implementation is to provide are the solver specific
110 // field and the implementation of the ToNonStreamableXxxInitArguments()
111 // corresponding to the solver type.
112 //
113 // Usage:
114 //
115 // struct NonStreamableXxxInitArguments
116 // : public NonStreamableSolverInitArgumentsHelper<
117 // NonStreamableXxxInitArguments, SOLVER_TYPE_XXX> {
118 //
119 // ... some data member here ...
120 //
121 // const NonStreamableXxxInitArguments*
122 // ToNonStreamableXxxInitArguments() const { return this; }
123 // };
124 template <typename Implementation, SolverTypeProto impl_solver_type>
127  SolverTypeProto solver_type() const final { return impl_solver_type; }
128 
129  std::unique_ptr<const NonStreamableSolverInitArguments> Clone() const final {
130  return std::make_unique<Implementation>(
131  *static_cast<const Implementation*>(this));
132  }
133 };
134 
135 } // namespace math_opt
136 } // namespace operations_research
137 
138 #endif // OR_TOOLS_MATH_OPT_CORE_NON_STREAMABLE_SOLVER_INIT_ARGUMENTS_H_
Collection of objects used to extend the Constraint Solver library.
std::unique_ptr< const NonStreamableSolverInitArguments > Clone() const final
virtual const NonStreamableGurobiInitArguments * ToNonStreamableGurobiInitArguments() const
virtual const NonStreamablePdlpInitArguments * ToNonStreamablePdlpInitArguments() const
virtual const NonStreamableCpSatInitArguments * ToNonStreamableCpSatInitArguments() const
virtual const NonStreamableGScipInitArguments * ToNonStreamableGScipInitArguments() const
virtual const NonStreamableGlopInitArguments * ToNonStreamableGlopInitArguments() const
virtual const NonStreamableGlpkInitArguments * ToNonStreamableGlpkInitArguments() const
virtual std::unique_ptr< const NonStreamableSolverInitArguments > Clone() const =0