14 #ifndef OR_TOOLS_MATH_OPT_CORE_SOLVER_INTERFACE_H_
15 #define OR_TOOLS_MATH_OPT_CORE_SOLVER_INTERFACE_H_
22 #include "absl/base/attributes.h"
23 #include "absl/container/flat_hash_map.h"
24 #include "absl/status/status.h"
25 #include "absl/status/statusor.h"
26 #include "absl/strings/string_view.h"
27 #include "absl/synchronization/mutex.h"
28 #include "ortools/math_opt/callback.pb.h"
31 #include "ortools/math_opt/model.pb.h"
32 #include "ortools/math_opt/model_parameters.pb.h"
33 #include "ortools/math_opt/model_update.pb.h"
34 #include "ortools/math_opt/parameters.pb.h"
35 #include "ortools/math_opt/result.pb.h"
44 "This solver does not support message callbacks.";
84 using Callback = std::function<absl::StatusOr<CallbackResultProto>(
85 const CallbackDataProto&)>;
97 std::function<absl::StatusOr<std::unique_ptr<SolverInterface>>(
125 virtual absl::StatusOr<SolveResultProto>
Solve(
127 const ModelSolveParametersProto& model_parameters,
129 const CallbackRegistrationProto& callback_registration,
Callback cb,
137 virtual absl::StatusOr<bool>
Update(
const ModelUpdateProto& model_update) = 0;
156 absl::StatusOr<std::unique_ptr<SolverInterface>>
Create(
157 SolverTypeProto solver_type,
const ModelProto&
model,
172 mutable absl::Mutex mutex_;
173 absl::flat_hash_map<SolverTypeProto, SolverInterface::Factory>
187 #define MATH_OPT_REGISTER_SOLVER(solver_type, solver_factory) \
189 const void* const kRegisterSolver ABSL_ATTRIBUTE_UNUSED = [] { \
190 AllSolversRegistry::Instance()->Register(solver_type, solver_factory); \
void Register(SolverTypeProto solver_type, SolverInterface::Factory factory)
absl::StatusOr< std::unique_ptr< SolverInterface > > Create(SolverTypeProto solver_type, const ModelProto &model, const SolverInterface::InitArgs &init_args) const
AllSolversRegistry(const AllSolversRegistry &)=delete
bool IsRegistered(SolverTypeProto solver_type) const
std::string RegisteredSolversToString() const
static AllSolversRegistry * Instance()
std::vector< SolverTypeProto > RegisteredSolvers() const
AllSolversRegistry & operator=(const AllSolversRegistry &)=delete
SolverInterface & operator=(const SolverInterface &)=delete
virtual ~SolverInterface()=default
virtual absl::StatusOr< SolveResultProto > Solve(const SolveParametersProto ¶meters, const ModelSolveParametersProto &model_parameters, MessageCallback message_cb, const CallbackRegistrationProto &callback_registration, Callback cb, SolveInterrupter *interrupter)=0
std::function< void(const std::vector< std::string > &)> MessageCallback
std::function< absl::StatusOr< std::unique_ptr< SolverInterface > >(const ModelProto &model, const InitArgs &init_args)> Factory
std::function< absl::StatusOr< CallbackResultProto >(const CallbackDataProto &)> Callback
SolverInterface()=default
virtual absl::StatusOr< bool > Update(const ModelUpdateProto &model_update)=0
SolverInterface(const SolverInterface &)=delete
constexpr absl::string_view kMessageCallbackNotSupported
Collection of objects used to extend the Constraint Solver library.
const NonStreamableSolverInitArguments * non_streamable
SolverInitializerProto streamable