NOMAD Source  Version 4.0.0 Beta
EvcInterface.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 
47 #ifndef __NOMAD400_EVCINTERFACE__
48 #define __NOMAD400_EVCINTERFACE__
49 
50 #include "../Algos/Step.hpp"
51 #include "../Eval/EvaluatorControl.hpp"
52 
53 #include "../nomad_nsbegin.hpp"
54 
55 
56 /// Class interface with EvaluatorControl, used by an Algorithm step through IterationUtils
57 /**
58  \todo Complete documentation
59  */
61 {
62 private:
63  const Step* _step; ///< Step that uses the EvaluatorControl
64  Point _fixedVariable; ///< Full dimension point including fixed variables
65 
66  static std::shared_ptr<EvaluatorControl> _evaluatorControl; ///< Static EvaluatorControl
67 
68 public:
69  /// Constructor
70  /**
71  \param step The step using this EvcInterface
72  */
73  explicit EvcInterface(Step* step )
74  : _step(step )
75  {
76  init();
77  }
78 
79  /*---------*/
80  /* Get/Set */
81  /*---------*/
82 
83  static const std::shared_ptr<EvaluatorControl> getEvaluatorControl()
84  {
85  return _evaluatorControl;
86  }
87 
88  /**
89  If the evaluatorControl attribute is NULL, throws an exception.
90  */
91  static void setEvaluatorControl(const std::shared_ptr<EvaluatorControl>& evaluatorControl);
92 
93  /// Interface for EvaluatorControl::setBarrier.
94  /**
95  Transform from subBarrier to fullBarrier, that is transform points in sub-space to full-space.
96  Set the barrier to a full space barrier.
97  */
98  void setBarrier(const std::shared_ptr<Barrier>& subBarrier);
99 
100  /// Look for a point in the EvaluatorControl Barrier.
101  /**
102  \param x -- IN
103  \param evalPoint -- OUT
104  \return \c true if point was found, \c false otherwise
105  */
106  bool findInBarrier(const Point& x, EvalPoint &evalPoint) const;
107 
108  /// Get all evaluated points
109  /**
110  \note _evaluatedPoints is cleared
111  */
112  std::vector<EvalPoint> retrieveAllEvaluatedPoints();
113 
114 
115  /*---------------*/
116  /* Other Methods */
117  /*-------------- */
118 
119  // This method may be used by MegaIteration, or by a SearchMethod or by Poll
120  /**
121  * For each point, look if it is in the cache.
122  * If it is, count a cache hit.
123  * If not, convert it to an EvalQueuePoint and add it to EvaluatorControl's Queue.
124 
125  \param trialPoints The trial points -- \b IN/OUT.
126  \param useMesh Flag to use mesh or not -- \b IN.
127  */
128  void keepPointsThatNeedEval(const EvalPointSet &trialPoints, bool useMesh = true);
129 
130 
131  /**
132  When points are generated and added to queue, we can start evaluation.
133  */
135 
136  /// Evaluate a single point.
137  /**
138  Useful for X0. \n
139  This method will convert a point from subspace to full space
140  before calling EvaluatorControl's method of the same name.
141 
142  \param evalPoint The poin to evaluate -- \b IN/OUT.
143  \param hMax The max infeasibility for keeping points in barrier -- \b IN.
144  \return \c true if evaluation worked (evalOk), \c false otherwise.
145  */
146  bool evalSinglePoint(EvalPoint &evalPoint, const Double &hMax = INF);
147 
148 private:
149  /// Helper for constructor
150  void init();
151 
152  /// Helper for init
153  /**
154  Utility that throws an exception when not verified.
155  */
156  void verifyStepNotNull();
157 
158  /// Helper for init and setEvaluatorControl
159  /**
160  Utility that throws an exception when not verified.
161  */
162  static void verifyEvaluatorControlNotNull();
163 
164 };
165 
166 #include "../nomad_nsend.hpp"
167 
168 #endif // __NOMAD400_EVCINTERFACE__
EvcInterface::init
void init()
Helper for constructor.
EvcInterface::getEvaluatorControl
static const std::shared_ptr< EvaluatorControl > getEvaluatorControl()
Definition: EvcInterface.hpp:83
Point
Class for the representation of a point.
Definition: Point.hpp:68
Double
Custom class for double-precision reals.
Definition: Double.hpp:71
INF
const double INF
Infinity.
Definition: defines.hpp:125
EvcInterface::verifyStepNotNull
void verifyStepNotNull()
Helper for init.
Step
Base class of all types of steps (Iteration, Termination, Initialization, Poll, Mads,...
Definition: Step.hpp:68
EvcInterface::setBarrier
void setBarrier(const std::shared_ptr< Barrier > &subBarrier)
Interface for EvaluatorControl::setBarrier.
SuccessType
SuccessType
Success type of an iteration.
Definition: defines.hpp:148
EvalPointSet
std::set< EvalPoint, EvalPointCompare > EvalPointSet
Definition for EvalPointSet.
Definition: EvalPoint.hpp:371
EvalPoint
Class for the representation of an evaluation point.
Definition: EvalPoint.hpp:75
EvcInterface::setEvaluatorControl
static void setEvaluatorControl(const std::shared_ptr< EvaluatorControl > &evaluatorControl)
EvcInterface::verifyEvaluatorControlNotNull
static void verifyEvaluatorControlNotNull()
Helper for init and setEvaluatorControl.
EvcInterface::startEvaluation
SuccessType startEvaluation()
EvcInterface::_fixedVariable
Point _fixedVariable
Full dimension point including fixed variables.
Definition: EvcInterface.hpp:64
EvcInterface::findInBarrier
bool findInBarrier(const Point &x, EvalPoint &evalPoint) const
Look for a point in the EvaluatorControl Barrier.
EvcInterface::evalSinglePoint
bool evalSinglePoint(EvalPoint &evalPoint, const Double &hMax=INF)
Evaluate a single point.
EvcInterface::EvcInterface
EvcInterface(Step *step)
Constructor.
Definition: EvcInterface.hpp:73
EvcInterface::_step
const Step * _step
Step that uses the EvaluatorControl.
Definition: EvcInterface.hpp:63
EvcInterface
Class interface with EvaluatorControl, used by an Algorithm step through IterationUtils.
Definition: EvcInterface.hpp:60
EvcInterface::keepPointsThatNeedEval
void keepPointsThatNeedEval(const EvalPointSet &trialPoints, bool useMesh=true)
EvcInterface::retrieveAllEvaluatedPoints
std::vector< EvalPoint > retrieveAllEvaluatedPoints()
Get all evaluated points.
EvcInterface::_evaluatorControl
static std::shared_ptr< EvaluatorControl > _evaluatorControl
Static EvaluatorControl.
Definition: EvcInterface.hpp:66