Commit 9c198e40 authored by Patric Schmitz's avatar Patric Schmitz

IPOPTSolverLean: refactoring default option initialization

parent a7785eca
...@@ -35,69 +35,78 @@ namespace COMISO { ...@@ -35,69 +35,78 @@ namespace COMISO {
//== IMPLEMENTATION =========================================================== //== IMPLEMENTATION ===========================================================
// smart pointer to IpoptApplication to set options etc.
class IPOPTSolverLean::Impl class IPOPTSolverLean::Impl
{// Create an instance of the IpoptApplication {
public: public:
Impl() Impl()
: app_(IpoptApplicationFactory()), max_iter_(200), alm_infsb_thrsh_(0.5), : app_(IpoptApplicationFactory()), // Create an instance of IpoptApplication
incr_lazy_cnstr_max_iter_nmbr_(5), enbl_all_lzy_cnstr_(true) alm_infsb_thrsh_(0.5),
{} incr_lazy_cnstr_max_iter_nmbr_(5),
enbl_all_lzy_cnstr_(true)
{
setup_ipopt_defaults();
}
private:
void setup_ipopt_defaults();
public: public:
Ipopt::SmartPtr<Ipopt::IpoptApplication> app_; Ipopt::SmartPtr<Ipopt::IpoptApplication> app_;
int max_iter_;
double alm_infsb_thrsh_; double alm_infsb_thrsh_;
int incr_lazy_cnstr_max_iter_nmbr_; int incr_lazy_cnstr_max_iter_nmbr_;
bool enbl_all_lzy_cnstr_; bool enbl_all_lzy_cnstr_;
private:
// default ipopt options
static const std::string ipopt_default_hsl_solver;
static const int ipopt_default_max_iter;
static const int ipopt_default_mumps_mem_percent;
}; };
// Constructor const std::string IPOPTSolverLean::Impl::ipopt_default_hsl_solver = "ma57";
IPOPTSolverLean::IPOPTSolverLean() const int IPOPTSolverLean::Impl::ipopt_default_max_iter = 200;
: impl_(new Impl) const int IPOPTSolverLean::Impl::ipopt_default_mumps_mem_percent = 5;
{
void IPOPTSolverLean::Impl::setup_ipopt_defaults()
{
// Switch to HSL if available // Switch to HSL if available
#if COMISO_HSL_AVAILABLE #if COMISO_HSL_AVAILABLE
impl_->app_->Options()->SetStringValue("linear_solver", "ma57"); app_->Options()->SetStringValue("linear_solver", ipopt_default_hsl_solver);
#else #else
impl_->app_->Options()->SetStringValue("linear_solver", "mumps"); app_->Options()->SetStringValue("linear_solver", "mumps");
#endif #endif
#ifdef DEB_ON #ifdef DEB_ON
if (!Debug::Config::query().console()) if (!Debug::Config::query().console())
#endif #endif
{// Block any output on cout and cerr from Ipopt. {// Block any output on cout and cerr from Ipopt.
impl_->app_->Options()->SetStringValue("suppress_all_output", "yes"); app_->Options()->SetStringValue("suppress_all_output", "yes");
} }
#ifdef WIN32 #ifdef WIN32
// Restrict memory to be able to run larger problems on windows // Restrict memory to be able to run larger problems on windows
// with the default mumps solver // with the default mumps solver
// TODO: find out what this does and whether it makes sense to do it // TODO: find out what this does and whether it makes sense to do it
impl_->app_->Options()->SetIntegerValue("mumps_mem_percent", 5); app_->Options()->SetIntegerValue("mumps_mem_percent",
ipopt_default_mumps_mem_percent);
#endif #endif
// set default parameters // set max iterations
impl_->app_->Options()->SetIntegerValue("max_iter", 100); app_->Options()->SetIntegerValue("max_iter", ipopt_default_max_iter);
// app->Options()->SetStringValue("derivative_test", "second-order"); }
// app->Options()->SetIntegerValue("print_level", 0);
// app->Options()->SetStringValue("expect_infeasible_problem", "yes"); // Constructor
IPOPTSolverLean::IPOPTSolverLean()
: impl_(new Impl)
{
} }
IPOPTSolverLean:: IPOPTSolverLean::
~IPOPTSolverLean() ~IPOPTSolverLean()
{ delete impl_; } { delete impl_; }
double
IPOPTSolverLean::
energy()
{
return impl_->app_->Statistics()->FinalObjective();
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
...@@ -105,14 +114,16 @@ IPOPTSolverLean:: ...@@ -105,14 +114,16 @@ IPOPTSolverLean::
set_max_iterations set_max_iterations
(const int _max_iterations) (const int _max_iterations)
{ {
impl_->max_iter_ = _max_iterations; impl_->app_->Options()->SetIntegerValue("max_iter", _max_iterations);
} }
int int
IPOPTSolverLean:: IPOPTSolverLean::
max_iterations() const max_iterations() const
{ {
return impl_->max_iter_; int max_iter;
impl_->app_->Options()->GetIntegerValue("max_iter", max_iter, "");
return max_iter;
} }
double double
...@@ -160,8 +171,6 @@ set_enable_all_lazy_contraints ...@@ -160,8 +171,6 @@ set_enable_all_lazy_contraints
impl_->enbl_all_lzy_cnstr_ = _enbl_all_lzy_cnstr; impl_->enbl_all_lzy_cnstr_ = _enbl_all_lzy_cnstr;
} }
//-----------------------------------------------------------------------------
static void static void
throw_ipopt_solve_failure throw_ipopt_solve_failure
(Ipopt::ApplicationReturnStatus const status) (Ipopt::ApplicationReturnStatus const status)
...@@ -278,10 +287,6 @@ solve ...@@ -278,10 +287,6 @@ solve
<< final_obj << "\n"); << final_obj << "\n");
} }
//-----------------------------------------------------------------------------
void void
IPOPTSolverLean:: IPOPTSolverLean::
solve solve
...@@ -313,9 +318,6 @@ solve ...@@ -313,9 +318,6 @@ solve
std::vector<int> n_inf; std::vector<int> n_inf;
std::vector<int> n_almost_inf; std::vector<int> n_almost_inf;
// set max iterations
impl_->app_->Options()->SetIntegerValue("max_iter", impl_->max_iter_);
while(!feasible_point_found && cur_pass < max_passes) while(!feasible_point_found && cur_pass < max_passes)
{ {
++cur_pass; ++cur_pass;
...@@ -498,9 +500,6 @@ solve ...@@ -498,9 +500,6 @@ solve
<< " infeasible and " << n_almost_inf[i] << " almost infeasible\n") << " infeasible and " << n_almost_inf[i] << " almost infeasible\n")
} }
//-----------------------------------------------------------------------------
void void
IPOPTSolverLean:: IPOPTSolverLean::
solve(NProblemInterface* _problem) solve(NProblemInterface* _problem)
...@@ -509,6 +508,13 @@ solve(NProblemInterface* _problem) ...@@ -509,6 +508,13 @@ solve(NProblemInterface* _problem)
solve(_problem, constraints); solve(_problem, constraints);
} }
double
IPOPTSolverLean::
energy()
{
return impl_->app_->Statistics()->FinalObjective();
}
//============================================================================= //=============================================================================
} // namespace COMISO } // namespace COMISO
//============================================================================= //=============================================================================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment