22#include "absl/container/flat_hash_map.h"
23#include "absl/log/check.h"
24#include "absl/status/statusor.h"
25#include "absl/strings/ascii.h"
26#include "absl/strings/match.h"
27#include "absl/strings/str_cat.h"
28#include "absl/strings/str_join.h"
29#include "absl/synchronization/mutex.h"
32#include "ortools/math_opt/model.pb.h"
33#include "ortools/math_opt/parameters.pb.h"
49 const absl::MutexLock lock(&mutex_);
51 registered_solvers_.emplace(solver_type, std::move(factory)).second;
54 <<
" already registered.";
58 SolverTypeProto solver_type,
const ModelProto&
model,
62 const absl::MutexLock lock(&mutex_);
65 if (factory ==
nullptr) {
66 std::string
name = SolverTypeProto_Name(solver_type);
68 name = absl::StrCat(
"unknown(",
static_cast<int>(solver_type),
")");
71 <<
"solver type " <<
name <<
" is not registered"
72 <<
", support for this solver has not been compiled";
74 return (*factory)(
model, init_args);
78 const absl::MutexLock lock(&mutex_);
79 return registered_solvers_.contains(solver_type);
83 std::vector<SolverTypeProto> result;
85 const absl::MutexLock lock(&mutex_);
86 for (
const auto& kv_pair : registered_solvers_) {
87 result.push_back(kv_pair.first);
90 std::sort(result.begin(), result.end());
95 std::vector<std::string> solver_names;
97 const absl::MutexLock lock(&mutex_);
98 for (
const auto& kv_pair : registered_solvers_) {
102 std::sort(solver_names.begin(), solver_names.end());
103 return absl::StrCat(
"[", absl::StrJoin(solver_names,
","),
"]");
bool IsRegistered(SolverTypeProto solver_type) const
Whether a solver type is supported.
std::vector< SolverTypeProto > RegisteredSolvers() const
List all supported solver types.
void Register(SolverTypeProto solver_type, SolverInterface::Factory factory)
static AllSolversRegistry * Instance()
std::string RegisteredSolversToString() const
Returns a human-readable list of supported solver types.
absl::StatusOr< std::unique_ptr< SolverInterface > > Create(SolverTypeProto solver_type, const ModelProto &model, const SolverInterface::InitArgs &init_args) const
std::function< absl::StatusOr< std::unique_ptr< SolverInterface > >( const ModelProto &model, const InitArgs &init_args)> Factory
const std::string name
A name for logging purposes.
const Collection::value_type::second_type * FindOrNull(const Collection &collection, const typename Collection::value_type::first_type &key)
In SWIG mode, we don't want anything besides these top-level includes.
std::string ProtoEnumToString(ProtoEnumType enum_value)
StatusBuilder InvalidArgumentErrorBuilder()
Initialization arguments.