NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Iteration.hpp
Go to the documentation of this file.
1 #ifndef __NOMAD400_ITERATION__
2 #define __NOMAD400_ITERATION__
3 
4 #include "../Algos/Step.hpp"
5 
6 #include "../nomad_nsbegin.hpp"
7 
8 /// Class for iteration of an Algorithm.
9 /**
10  This is an abstract class, each algorithm mus implement its own initilization.
11  */
12 class Iteration: public Step
13 {
14 protected:
15 
16  size_t _k; ///< Iteration number
17 
18  void init(); ///< Utility for constructor
19 
20 public:
21  /// Constructor
22  /**
23  \param parentStep The parent of this step -- \b IN.
24  \param k The iteration number -- \b IN.
25  */
26  explicit Iteration(const Step *parentStep,
27  const size_t k)
28  : Step( parentStep ),
29  _k(k)
30  {
31  init();
32  }
33 
34 
35  /// Destructor
36  /**
37  When iteration is done, Flush prints output queue.
38  */
39  virtual ~Iteration()
40  {
41 
43  }
44 
45  /**
46  This default start function can be called by the iteration step specific to an algorithm.
47  This allow to perform basic iteration task, such as incrementing the iteration counter or checking if parent is null.
48  */
49  virtual void start() override;
50 
51  /**
52  This must be implemented when an algorithm has its own iteration.
53  */
54  virtual bool run() override = 0;
55 
56  /**
57  The default end function displays the stop reason and calls the customized end function if provided by the user. \n
58  If an end function specific to an algorithm is required, it is convenient to call this function for basic task.
59  */
60  virtual void end() override;
61 
62  // Get/Set
63 
64  /// Get iteration number
65  /**
66  Iteration number is incremented when calling the default Iteration::start().
67  */
68  size_t getK() const { return _k; }
69 
70  /// Increment iteration number by one
71  /// To be used only when a single Iteration is used over and over, e.g. Nelder Mead
72  void incK() { _k++; }
73 
74  /**
75  \return \c nullptr for algorithms that do not use a mesh. Otherwise, this function must be reimplemented in algorithm specific iteration (for example, MadsIteration, NMIteration).
76  */
77  virtual const std::shared_ptr<MeshBase> getMesh() const { return nullptr; }
78 
79  /**
80  \return \c nullptr for algorithms that do not use a frame center. Otherwise, this function must be reimplemented in algorithm specific iteration (for example, MadsIteration, NMIteration).
81  */
82  virtual const std::shared_ptr<EvalPoint> getFrameCenter() const { return nullptr; }
83 
84 };
85 
86 #include "../nomad_nsend.hpp"
87 
88 #endif // __NOMAD400_ITERATION__
virtual const std::shared_ptr< MeshBase > getMesh() const
Definition: Iteration.hpp:77
virtual void start() override
virtual bool run() override=0
size_t _k
Iteration number.
Definition: Iteration.hpp:16
void init()
Utility for constructor.
Class for iteration of an Algorithm.
Definition: Iteration.hpp:12
Base class of all types of steps (Iteration, Termination, Initialization, Poll, Mads,...).
Definition: Step.hpp:24
virtual ~Iteration()
Destructor.
Definition: Iteration.hpp:39
void incK()
Definition: Iteration.hpp:72
virtual void end() override
virtual const std::shared_ptr< EvalPoint > getFrameCenter() const
Definition: Iteration.hpp:82
size_t getK() const
Get iteration number.
Definition: Iteration.hpp:68
static void Flush()
Definition: OutputQueue.hpp:74
Iteration(const Step *parentStep, const size_t k)
Constructor.
Definition: Iteration.hpp:26