SolverRegistry class
#include <gtopt/solver_registry.hpp>
Singleton registry for dynamically loaded solver plugins.
Usage:
auto& reg = SolverRegistry::instance(); auto backend = reg.create("highs"); // loads plugin if needed
Public static functions
- static auto instance() -> SolverRegistry&
- Get the global singleton registry.
Constructors, destructors, conversion operators
- SolverRegistry(const SolverRegistry&) deleted
- SolverRegistry(SolverRegistry&&) deleted
- ~SolverRegistry()
Public functions
- auto available_solvers() const -> std::vector<std::string>
- List all available solver names across loaded plugins.
- auto create(std::string_view solver_name) const -> std::unique_ptr<SolverBackend>
- Create a solver backend by name.
- auto default_solver() const -> std::string_view
- Return the best available solver name by priority.
- auto discover_plugins(const std::filesystem::path& dir) -> void
- Discover and load all plugins from a directory.
- auto has_solver(std::string_view name) const -> bool
- Check whether a solver name is available.
- auto load_errors() const -> const std::vector<std::string>&
- Return diagnostic messages for plugins that failed to load.
- auto load_plugin(const std::filesystem::path& path) -> bool
- Load a single plugin shared library.
- auto operator=(const SolverRegistry&) -> SolverRegistry& deleted
- auto operator=(SolverRegistry&&) -> SolverRegistry& deleted
- auto searched_directories() const -> const std::vector<std::string>&
- Return the directories that were searched for plugins.
Function documentation
static SolverRegistry& gtopt:: SolverRegistry:: instance()
Get the global singleton registry.
On first call, automatically discovers plugins from standard paths.
std::unique_ptr<SolverBackend> gtopt:: SolverRegistry:: create(std::string_view solver_name) const
Create a solver backend by name.
| Parameters | |
|---|---|
| solver_name | Solver identifier: "clp", "cbc", "cplex", "highs" |
| Returns | Owning pointer to the created backend |
| Exceptions | |
| std::runtime_error | if the solver is not available |
std::string_view gtopt:: SolverRegistry:: default_solver() const
Return the best available solver name by priority.
| Exceptions | |
|---|---|
| std::runtime_error | if no solver plugins are loaded. |
Priority order: cplex, highs, cbc, clp.
void gtopt:: SolverRegistry:: discover_plugins(const std::filesystem::path& dir)
Discover and load all plugins from a directory.
Scans dir for files matching libgtopt_solver_*.so and loads each. Already-loaded plugins are skipped.
bool gtopt:: SolverRegistry:: load_plugin(const std::filesystem::path& path)
Load a single plugin shared library.
| Parameters | |
|---|---|
| path | Full path to the .so file |
| Returns | true if the plugin was loaded successfully |