@@ -412,26 +412,10 @@ MPSolver::MPSolver(const std::string& name,
412412
413413MPSolver::~MPSolver () { Clear (); }
414414
415- extern bool GurobiIsCorrectlyInstalled ();
416- extern bool XpressIsCorrectlyInstalled ();
417-
418415// static
419416bool MPSolver::SupportsProblemType (OptimizationProblemType problem_type) {
420- if (!MPSolverInterfaceFactoryRepository::GetInstance ()->Supports (
421- problem_type)) {
422- return false ;
423- }
424- switch (problem_type) {
425- case GUROBI_LINEAR_PROGRAMMING :
426- case GUROBI_MIXED_INTEGER_PROGRAMMING :
427- return GurobiIsCorrectlyInstalled ();
428- case XPRESS_LINEAR_PROGRAMMING :
429- case XPRESS_MIXED_INTEGER_PROGRAMMING :
430- return XpressIsCorrectlyInstalled ();
431- default :
432- break ;
433- }
434- return true ;
417+ return MPSolverInterfaceFactoryRepository::GetInstance ()->Supports (
418+ problem_type);
435419}
436420
437421// TODO(user): post c++ 14, instead use
@@ -2238,9 +2222,14 @@ MPSolverInterfaceFactoryRepository::~MPSolverInterfaceFactoryRepository() {
22382222
22392223void MPSolverInterfaceFactoryRepository::Register (
22402224 MPSolverInterfaceFactory factory,
2241- MPSolver::OptimizationProblemType problem_type) {
2225+ MPSolver::OptimizationProblemType problem_type,
2226+ std::function<bool ()> is_runtime_ready) {
22422227 absl::MutexLock lock (mutex_);
2243- map_[problem_type] = std::move (factory);
2228+ if (!is_runtime_ready) is_runtime_ready = []() { return true ; };
2229+ map_[problem_type] = Entry{
2230+ .factory = std::move (factory),
2231+ .is_runtime_ready = std::move (is_runtime_ready),
2232+ };
22442233}
22452234
22462235bool MPSolverInterfaceFactoryRepository::Unregister (
@@ -2252,17 +2241,20 @@ bool MPSolverInterfaceFactoryRepository::Unregister(
22522241MPSolverInterface* MPSolverInterfaceFactoryRepository::Create (
22532242 MPSolver* solver) const {
22542243 absl::MutexLock lock (mutex_);
2255- const MPSolverInterfaceFactory factory =
2256- gtl::FindWithDefault (map_, solver->ProblemType (), nullptr );
2257- if (!factory) {
2258- return nullptr ;
2259- }
2260- return factory (solver);
2244+ const Entry* entry = gtl::FindOrNull (map_, solver->ProblemType ());
2245+ CHECK (entry != nullptr ) << " No factory registered for problem type "
2246+ << ToString (solver->ProblemType ());
2247+ CHECK (entry->is_runtime_ready ())
2248+ << " Solver for problem type " << ToString (solver->ProblemType ())
2249+ << " is not ready." ;
2250+ return entry->factory (solver);
22612251}
22622252
22632253bool MPSolverInterfaceFactoryRepository::Supports (
22642254 MPSolver::OptimizationProblemType problem_type) const {
2265- return map_.count (problem_type) > 0 ;
2255+ const Entry* entry = gtl::FindOrNull (map_, problem_type);
2256+ if (entry == nullptr ) return false ;
2257+ return entry->is_runtime_ready ();
22662258}
22672259
22682260std::vector<MPSolver::OptimizationProblemType>
0 commit comments