Skip to content

Commit

Permalink
check available Solvers once per program
Browse files Browse the repository at this point in the history
  • Loading branch information
a-zakir committed Nov 15, 2023
1 parent 5731bce commit dd28db3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
20 changes: 13 additions & 7 deletions src/cpp/multisolver_interface/SolverFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
#endif
#include "LogUtils.h"
#include "multisolver_interface/SolverFactory.h"
std::vector<std::string> tmp;

SolverFactory::SolverFactory() {
_available_solvers.clear();
if ((isXpress_available_ = LoadXpress::XpressIsCorrectlyInstalled())) {
_available_solvers.push_back(XPRESS_STR);
}
std::vector<std::string> SolverLoader::GetAvailableSolvers() {
if (tmp.empty()) {
if (LoadXpress::XpressIsCorrectlyInstalled()) {
tmp.push_back(XPRESS_STR);
}
#ifdef COIN_OR
_available_solvers.push_back(CLP_STR);
_available_solvers.push_back(CBC_STR);
tmp.push_back(CLP_STR);
tmp.push_back(CBC_STR);
#endif
}
return tmp;
}

SolverFactory::SolverFactory()
: _available_solvers(SolverLoader::GetAvailableSolvers()) {}

SolverAbstract::Ptr SolverFactory::create_solver(
const std::string &solver_name, const SOLVER_TYPE solver_type) const {
if (solver_name == "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ enum class SOLVER_TYPE { INTEGER, CONTINUOUS };
const std::string UNKNOWN_STR("UNKNOWN"), COIN_STR("COIN"), CBC_STR("CBC"),
CLP_STR("CLP"), XPRESS_STR("XPRESS");

/*!
* \class class SolverLoader
* \brief Class to check if supported solvers are available
*/
class SolverLoader {
public:
static std::vector<std::string> GetAvailableSolvers();
};

/*!
* \class class SolverFactory
* \brief Class to manage the creation of solvers from the different
Expand All @@ -31,9 +40,8 @@ class SolverFactory {
* @param solver_name : Name of the solver to use
*/
SolverAbstract::Ptr create_solver(const std::string &solver_name) const;
SolverAbstract::Ptr create_solver(
const std::string &solver_name,
SolverLogManager&log_manager) const;
SolverAbstract::Ptr create_solver(const std::string &solver_name,
SolverLogManager &log_manager) const;

/**
* @brief Creates and returns to an object solver from the wanted
Expand All @@ -44,9 +52,9 @@ class SolverFactory {
*/
SolverAbstract::Ptr create_solver(const std::string &solver_name,
const SOLVER_TYPE solver_type) const;
SolverAbstract::Ptr create_solver(
const std::string &solver_name, const SOLVER_TYPE solver_type,
SolverLogManager&log_manager) const;
SolverAbstract::Ptr create_solver(const std::string &solver_name,
const SOLVER_TYPE solver_type,
SolverLogManager &log_manager) const;

/**
* @brief Copy constructor : Creates and returns to an object solver from the
Expand All @@ -63,5 +71,5 @@ class SolverFactory {
*/
const std::vector<std::string> &get_solvers_list() const;

bool isXpress_available_ = false;
bool isXpress_available_ = false;
};

0 comments on commit dd28db3

Please sign in to comment.