NOMAD Source  Version 4.0.0 Beta
Termination.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_TERMINATION__
47 #define __NOMAD400_TERMINATION__
48 
49 #include "../Algos/Step.hpp"
50 
51 #include "../nomad_nsbegin.hpp"
52 
53 /// Class for termination of an algorithm.
54 /**
55  The terminate function checks for termination criterions such as MAX_ITERATIONS, MAX_TIME, STOP_IF_FEASIBLE and set the stop reason.
56  */
57 class Termination: public Step
58 {
59 public:
60  /// Constructor
61  explicit Termination(const Step* parentStep,
62  const std::shared_ptr<RunParameters>& runParams = nullptr,
63  const std::shared_ptr<PbParameters>& pbParams = nullptr)
64  : Step(parentStep, runParams, pbParams)
65  {
66  init();
67  }
68 
69  /// Destructor
70  virtual ~Termination() {}
71 
72  /**
73  The terminate function is called when algorithm are performing iterations during a run. At each iteration, we test if a stop criterion is reached.
74  */
75  virtual bool terminate(size_t iteration);
76 
77  virtual void startImp() override; ///< Will update the step name
78 
79  /// Implementation for run task of algorithm Termination.
80  /**
81  \return \c true is a stop reason requires termination of an algorithm, \c false otherwise.
82  */
83  virtual bool runImp() override;
84 
85  /// Implementation for end tasks of algorithm Termination.
86  /**
87  Upon completing an algorithm run, this end function is called to display termination info.
88  */
89  virtual void endImp() override;
90 
91 private:
92 
93  /// Helper for constructor
94  void init();
95 
96  /// Helper for end
97  bool solHasFeas() const;
98 
99 };
100 
101 #include "../nomad_nsend.hpp"
102 
103 #endif // __NOMAD400_TERMINATION__
Termination::init
void init()
Helper for constructor.
Step
Base class of all types of steps (Iteration, Termination, Initialization, Poll, Mads,...
Definition: Step.hpp:68
Termination::endImp
virtual void endImp() override
Implementation for end tasks of algorithm Termination.
Termination::runImp
virtual bool runImp() override
Implementation for run task of algorithm Termination.
Termination::Termination
Termination(const Step *parentStep, const std::shared_ptr< RunParameters > &runParams=nullptr, const std::shared_ptr< PbParameters > &pbParams=nullptr)
Constructor.
Definition: Termination.hpp:61
Termination::~Termination
virtual ~Termination()
Destructor.
Definition: Termination.hpp:70
Termination::solHasFeas
bool solHasFeas() const
Helper for end.
Termination
Class for termination of an algorithm.
Definition: Termination.hpp:57
Termination::startImp
virtual void startImp() override
Will update the step name.
Termination::terminate
virtual bool terminate(size_t iteration)