NOMAD Source  Version 4.0.0 Beta
MadsIteration.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_MADSITERATION__
47 #define __NOMAD400_MADSITERATION__
48 
49 #include "../../Algos/Iteration.hpp"
50 #include "../../Algos/MeshBase.hpp"
51 #include "../../Eval/EvalPoint.hpp"
52 
53 #include "../../nomad_nsbegin.hpp"
54 
55 /// Class for MADS iteration
56 /**
57  A MADS iteration consists of a Search step followed by a Poll step depending on the stop reasons and successes.
58  */
59 class MadsIteration: public Iteration
60 {
61 private:
62  const std::shared_ptr<EvalPoint> _frameCenter; ///< Center around which the points are generated
63  const std::shared_ptr<MeshBase> _mesh; ///< Mesh on which the points are
64  SuccessType _success; ///< Success type of this iteration
65 
66 #ifdef TIME_STATS
67  /// Time counters
68  static double _iterTime; ///< Total time spent running this class
69  static double _searchTime; ///< Total time spent running searches
70  static double _searchEvalTime; ///< Total time spent evaluating search points
71  static double _pollTime; ///< Total time spent running polls
72  static double _pollEvalTime; ///< Total time spent evaluating poll points
73  double _iterStartTime; ///< Time at which the start method was called
74 #endif // TIME_STATS
75 
76 public:
77  /// Constructor
78  /**
79  \param parentStep The parent of this step -- \b IN.
80  \param frameCenter Frame center of this iteration -- \b IN.
81  \param k The iteration number -- \b IN.
82  \param mesh The mesh of the iteration -- \b IN.
83  */
84  explicit MadsIteration(const Step *parentStep,
85  const std::shared_ptr<EvalPoint>& frameCenter,
86  const size_t k,
87  const std::shared_ptr<MeshBase> mesh)
88  : Iteration(parentStep, k),
89  _frameCenter(frameCenter),
90  _mesh(mesh),
92 #ifdef TIME_STATS
93  ,_iterStartTime(0.0)
94 #endif // TIME_STATS
95  {
96  init();
97  }
98 
99 
100  // Gets/Sets
101 
102  /**
103  The Mads algorithm iteration possesses a frame center, unlike the base iteration that has none.
104  \remark Used by Step::getIterationFrameCenter() to pass the frame center whenever needed
105  */
106  const std::shared_ptr<EvalPoint> getFrameCenter() const override { return _frameCenter; }
107 
108  /**
109  The Mads algorithm iteration possesses a mesh, unlike the base iteration that has none.
110  \remark Used by Step::getIterationMesh() to pass the mesh whenever needed
111  */
112  const std::shared_ptr<MeshBase> getMesh() const override { return _mesh; }
113 
114  /// Return current SuccessType
115  const SuccessType& getSuccessType() const { return _success; }
116 
117  /// Set SuccessType member
118  void setSuccessType(const SuccessType& success) { _success = success; }
119 
120 #ifdef TIME_STATS
121  /// Time stats
122  static double getIterTime() { return _iterTime; }
123  static double getSearchTime() { return _searchTime; }
124  static double getSearchEvalTime() { return _searchEvalTime; }
125  static double getPollTime() { return _pollTime; }
126  static double getPollEvalTime() { return _pollEvalTime; }
127 #endif // TIME_STATS
128 
129  /*---------------------*/
130  /* Other class methods */
131  /*---------------------*/
132 
133  /// Is this the main iteration of the current MegaIteration?
134  bool isMainIteration() const override;
135 
136 
137 private:
138  /// Helper for constructor
139  void init();
140 
141  virtual void startImp() override;
142 
143  /// Implementation of the run tasks of MADS algorithm.
144  /**
145  Run a MADS iteration: a Search step followed by a Poll step depending on the stop reasons and successes.
146  */
147  virtual bool runImp() override;
148 
149 #ifdef TIME_STATS
150  virtual void endImp() override;
151 #endif // TIME_STATS
152 };
153 
154 #include "../../nomad_nsend.hpp"
155 
156 #endif // __NOMAD400_MADSITERATION__
MadsIteration::getMesh
const std::shared_ptr< MeshBase > getMesh() const override
Definition: MadsIteration.hpp:112
MadsIteration::isMainIteration
bool isMainIteration() const override
Is this the main iteration of the current MegaIteration?
MadsIteration
Class for MADS iteration.
Definition: MadsIteration.hpp:59
MadsIteration::setSuccessType
void setSuccessType(const SuccessType &success)
Set SuccessType member.
Definition: MadsIteration.hpp:118
Iteration
Class for iteration of an Algorithm.
Definition: Iteration.hpp:57
Step
Base class of all types of steps (Iteration, Termination, Initialization, Poll, Mads,...
Definition: Step.hpp:68
SuccessType
SuccessType
Success type of an iteration.
Definition: defines.hpp:148
MadsIteration::getFrameCenter
const std::shared_ptr< EvalPoint > getFrameCenter() const override
Definition: MadsIteration.hpp:106
MadsIteration::runImp
virtual bool runImp() override
Implementation of the run tasks of MADS algorithm.
MadsIteration::_frameCenter
const std::shared_ptr< EvalPoint > _frameCenter
Center around which the points are generated.
Definition: MadsIteration.hpp:62
MadsIteration::MadsIteration
MadsIteration(const Step *parentStep, const std::shared_ptr< EvalPoint > &frameCenter, const size_t k, const std::shared_ptr< MeshBase > mesh)
Constructor.
Definition: MadsIteration.hpp:84
Iteration::endImp
virtual void endImp() override
MadsIteration::getSuccessType
const SuccessType & getSuccessType() const
Return current SuccessType.
Definition: MadsIteration.hpp:115
MadsIteration::init
void init()
Helper for constructor.
MadsIteration::startImp
virtual void startImp() override
MadsIteration::_mesh
const std::shared_ptr< MeshBase > _mesh
Mesh on which the points are.
Definition: MadsIteration.hpp:63
MadsIteration::_success
SuccessType _success
Success type of this iteration.
Definition: MadsIteration.hpp:64
SuccessType::NOT_EVALUATED
@ NOT_EVALUATED
Not evaluated yet.