26#ifndef UTILS_HJ_PATTERN_SEARCH_dot_HH
27#define UTILS_HJ_PATTERN_SEARCH_dot_HH
169 template <
typename Real>
171 using Vec_t = Eigen::Matrix<Real,Eigen::Dynamic,1>;
172 using MapVec = Eigen::Map<Vec_t>;
174 using HJFunc = std::function<Real(Real
const[])>;
182 Console const * m_console{
nullptr};
184 Real m_rho{Real(0.9)};
186 bool m_stencil_failure{
false};
190 MapVec m_x_old{
nullptr,0};
191 MapVec m_x_best{
nullptr,0};
195 MapVec m_dir{
nullptr,0};
196 MapVec m_search_sign{
nullptr,0};
198 MapVec m_p{
nullptr,0};
199 MapVec m_p1{
nullptr,0};
200 MapVec m_new_x{
nullptr,0};
202 Real m_tolerance{Real(1e-8)};
203 integer m_max_iteration{500};
204 integer m_max_fun_evaluation{1000};
205 integer m_max_num_stagnation{10};
206 integer m_verbose{1};
208 integer m_iteration_count;
209 integer m_fun_evaluation_count;
211 void allocate( integer n );
215 eval_function( MapVec
const & x )
const
216 { ++m_fun_evaluation;
return m_fun( x.data() ); }
218 mutable integer m_fun_evaluation;
238 string_view
name(
void)
const {
return m_name; }
247 void setup( integer dim, HJFunc & fun,
Console const * console );
325 void run( Real
const x_sol[], Real h );
335 { std::copy_n( m_x_best.data(), m_dim, x );
return m_f_best; }
Class to handle console output with different styles and levels.
Definition Console.hxx:52
void set_tolerance(Real tol)
Sets the convergence tolerance.
Definition Utils_HJPatternSearch.cc:34
void set_max_fun_evaluation(integer mfev)
Sets the maximum number of function evaluations.
Definition Utils_HJPatternSearch.cc:58
void change_console(Console const *console)
Changes the console used for output messages.
Definition Utils_HJPatternSearch.hh:254
HJPatternSearch(string_view name)
Constructs a Hooke-Jeeves Pattern Search instance.
Definition Utils_HJPatternSearch.hh:228
void setup(integer dim, HJFunc &fun, Console const *console)
Sets up the pattern search with the specified dimension and objective function.
Definition Utils_HJPatternSearch.cc:102
Real get_last_solution(Real x[]) const
Retrieves the last solution found by the algorithm.
Definition Utils_HJPatternSearch.hh:334
string_view name(void) const
Retrieves the name of the pattern search instance.
Definition Utils_HJPatternSearch.hh:238
void run(Real const x_sol[], Real h)
Runs the optimization algorithm starting from the provided solution.
Definition Utils_HJPatternSearch.cc:254
void set_max_iterations(integer mit)
Sets the maximum number of iterations.
Definition Utils_HJPatternSearch.cc:46
string info() const
Provides information about the current state of the algorithm.
Definition Utils_HJPatternSearch.cc:116
void search()
Performs the main search algorithm.
Definition Utils_HJPatternSearch.cc:147
void best_nearby()
Searches for the best nearby solution.
Definition Utils_HJPatternSearch.cc:211
void set_verbose(integer level)
Sets the verbosity level for output messages.
Definition Utils_HJPatternSearch.hh:261
void print_info(ostream_type &stream) const
Prints the current state information to the specified output stream.
Definition Utils_HJPatternSearch.hh:303
void set_max_num_stagnation(integer nstg)
Sets the maximum number of allowed stagnation iterations.
Definition Utils_HJPatternSearch.cc:70
Class for dynamic memory allocation of objects.
Definition Malloc.hxx:79
Definition SystemUtils.cc:39
std::basic_ostream< char > ostream_type
Type for output stream.
Definition Console.hxx:28
std::string string
Type for string.
Definition Console.hxx:29