21 #ifndef SELDON_COMPUTATION_OPTIMIZATION_NLOPTSOLVER_CXX
22 #define SELDON_COMPUTATION_OPTIMIZATION_NLOPTSOLVER_CXX
25 #include "NLoptSolver.hxx"
73 double parameter_tolerance,
74 double cost_function_tolerance,
77 map<string, nlopt::algorithm> algorithm_map;
78 map<string, nlopt::algorithm>::iterator it;
79 algorithm_map[
"GN_DIRECT"] = nlopt::GN_DIRECT;
80 algorithm_map[
"GN_DIRECT_L"] = nlopt::GN_DIRECT_L;
81 algorithm_map[
"GN_DIRECT_L_RAND"] = nlopt::GN_DIRECT_L_RAND;
82 algorithm_map[
"GN_DIRECT_NOSCAL"] = nlopt::GN_DIRECT_NOSCAL;
83 algorithm_map[
"GN_DIRECT_L_NOSCAL"] = nlopt::GN_DIRECT_L_NOSCAL;
84 algorithm_map[
"GN_DIRECT_L_RAND_NOSCAL"]
85 = nlopt::GN_DIRECT_L_RAND_NOSCAL;
86 algorithm_map[
"GN_ORIG_DIRECT"] = nlopt::GN_ORIG_DIRECT;
87 algorithm_map[
"GN_ORIG_DIRECT_L"] = nlopt::GN_ORIG_DIRECT_L;
88 algorithm_map[
"GD_STOGO"] = nlopt::GD_STOGO;
89 algorithm_map[
"GD_STOGO_RAND"] = nlopt::GD_STOGO_RAND;
90 algorithm_map[
"LD_LBFGS_NOCEDAL"] = nlopt::LD_LBFGS_NOCEDAL;
91 algorithm_map[
"LD_LBFGS"] = nlopt::LD_LBFGS;
92 algorithm_map[
"LN_PRAXIS"] = nlopt::LN_PRAXIS;
93 algorithm_map[
"LD_VAR1"] = nlopt::LD_VAR1;
94 algorithm_map[
"LD_VAR2"] = nlopt::LD_VAR2;
95 algorithm_map[
"LD_TNEWTON"] = nlopt::LD_TNEWTON;
96 algorithm_map[
"LD_TNEWTON_RESTART"] = nlopt::LD_TNEWTON_RESTART;
97 algorithm_map[
"LD_TNEWTON_PRECOND"] = nlopt::LD_TNEWTON_PRECOND;
98 algorithm_map[
"LD_TNEWTON_PRECOND_RESTART"]
99 = nlopt::LD_TNEWTON_PRECOND_RESTART;
100 algorithm_map[
"GN_CRS2_LM"] = nlopt::GN_CRS2_LM;
101 algorithm_map[
"GN_MLSL"] = nlopt::GN_MLSL;
102 algorithm_map[
"GD_MLSL"] = nlopt::GD_MLSL;
103 algorithm_map[
"GN_MLSL_LDS"] = nlopt::GN_MLSL_LDS;
104 algorithm_map[
"GD_MLSL_LDS"] = nlopt::GD_MLSL_LDS;
105 algorithm_map[
"LD_MMA"] = nlopt::LD_MMA;
106 algorithm_map[
"LN_COBYLA"] = nlopt::LN_COBYLA;
107 algorithm_map[
"LN_NEWUOA"] = nlopt::LN_NEWUOA;
108 algorithm_map[
"LN_NEWUOA_BOUND"] = nlopt::LN_NEWUOA_BOUND;
109 algorithm_map[
"LN_NELDERMEAD"] = nlopt::LN_NELDERMEAD;
110 algorithm_map[
"LN_SBPLX"] = nlopt::LN_SBPLX;
111 algorithm_map[
"LN_AUGLAG"] = nlopt::LN_AUGLAG;
112 algorithm_map[
"LD_AUGLAG"] = nlopt::LD_AUGLAG;
113 algorithm_map[
"LN_AUGLAG_EQ"] = nlopt::LN_AUGLAG_EQ;
114 algorithm_map[
"LD_AUGLAG_EQ"] = nlopt::LD_AUGLAG_EQ;
115 algorithm_map[
"LN_BOBYQA"] = nlopt::LN_BOBYQA;
116 algorithm_map[
"GN_ISRES"] = nlopt::GN_ISRES;
117 algorithm_map[
"AUGLAG"] = nlopt::AUGLAG;
118 algorithm_map[
"AUGLAG_EQ"] = nlopt::AUGLAG_EQ;
119 algorithm_map[
"G_MLSL"] = nlopt::G_MLSL;
120 algorithm_map[
"G_MLSL_LDS"] = nlopt::G_MLSL_LDS;
121 algorithm_map[
"LD_SLSQP"] = nlopt::LD_SLSQP;
123 it = algorithm_map.find(algorithm);
124 if (it == algorithm_map.end())
125 WrongArgument(
"void NLoptSolver::Initialize(int, string, double)",
126 "Unknown algorithm. Implemented algorithms are:"
128 "GN_DIRECT_L, GN_DIRECT_L_RAND, "
130 "GN_DIRECT_L_NOSCAL, GN_DIRECT_L_RAND_NOSCAL,"
132 "GN_ORIG_DIRECT_L, GD_STOGO, GD_STOGO_RAND, "
133 "LD_LBFGS_NOCEDAL, LD_LBFGS, LN_PRAXIS, "
134 "LD_VAR1, LD_VAR2, LD_TNEWTON, "
135 "LD_TNEWTON_RESTART, LD_TNEWTON_PRECOND, "
136 "LD_TNEWTON_PRECOND_RESTART, GN_CRS2_LM, "
138 "GD_MLSL, GN_MLSL_LDS, GD_MLSL_LDS, "
139 "LD_MMA, LN_COBYLA, LN_NEWUOA, "
140 "LN_NEWUOA_BOUND, LN_NELDERMEAD, "
141 "LN_SBPLX, LN_AUGLAG, LD_AUGLAG, "
142 "LN_AUGLAG_EQ, LD_AUGLAG_EQ, LN_BOBYQA, "
143 "GN_ISRES, AUGLAG, AUGLAG_EQ,"
144 "G_MLSL, G_MLSL_LDS, LD_SLSQP, NUM_ALGORITHMS");
164 if (lower_bound.GetSize() != 0)
165 opt_.set_lower_bounds(lower_bound);
175 if (upper_bound.GetSize() != 0)
176 opt_.set_upper_bounds(upper_bound);
298 "The vector of parameters to be optimized"
301 opt_.set_min_objective(cost, argument);
308 throw Error(
"NLoptSolver::Optimize()",
"Nlopt failed.");
void GetParameter(Vector< double > ¶meter) const
Gets the parameters.
void GetParameterTolerance(double &) const
Gets the relative tolerance on the parameters.
double cost_function_tolerance_
Relative tolerance on the cost function.
void GetCostFunctionTolerance(double &) const
Gets the relative tolerance on the cost function.
void SetCostFunctionTolerance(double)
Sets the relative tolerance on the cost function.
void SetLowerBound(const Vector< double > &)
Sets lower bounds on the parameters.
void SetParameterTolerance(double)
Sets the relative tolerance on the parameters.
~NLoptSolver()
Destructor.
nlopt::SeldonOpt opt_
NLopt optimization solver.
void Optimize(cost_ptr cost, void *argument)
Optimization.
void GetNiterationMax(int &) const
Gets the maximum number of cost function evaluations.
void SetParameter(const Vector< double > ¶meter)
Sets the parameters.
double GetCost() const
Returns the value of the cost function.
void SetUpperBound(const Vector< double > &)
Sets upper bounds on the parameters.
NLoptSolver()
Default constructor.
double cost_
The value of cost function for given parameter values.
double parameter_tolerance_
Relative tolerance on the optimization parameters.
void SetNiterationMax(int)
Sets the maximum number of cost function evaluations.
Vector< double > parameter_
The vector that stores parameters values. Before optimization, stores the initial parameter vector; a...
nlopt::algorithm algorithm_
Optimization algorithm.
void Initialize(int Nparameter, string algorithm, double parameter_tolerance=1.e-6, double cost_function_tolerance=1.e-6, int Niteration_max=-1)
Initializations.
int Niteration_max_
Maximum number of function evaluations. It is ignored if it is non-positive.