Commit 3379e99e authored by Patric Schmitz's avatar Patric Schmitz

IPOPTSolverLean: add (opaque) methods to get and set solver options

APICHG: rename getters to use get_ consistently
parent 21e3c851
......@@ -47,6 +47,13 @@ public:
setup_ipopt_defaults();
}
void set_ipopt_option(std::string, int);
void set_ipopt_option(std::string, double);
void set_ipopt_option(std::string, std::string);
template <typename T>
T get_ipopt_option(std::string);
private:
void setup_ipopt_defaults();
......@@ -68,36 +75,94 @@ const std::string IPOPTSolverLean::Impl::ipopt_default_hsl_solver = "ma57";
const int IPOPTSolverLean::Impl::ipopt_default_max_iter = 200;
const int IPOPTSolverLean::Impl::ipopt_default_mumps_mem_percent = 5;
void
IPOPTSolverLean::Impl::
set_ipopt_option
(std::string option, int value)
{
app_->Options()->SetIntegerValue(option, value);
}
void
IPOPTSolverLean::Impl::
set_ipopt_option
(std::string option, double value)
{
app_->Options()->SetNumericValue(option, value);
}
void
IPOPTSolverLean::Impl::
set_ipopt_option
(std::string option, std::string value)
{
app_->Options()->SetStringValue(option, value);
}
template <typename T> T
IPOPTSolverLean::Impl::
get_ipopt_option(std::string)
{
// @TODO print warning about unsupported option type!
}
template <> int
IPOPTSolverLean::Impl::
get_ipopt_option<int>(std::string option)
{
int value;
app_->Options()->GetIntegerValue(option, value, "");
return value;
}
template <> double
IPOPTSolverLean::Impl::
get_ipopt_option<double>(std::string option)
{
double value;
app_->Options()->GetNumericValue(option, value, "");
return value;
}
template <> std::string
IPOPTSolverLean::Impl::
get_ipopt_option<std::string>(std::string option)
{
std::string value;
app_->Options()->GetStringValue(option, value, "");
return value;
}
void IPOPTSolverLean::Impl::setup_ipopt_defaults()
{
// Switch to HSL if available
#if COMISO_HSL_AVAILABLE
app_->Options()->SetStringValue("linear_solver", ipopt_default_hsl_solver);
set_ipopt_option("linear_solver", ipopt_default_hsl_solver);
#else
app_->Options()->SetStringValue("linear_solver", "mumps");
set_ipopt_option("linear_solver", "mumps");
#endif
#ifdef DEB_ON
if (!Debug::Config::query().console())
#endif
{// Block any output on cout and cerr from Ipopt.
app_->Options()->SetStringValue("suppress_all_output", "yes");
set_ipopt_option("suppress_all_output", "yes");
}
#ifdef WIN32
// Restrict memory to be able to run larger problems on windows
// with the default mumps solver
// TODO: find out what this does and whether it makes sense to do it
app_->Options()->SetIntegerValue("mumps_mem_percent",
ipopt_default_mumps_mem_percent);
set_ipopt_option("mumps_mem_percent",
ipopt_default_mumps_mem_percent);
#endif
// set max iterations
app_->Options()->SetIntegerValue("max_iter", ipopt_default_max_iter);
// set maximum solver iterations
set_ipopt_option("max_iter", ipopt_default_max_iter);
}
// Constructor
//-----------------------------------------------------------------------------
IPOPTSolverLean::IPOPTSolverLean()
: impl_(new Impl)
{
......@@ -105,32 +170,39 @@ IPOPTSolverLean::IPOPTSolverLean()
IPOPTSolverLean::
~IPOPTSolverLean()
{ delete impl_; }
//-----------------------------------------------------------------------------
{
delete impl_;
}
template <typename T>
void
IPOPTSolverLean::
set_max_iterations
(const int _max_iterations)
set_ipopt_option
(std::string option, const T& value)
{
impl_->app_->Options()->SetIntegerValue("max_iter", _max_iterations);
impl_->set_ipopt_option(option, value);
}
int
template <typename T> T
IPOPTSolverLean::
max_iterations() const
get_ipopt_option(std::string option)
{
int max_iter;
impl_->app_->Options()->GetIntegerValue("max_iter", max_iter, "");
return max_iter;
return impl_->get_ipopt_option<T>(option);
}
double
void
IPOPTSolverLean::
almost_infeasible_threshold() const
set_max_iterations
(const int _max_iterations)
{
return impl_->alm_infsb_thrsh_;
impl_->set_ipopt_option("max_iter", _max_iterations);
}
int
IPOPTSolverLean::
get_max_iterations() const
{
return impl_->get_ipopt_option<int>("max_iter");
}
void
......@@ -141,11 +213,11 @@ set_almost_infeasible_threshold
impl_->alm_infsb_thrsh_ = _alm_infsb_thrsh;
}
int
double
IPOPTSolverLean::
incremental_lazy_constraint_max_iteration_number() const
get_almost_infeasible_threshold() const
{
return impl_->incr_lazy_cnstr_max_iter_nmbr_;
return impl_->alm_infsb_thrsh_;
}
void
......@@ -156,11 +228,11 @@ set_incremental_lazy_constraint_max_iteration_number
impl_->incr_lazy_cnstr_max_iter_nmbr_ = _incr_lazy_cnstr_max_iter_nmbr;
}
bool
int
IPOPTSolverLean::
enable_all_lazy_contraints() const
get_incremental_lazy_constraint_max_iteration_number() const
{
return impl_->enbl_all_lzy_cnstr_;
return impl_->incr_lazy_cnstr_max_iter_nmbr_;
}
void
......@@ -171,6 +243,13 @@ set_enable_all_lazy_contraints
impl_->enbl_all_lzy_cnstr_ = _enbl_all_lzy_cnstr;
}
bool
IPOPTSolverLean::
get_enable_all_lazy_contraints() const
{
return impl_->enbl_all_lzy_cnstr_;
}
static void
throw_ipopt_solve_failure
(Ipopt::ApplicationReturnStatus const status)
......
......@@ -13,10 +13,11 @@
#if COMISO_IPOPT_AVAILABLE
//== INCLUDES =================================================================
#include <CoMISo/Config/CoMISoDefines.hh>
#include <vector>
#include <cstddef>
#include <vector>
#include <string>
#include <CoMISo/Config/CoMISoDefines.hh>
//== NAMESPACES ===============================================================
namespace COMISO {
......@@ -51,17 +52,35 @@ public:
// *********** OPTIONS **************//
/*!
Set options of the underlying ipopt solver.
For a thorough list and documentation of available options, refer
to: https://www.coin-or.org/Ipopt/documentation/node40.html
*/
template<typename T>
void set_ipopt_option(std::string option, const T& value);
/*!
Get options of the underlying ipopt solver.
The type of option {int, double, std::string} needs to be passed as
template argument.
*/
template<typename T>
T get_ipopt_option(std::string option);
/*!
Set the maximum number of iterations
*/
void set_max_iterations(const int _max_iterations);
int max_iterations() const;
int get_max_iterations() const;
/*! Set the threshold on the lazy inequality constraint to decide
if we are near the constraint boundary.
*/
void set_almost_infeasible_threshold(const double _alm_infsb_thrsh);
double almost_infeasible_threshold() const;
double get_almost_infeasible_threshold() const;
/*!
Set the max number of incremental lazy constraint iterations before switching
......@@ -70,7 +89,7 @@ public:
*/
void set_incremental_lazy_constraint_max_iteration_number
(const int _incr_lazy_cnstr_max_iter_nmbr);
int incremental_lazy_constraint_max_iteration_number() const;
int get_incremental_lazy_constraint_max_iteration_number() const;
/*
Turn on/off solving the fully constraint problem after exhausting the
......@@ -79,7 +98,7 @@ public:
\note The default value of this is true.
*/
void set_enable_all_lazy_contraints(const bool _enbl_all_lzy_cnstr);
bool enable_all_lazy_contraints() const;
bool get_enable_all_lazy_contraints() const;
// ********** SOLVE **************** //
......@@ -95,7 +114,7 @@ public:
void solve
(NProblemInterface* _problem,
const std::vector<NConstraintInterface*>& _constraints,
const std::vector<NConstraintInterface*>& _lazy_constraints);
const std::vector<NConstraintInterface*>& _lazy_constraints = {});
//! Get the computed solution energy
double energy();
......
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