NOMAD Source  Version 4.0.0 Beta
Iteration.hpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------*/
2 /* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
3 /* */
4 /* NOMAD - Version 4.0.0 has been created by */
5 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
6 /* Christophe Tribes - Polytechnique Montreal */
7 /* */
8 /* The copyright of NOMAD - version 4.0.0 is owned by */
9 /* Charles Audet - Polytechnique Montreal */
10 /* Sebastien Le Digabel - Polytechnique Montreal */
11 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
12 /* Christophe Tribes - Polytechnique Montreal */
13 /* */
14 /* NOMAD v4 has been funded by Rio Tinto, Hydro-Québec, NSERC (Natural */
15 /* Sciences and Engineering Research Council of Canada), InnovÉÉ (Innovation */
16 /* en Énergie Électrique) and IVADO (The Institute for Data Valorization) */
17 /* */
18 /* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
19 /* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
20 /* and Exxon Mobil. */
21 /* */
22 /* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
23 /* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
24 /* Exxon Mobil. */
25 /* */
26 /* Contact information: */
27 /* Polytechnique Montreal - GERAD */
28 /* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
29 /* e-mail: nomad@gerad.ca */
30 /* */
31 /* This program is free software: you can redistribute it and/or modify it */
32 /* under the terms of the GNU Lesser General Public License as published by */
33 /* the Free Software Foundation, either version 3 of the License, or (at your */
34 /* option) any later version. */
35 /* */
36 /* This program is distributed in the hope that it will be useful, but WITHOUT */
37 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
38 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License */
39 /* for more details. */
40 /* */
41 /* You should have received a copy of the GNU Lesser General Public License */
42 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
43 /* */
44 /* You can find information on the NOMAD software at www.gerad.ca/nomad */
45 /*---------------------------------------------------------------------------------*/
46 #ifndef __NOMAD400_ITERATION__
47 #define __NOMAD400_ITERATION__
48 
49 #include "../Algos/Step.hpp"
50 
51 #include "../nomad_nsbegin.hpp"
52 
53 /// Class for iteration of an Algorithm.
54 /**
55  This is an abstract class, each algorithm must implement its own iteration.
56  */
57 class Iteration: public Step
58 {
59 protected:
60 
61  size_t _k; ///< Iteration number
62 
63  void init(); ///< Utility for constructor
64 
65 public:
66  /// Constructor
67  /**
68  \param parentStep The parent of this step -- \b IN.
69  \param k The iteration number -- \b IN.
70  */
71  explicit Iteration(const Step *parentStep,
72  const size_t k)
73  : Step( parentStep ),
74  _k(k)
75  {
76  init();
77  }
78 
79  /// Destructor
80  /**
81  When iteration is done, Flush prints output queue.
82  */
83  virtual ~Iteration();
84 
85  // Get/Set
86 
87  /// Get iteration number
88  /**
89  Iteration number is incremented when calling the default Iteration::start().
90  */
91  size_t getK() const { return _k; }
92 
93  /// Increment iteration number by one
94  /// To be used only when a single Iteration is used over and over, e.g. Nelder Mead
95  void incK() { _k++; }
96 
97  /**
98  \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).
99  */
100  virtual const std::shared_ptr<MeshBase> getMesh() const { return nullptr; }
101 
102  /**
103  \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, ...).
104  */
105  virtual const std::shared_ptr<EvalPoint> getFrameCenter() const { return nullptr; }
106 
107 protected:
108 
109  /**
110  This must be implemented when an algorithm has its own iteration.
111  */
112  virtual void startImp() override = 0;
113 
114  /**
115  This must be implemented when an algorithm has its own iteration.
116  */
117  virtual bool runImp() override = 0;
118 
119  /**
120  The default implement for end function displays the stop reason and calls the customized end function if provided by the user. \n
121  If an end implementation function specific to an algorithm is required, it is convenient to call this function for default task.
122  */
123  virtual void endImp() override;
124 
125  /**
126  \return \c true if this Iteration is considered the principal iteration of its parent MegaIteration.
127  By default, return true.
128  */
129  virtual bool isMainIteration() const { return true; }
130 
131 };
132 
133 #include "../nomad_nsend.hpp"
134 
135 #endif // __NOMAD400_ITERATION__
Iteration::_k
size_t _k
Iteration number.
Definition: Iteration.hpp:61
Iteration::init
void init()
Utility for constructor.
Iteration
Class for iteration of an Algorithm.
Definition: Iteration.hpp:57
Iteration::~Iteration
virtual ~Iteration()
Destructor.
Step
Base class of all types of steps (Iteration, Termination, Initialization, Poll, Mads,...
Definition: Step.hpp:68
Iteration::incK
void incK()
Definition: Iteration.hpp:95
Iteration::getMesh
virtual const std::shared_ptr< MeshBase > getMesh() const
Definition: Iteration.hpp:100
Iteration::isMainIteration
virtual bool isMainIteration() const
Definition: Iteration.hpp:129
Iteration::Iteration
Iteration(const Step *parentStep, const size_t k)
Constructor.
Definition: Iteration.hpp:71
Iteration::getK
size_t getK() const
Get iteration number.
Definition: Iteration.hpp:91
Iteration::endImp
virtual void endImp() override
Iteration::runImp
virtual bool runImp() override=0
Iteration::getFrameCenter
virtual const std::shared_ptr< EvalPoint > getFrameCenter() const
Definition: Iteration.hpp:105
Iteration::startImp
virtual void startImp() override=0