1 /*-------------------------------------------------------------------------------------*/
2 /* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2 */
3 /* */
4 /* Copyright (C) 2001-2015 Mark Abramson - the Boeing Company, Seattle */
5 /* Charles Audet - Ecole Polytechnique, Montreal */
6 /* Gilles Couture - Ecole Polytechnique, Montreal */
7 /* John Dennis - Rice University, Houston */
8 /* Sebastien Le Digabel - Ecole Polytechnique, Montreal */
9 /* Christophe Tribes - Ecole Polytechnique, Montreal */
10 /* */
11 /* funded in part by AFOSR and Exxon Mobil */
12 /* */
13 /* Author: Sebastien Le Digabel */
14 /* */
15 /* Contact information: */
16 /* Ecole Polytechnique de Montreal - GERAD */
17 /* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
18 /* e-mail: nomad@gerad.ca */
19 /* phone : 1-514-340-6053 #6928 */
20 /* fax : 1-514-340-5665 */
21 /* */
22 /* This program is free software: you can redistribute it and/or modify it under the */
23 /* terms of the GNU Lesser General Public License as published by the Free Software */
24 /* Foundation, either version 3 of the License, or (at your option) any later */
25 /* version. */
26 /* */
27 /* This program is distributed in the hope that it will be useful, but WITHOUT ANY */
28 /* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A */
29 /* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. */
30 /* */
31 /* You should have received a copy of the GNU Lesser General Public License along */
32 /* with this program. If not, see <http://www.gnu.org/licenses/>. */
33 /* */
34 /* You can find information on the NOMAD software at www.gerad.ca/nomad */
35 /*-------------------------------------------------------------------------------------*/
36 /**
37 \file Eval_Point.hpp
38 \brief Evaluation point (headers)
39 \author Sebastien Le Digabel
40 \date 2010-04-14
41 \see Eval_Point.cpp
42 */
43 #ifndef __EVAL_POINT__
44 #define __EVAL_POINT__
45
46 #include "Parameters.hpp"
47 #include "Cache_File_Point.hpp"
48 #include "Set_Element.hpp"
49
50 #ifdef WINDOWS
51 #ifndef isnan
isnan(double x)52 inline bool isnan ( double x ) { return x != x; }
53 #endif
54 #endif
55
56 namespace NOMAD {
57
58 /// Class for the representation of an evaluation point.
59 /**
60 An evaluation point gathers the point coordinates \c x, and the blackbox
61 outputs at these coordinates \c f(x).
62 */
63 class Eval_Point : public NOMAD::Point {
64
65 private:
66
67 static int _current_tag; ///< Current tag for all NOMAD::Eval_Point objects.
68 int _tag; ///< Unique tag.
69
70 static int _current_bbe; ///< Current bbe for all NOMAD::Eval_Point objects
71 static int _current_sgte_bbe; ///< Current sgte_bbe for all NOMAD::Eval_Point objects .
72 int _bbe; /// Recorded bbe for current NOMAD::Eval_Point object
73 int _sgte_bbe; /// Recorded sgte_bbe for current NOMAD::Eval_Point object
74 int _real_time; /// Recorded time for current NOMAD::Eval_Point object
75
76 NOMAD::Signature * _signature; ///< Signature of the point.
77
78 /**
79 \c f is explicitely computed by a NOMAD::Evaluator object
80 and is not saved in the cache file.
81 */
82 NOMAD::Double _f;
83
84 /**
85 \c h is explicitely computed by a NOMAD::Evaluator object
86 and is not saved in the cache file.
87 */
88 NOMAD::Double _h;
89
90 /// Flag equal to \c true if this eval point is in the cache.
91 mutable bool _in_cache;
92
93 /**
94 Flag equal to \c true if the point has been evaluated
95 during the current run.
96 */
97 mutable bool _current_run;
98
99 /// Type of the evaluation (true function or surrogate).
100 NOMAD::eval_type _eval_type;
101
102 /// Direction from which the point has been constructed.
103 /**
104 May be \c NULL if no direction has been used.
105 */
106 NOMAD::Direction * _direction;
107
108
109 /// Poll center from which the point has been constructed.
110 /**
111 May be \c NULL if no direction has been used.
112 */
113 const NOMAD::Eval_Point * _poll_center;
114
115 /**
116 Type of the poll center (feasible or not)
117 from which the point has been constructed.
118 */
119 NOMAD::poll_center_type _poll_center_type;
120
121 /// Evaluation status.
122 /**
123 Indicates if the evaluation failed, succeeded,
124 or is in progress.
125 */
126 NOMAD::eval_status_type _eval_status;
127
128 /// Flag equal to \c true if all EB constraints have been satisfied.
129 bool _EB_ok;
130
131 /// Blackbox outputs.
132 NOMAD::Point _bb_outputs;
133
134 /// User evaluation priority.
135 /**
136 - Decided by the user in his custom
137 NOMAD::Evaluator::eval_x() function, via
138 \c set_user_eval_priority().
139 - Points with higher priorities
140 will be evaluated first.
141 */
142 NOMAD::Double _user_eval_priority;
143
144 /// Random evaluation priority.
145 /**
146 Same idea than \c _user_eval_priority
147 for a random ordering of trial points.
148 */
149 NOMAD::Double _rand_eval_priority;
150
151 /// Affectation operator.
152 /**
153 \param x The right-hand side object -- \b IN.
154 \return \c *this as the result of the affectation.
155 */
156 Eval_Point & operator = ( const Eval_Point & x );
157
158 public:
159
160 /// Constructor #1.
161 explicit Eval_Point ( void );
162
163 /// Constructor #2.
164 /**
165 \param n Number of variables -- \b IN.
166 \param m Number of blackbox outputs -- \b IN.
167 */
168 Eval_Point ( int n , int m );
169
170 /// Constructor #3.
171 /**
172 \param x Coordinates of a point taken in a cache -- \b IN.
173 \param et Type of the evaluation (true or surrogate) -- \b IN.
174 */
175 explicit Eval_Point ( const NOMAD::Cache_File_Point & x ,
176 NOMAD::eval_type et );
177
178
179 ///Constructor 4
180 /**
181 \param x Coordinates of a point -- \b IN.
182 \param m Number of blackbox outputs -- \b IN.
183 */
184 explicit Eval_Point ( const NOMAD::Point & x, int m ) ;
185
186
187
188 /// Copy constructor.
189 /**
190 \param x The copied object.
191 */
192 explicit Eval_Point ( const Eval_Point & x );
193
194 /// Destructor.
195 virtual ~Eval_Point ( void );
196
197 /// Check the evaluation point.
198 /**
199 \param m Number of blackbox outputs -- \b IN.
200 \param cf The reason for a check failure -- \b OUT.
201 \return A boolean equal to \c true if the point is valid.
202 */
203 bool check ( int m , NOMAD::check_failed_type & cf ) const;
204
205 /*---------------*/
206 /* GET methods */
207 /*---------------*/
208
209 /// Size of the point in memory.
210 /**
211 \return Size of the point in memory, in bytes.
212 */
213 virtual int size_of ( void ) const;
214
215 /// Access to the signature of the point.
216 /**
217 \return A pointer to the signature of the point.
218 */
219 NOMAD::Signature * get_signature ( void ) const;
220
221 /// Access to the number of blackbox outputs.
222 /**
223 \return Number of blackbox outputs.
224 */
get_m(void) const225 int get_m ( void ) const { return _bb_outputs.size(); }
226
227 /// Access to the number of variables.
228 /**
229 \return Number of variables.
230 */
get_n(void) const231 int get_n ( void ) const { return size(); }
232
233 /// Check if the evaluation at this point is valid.
234 /**
235 \return A boolean equal to \c true if the evaluation is valid.
236 */
is_eval_ok(void) const237 bool is_eval_ok ( void ) const { return (_eval_status == NOMAD::EVAL_OK); }
238
239 /// Check if the evaluation at this point has been rejected by the user.
240 /**
241 \return A boolean equal to \c true if the evaluation has been rejected by the user.
242 */
check_rejected(void) const243 bool check_rejected ( void ) const { return (_eval_status == NOMAD::EVAL_USER_REJECT); }
244
245
246 /// Access to the tag of the point.
247 /**
248 \return The tag.
249 */
get_tag(void) const250 int get_tag ( void ) const { return _tag; }
251
252 /// Access to the bbe of the point.
253 /**
254 \return The bbe.
255 */
get_bbe(void) const256 int get_bbe ( void ) const { return _bbe; }
257
258 /// Access to the bbe of the point.
259 /**
260 \return The sgte_bbe.
261 */
get_sgte_bbe(void) const262 int get_sgte_bbe ( void ) const { return _sgte_bbe; }
263
264
265 /// Access to the real time of the point evaluation.
266 /**
267 \return The real time.
268 */
get_real_time(void) const269 int get_real_time( void ) const { return _real_time; }
270
271
272 /// Access to the objective value \c f.
273 /**
274 \return The objective value.
275 */
get_f(void) const276 const NOMAD::Double & get_f ( void ) const { return _f; }
277
278 /// Access to the feasibility value \c h.
279 /**
280 \return The feasibility value.
281 */
get_h(void) const282 const NOMAD::Double & get_h ( void ) const { return _h; }
283
284 /// Access to the blackbox outputs.
285 /**
286 \return The \c m blackblack outputs.
287 */
get_bb_outputs(void) const288 const NOMAD::Point & get_bb_outputs ( void ) const { return _bb_outputs; }
289
290 /// Access to the direction used to construct the point.
291 /**
292 \return The direction used to construct the point;
293 may be \c NULL if no direction has been used.
294 */
get_direction(void) const295 const NOMAD::Direction * get_direction ( void ) const { return _direction; }
296
297 /// Access to the poll_center used to construct the point.
298 /**
299 \return The poll center used to construct the point;
300 may be \c NULL if no poll center has been used.
301 */
get_poll_center(void) const302 const NOMAD::Eval_Point * get_poll_center ( void ) const { return _poll_center ; }
303
304
305 /// Check if the point has been generated during the current run.
306 /**
307 \return A boolean equal to \c true if the point has been
308 generated during the current run.
309 */
get_current_run(void) const310 bool get_current_run ( void ) const { return _current_run; }
311
312 /// Check if the point is in cache.
313 /**
314 \return A boolean equal to \c true if the point is in cache.
315 */
is_in_cache(void) const316 bool is_in_cache ( void ) const { return _in_cache; }
317
318 /// Check if the point respects the EB constraints.
319 /**
320 \return A boolean equal to \c true if the point respects the EB constraints.
321 */
is_EB_ok(void) const322 bool is_EB_ok ( void ) const { return _EB_ok; }
323
324 /// Access to the evaluation type.
325 /**
326 \return The evaluation type (true or surrogate).
327 */
get_eval_type(void) const328 NOMAD::eval_type get_eval_type ( void ) const { return _eval_type; }
329
330 /// Access to the poll center type.
331 /**
332 \return The poll center type (feasible or not).
333 */
get_poll_center_type(void) const334 NOMAD::poll_center_type get_poll_center_type ( void ) const
335 {
336 return _poll_center_type;
337 }
338
339 /// Access to the evaluation status.
340 /**
341 \return The evaluation status
342 (evaluation failed, succeeded, or is in progress).
343 */
get_eval_status(void) const344 NOMAD::eval_status_type get_eval_status ( void ) const { return _eval_status; }
345
346 /// Access to the user evaluation priority.
347 /**
348 \return The user evaluation priority.
349 */
get_user_eval_priority(void) const350 const NOMAD::Double & get_user_eval_priority ( void ) const
351 {
352 return _user_eval_priority;
353 }
354
355 /// Access to the random evaluation priority.
356 /**
357 \return The random evaluation priority.
358 */
get_rand_eval_priority(void) const359 const NOMAD::Double & get_rand_eval_priority ( void ) const
360 {
361 return _rand_eval_priority;
362 }
363
364 /// Check the point feasibility.
365 /**
366 The point is feasible if \c h \c <= \c h_min.
367 \param h_min Feasibility threshold -- \b IN.
368 \return A boolean equal to \c true if the point is feasible.
369 */
is_feasible(const NOMAD::Double & h_min) const370 bool is_feasible ( const NOMAD::Double & h_min ) const
371 {
372 return ( _h.is_defined() && _h <= h_min );
373 }
374
375 /// Scaling.
376 void scale ( void );
377
378 /// Unscaling.
379 void unscale ( void );
380
381 /// Snap to bounds.
382 /**
383 \return A boolean equal to \c true if the snapping went well.
384 */
385 bool snap_to_bounds ( void );
386
387 /// Treat the periodic variables.
388 /**
389 \param new_dir A pointer to the modified direction used to generate
390 this point from the poll center; may be \c NULL if no
391 direction has been used -- \b OUT.
392 \return A boolean equal to \c true if the treatment went well.
393 */
394 bool treat_periodic_variables ( NOMAD::Direction *& new_dir );
395
396 /// Comparison operator.
397 /**
398 \param x Right-hand side object -- \b IN.
399 \return A boolean equal to \c true if \c *this \c < \c x .
400 */
401 bool operator < ( const Eval_Point & x ) const;
402
403 /*---------------*/
404 /* SET methods */
405 /*---------------*/
406
407 /// Set the \c n and \c m.
408 /**
409 \param n Number of variables -- \b IN.
410 \param m Number of blackbox outputs -- \b IN.
411 */
412 void set ( int n , int m );
413
414 /// Set the coordinates and \c m.
415 /**
416 \param x Coordinates of the point -- \b IN.
417 \param m Number of blackbox outputs -- \b IN.
418 */
419 void set ( const NOMAD::Point & x , int m );
420
421 /// Set the tag.
422 /**
423 \param tag The tag -- \b IN.
424 */
425 void set_tag ( int tag );
426
427 /// Set the real time.
428 /**
429 \param real_time The real time -- \b IN.
430 */
set_real_time(int real_time)431 void set_real_time ( int real_time ){_real_time=real_time;}
432
433 /// increment sgte_bbe.
434 /**
435 */
436 void increment_sgte_bbe (void);
437
438 /// increment bbe.
439 /**
440 */
441 void increment_bbe (void);
442
443 /// Set the blackbox evaluation number.
444 /**
445 \param bbe the evaluation number
446 */
set_bbe(int bbe)447 void set_bbe (int bbe){_bbe=bbe;}
448
449 /// Set the objective value \c f.
450 /**
451 \param f Objective value -- \b IN.
452 */
set_f(const NOMAD::Double & f)453 void set_f ( const NOMAD::Double & f ) { _f = f; }
454
455 /// Set the feasibility value \c h.
456 /**
457 \param h Feasibility value -- \b IN.
458 */
set_h(const NOMAD::Double & h)459 void set_h ( const NOMAD::Double & h ) { _h = h; }
460
461 /// Set the user evaluation priority.
462 /**
463 \param u User evaluation priority -- \b IN.
464 */
set_user_eval_priority(const NOMAD::Double & u)465 void set_user_eval_priority ( const NOMAD::Double & u ) { _user_eval_priority = u; }
466
467 /// Set the random evaluation priority.
468 /**
469 \param r Random evaluation priority -- \b IN.
470 */
set_rand_eval_priority(const NOMAD::Double & r)471 void set_rand_eval_priority ( const NOMAD::Double & r ) { _rand_eval_priority = r; }
472
473 /// Set one blackbox output.
474 /**
475 \param i Index of the output to set -- \b IN.
476 \param v Value of the output -- \b IN.
477 */
set_bb_output(int i,const NOMAD::Double & v)478 void set_bb_output ( int i , const NOMAD::Double & v ) { _bb_outputs[i]= v; }
479
480 /// Set all blackbox outputs.
481 /**
482 \param b The \c m blackbox outputs -- \b IN.
483 */
set_bb_output(const NOMAD::Point & b)484 void set_bb_output ( const NOMAD::Point & b ) { _bb_outputs = b; }
485
486 /// Set the evaluation status.
487 /**
488 \param e Evaluation status (failed, succeeded, or in progress)
489 -- \b IN.
490 */
set_eval_status(const NOMAD::eval_status_type & e)491 void set_eval_status ( const NOMAD::eval_status_type & e ) { _eval_status = e; }
492
493 /// Set if the point respects the EB constraints.
494 /**
495 \param e A boolean equal to \c true if the point
496 respects the EB constraints.
497 */
set_EB_ok(bool e)498 void set_EB_ok ( bool e ) { _EB_ok = e; }
499
500 /// Set the evaluation type.
501 /**
502 \param e Evaluation type (true or surrogate) -- \b IN.
503 */
set_eval_type(NOMAD::eval_type e)504 void set_eval_type ( NOMAD::eval_type e ) { _eval_type = e; }
505
506 /// Set the type of the poll center.
507 /**
508 \param p Type of the poll center (feasible or not) -- \b IN.
509 */
set_poll_center_type(NOMAD::poll_center_type p)510 void set_poll_center_type ( NOMAD::poll_center_type p ) { _poll_center_type = p; }
511
512 /// Indicate if the point has been generated during the current run.
513 /**
514 \param c A boolean equal to \c true if the point
515 has been generated during the current run -- \b IN.
516 */
set_current_run(bool c) const517 void set_current_run ( bool c ) const { _current_run = c; }
518
519 /// Indicate if the point is in cache.
520 /**
521 \param i A boolean equal to \c true if the point is in cache
522 -- \b IN.
523 */
set_in_cache(bool i) const524 void set_in_cache ( bool i ) const { _in_cache = i; }
525
526
527 /// Set the direction used to create the point.
528 /**
529 \param d A pointer to the direction; may be \c NULL -- \b IN.
530 */
531 void set_direction ( const NOMAD::Direction * d );
532
533
534 /// Set the poll center used to create the point.
535 /**
536 \param d A pointer to the poll center; may be \c NULL -- \b IN.
537 */
538 void set_poll_center ( const NOMAD::Eval_Point * d );
539
540 /// Set the signature.
541 /**
542 \param s A pointer to the signature -- \b IN.
543 */
544 void set_signature ( NOMAD::Signature * s );
545
546 /// Check if there are nan's in the blackbox outputs:
547 /**
548 \return \c true if there is at least a nan.
549 */
550 bool check_nan ( void ) const;
551
552
553 /// Reset the tags and bbes
554 /**
555 */
reset_tags_and_bbes(void)556 static void reset_tags_and_bbes ( void ) {_current_tag = 0;_current_bbe = 0;_current_sgte_bbe = 0;}
557
558 #ifdef MODEL_STATS
559
560 private:
561
562 mutable int _mod_use; // 1: model search; 2: model eval sort
563 mutable int _nY;
564 mutable NOMAD::Double _cond , _Yw , _mh , _mf;
565
566 public:
567
set_mod_use(int mod_use) const568 void set_mod_use ( int mod_use ) const { _mod_use = mod_use; }
set_nY(int nY) const569 void set_nY ( int nY ) const { _nY = nY; }
set_cond(const NOMAD::Double & cond) const570 void set_cond ( const NOMAD::Double & cond ) const { _cond = cond; }
set_Yw(const NOMAD::Double & Yw) const571 void set_Yw ( const NOMAD::Double & Yw ) const { _Yw = Yw; }
set_mh(const NOMAD::Double & mh) const572 void set_mh ( const NOMAD::Double & mh ) const { _mh = mh; }
set_mf(const NOMAD::Double & mf) const573 void set_mf ( const NOMAD::Double & mf ) const { _mf = mf; }
574
get_mod_use(void) const575 int get_mod_use ( void ) const { return _mod_use; }
get_nY(void) const576 int get_nY ( void ) const { return _nY; }
get_cond(void) const577 const NOMAD::Double & get_cond ( void ) const { return _cond; }
get_Yw(void) const578 const NOMAD::Double & get_Yw ( void ) const { return _Yw; }
get_mh(void) const579 const NOMAD::Double & get_mh ( void ) const { return _mh; }
get_mf(void) const580 const NOMAD::Double & get_mf ( void ) const { return _mf; }
581
582 void set_model_data ( const NOMAD::Eval_Point & x ) const;
583 void clear_model_data ( void ) const;
584
585 #endif
586
587 /// Display the tag of the point.
588 /**
589 \param out The NOMAD::Display object -- \b IN.
590 */
591 void display_tag ( const NOMAD::Display & out ) const;
592
593 /// Display.
594 /**
595 \param out The NOMAD::Display object -- \b IN.
596 \param in_block If \c true, the point is displayed into an indented block
597 -- \b IN -- \b optional (default = \c true ).
598 */
599 virtual void display_eval ( const NOMAD::Display & out , bool in_block = true ) const;
600 };
601
602 /// Display a NOMAD::Eval_Point object.
603 /**
604 \param out The NOMAD::Display object -- \b IN.
605 \param x The NOMAD::Eval_Point object to be displayed -- \b IN.
606 \return The NOMAD::Display object.
607 */
operator <<(const NOMAD::Display & out,const NOMAD::Eval_Point & x)608 inline const NOMAD::Display & operator << ( const NOMAD::Display & out ,
609 const NOMAD::Eval_Point & x )
610 {
611 x.display_eval (out , true );
612 return out;
613 }
614 }
615
616 #endif
617