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   defines.hpp
38  \brief  Definitions
39  \author Sebastien Le Digabel
40  \date   2010-03-23
41  */
42 #ifndef __DEFINES__
43 #define __DEFINES__
44 
45 #include <string>
46 #include <iostream>
47 #include <sstream>
48 #include <limits>
49 #include <limits.h>
50 #include <cstdlib>
51 
52 
53 // #define R_VERSION // defined for the R version only
54 
55 // Matlab version OPTI style (if not defined than GERAD style)
56 // #define OPTI_VERSION
57 
58 // Define in order to display debug information
59 //#define DEBUG
60 
61 // define in order to display memory debug information:
62 //#define MEMORY_DEBUG
63 
64 // define in order to display TGP information.
65 // #define TGP_DEBUG
66 
67 // #define USE_TGP is defined in the makefile
68 
69 #ifdef DEBUG
70 #ifndef MEMORY_DEBUG
71 #define MEMORY_DEBUG
72 #ifndef TGP_DEBUG
73 #define TGP_DEBUG
74 #endif
75 #endif
76 #endif
77 
78 
79 // CASE Linux using gnu compiler
80 #ifdef __gnu_linux__
81 #define GCC_X
82 #endif
83 
84 // CASE OSX using gnu compiler
85 #ifdef __APPLE__
86 #ifdef __GNUC__
87 #define GCC_X
88 #endif
89 #endif
90 
91 // CASE minGW using gnu compiler
92 #ifdef __MINGW32__
93 #define WINDOWS
94 #ifdef __GNUC__
95 #define GCC_X
96 #endif
97 #endif
98 
99 // CASE Visual Studio C++ compiler
100 #ifdef _MSC_VER
101 #define WINDOWS
102 #pragma warning(disable:4996)
103 #endif
104 
105 // For NOMAD random number generator
106 #if !defined(UINT32_MAX)
107 typedef unsigned int uint32_t;
108 #define UINT32_MAX	0xffffffff
109 #endif
110 
111 // to display model stats for each evaluation at
112 // which a model has been used (looks better
113 // with DISPLAY_DEGREE set to zero);
114 // The displayed stats are:
115 //   type (1:model_search, 2:model_ordering)
116 //   mesh_index
117 //   cardinality of Y
118 //   width of Y
119 //   Y condition number
120 //   h value, model for h, relative error (if constraints)
121 //   f value, model for f, relative error
122 
123 // #define MODEL_STATS
124 
125 namespace NOMAD {
126 
127     /// Current version:
128     const std::string BASE_VERSION = "3.7.2";
129 
130 #ifdef R_VERSION
131     const std::string VERSION = BASE_VERSION + ".R";
132 #else
133 #ifdef USE_MPI
134 #ifdef USE_TGP
135     const std::string VERSION = BASE_VERSION + ".TGP" + ".MPI";
136 #else
137     const std::string VERSION = BASE_VERSION + ".MPI";
138 #endif
139 #else
140 #ifdef USE_TGP
141     const std::string VERSION = BASE_VERSION + ".TGP";
142 #else
143     const std::string VERSION = BASE_VERSION;
144 #endif
145 #endif
146 #endif
147 
148     // Directory separator, plus LGPL and user guide files
149 #ifdef WINDOWS
150     const char        DIR_SEP = '\\';           ///< Directory separator
151     const std::string HOME    = "%NOMAD_HOME%"; ///< Home directory
152 #else
153     const char        DIR_SEP = '/';            ///< Directory separator
154     const std::string HOME    = "$NOMAD_HOME";  ///< Home directory
155 #endif
156 
157     /// Licence file
158     const std::string LGPL_FILE = HOME+DIR_SEP+"src"+DIR_SEP+"lgpl.txt";
159 
160     /// User guide file
161     const std::string USER_GUIDE_FILE = HOME+DIR_SEP+"doc"+DIR_SEP+"user_guide.pdf";
162 
163     /// Examples directory
164     const std::string EXAMPLES_DIR = HOME+DIR_SEP+"examples";
165 
166     /// Tools directory
167     const std::string TOOLS_DIR = HOME+DIR_SEP+"tools";
168 
169     /// Tag for valid cache files
170 #ifdef GCC_X
171     const int CACHE_FILE_ID = 77041301;
172 #else
173 #ifdef GCC_WINDOWS
174     const int CACHE_FILE_ID = 77041302;
175 #else
176 #ifdef _MSC_VER
177     const int CACHE_FILE_ID = 77041303;
178 #else
179     const int CACHE_FILE_ID = 77041304;
180 #endif
181 #endif
182 #endif
183 
184 #ifdef USE_MPI
185     // MPI constants
186     const int   MAX_REQ_WAIT =  3 ;  ///< Maximum time to wait for a request
187     const char   STOP_SIGNAL = 'S';  ///< Stop signal
188     const char   EVAL_SIGNAL = 'X';  ///< Evaluation signal
189     const char  READY_SIGNAL = 'R';  ///< Ready signal
190     const char RESULT_SIGNAL = 'O';  ///< Result signal
191     const char   WAIT_SIGNAL = 'W';  ///< Wait signal
192 #endif
193 
194     /// Maximum number of variables.
195     const int MAX_DIMENSION = 1000;
196 
197     // Old static Mesh index constants
198     const int L_LIMITS    = 50;         ///< Limits for the smesh index values
199     const int UNDEFINED_L = L_LIMITS+1;  ///< Undefined value for the smesh index
200 
201     // xmesh index constants
202     const int XL_LIMITS    = -50;         ///< Limits for the xmesh index values
203     const int UNDEFINED_XL = XL_LIMITS-1;  ///< Undefined value for the xmesh index
204 
205 
206     /// Default epsilon used by NOMAD::Double
207     /** Use Parameters::set_EPSILON(), or parameter EPSILON,
208      or NOMAD::Double::set_epsilon() to change it
209      */
210     const double DEFAULT_EPSILON = 1e-13;
211 
212     /// Maximal output value for points used for models.
213     const double MODEL_MAX_OUTPUT = 1e10;
214 
215     /// Default infinity string used by NOMAD::Double
216     /** Use Parameters::set_INF_STR(), or parameter INF_STR,
217      or NOMAD::Double::set_inf_str() to change it
218      */
219     const std::string DEFAULT_INF_STR = "inf";
220 
221     /// Default undefined value string used by NOMAD::Double
222     /** Use Parameters::set_UNDEF_STR(), or parameter UNDEF_STR,
223      or NOMAD::Double::set_undef_str() to change it
224      */
225     const std::string DEFAULT_UNDEF_STR = "NaN";
226 
227     /// log(10) (for display widths.)
228     const double LOG10 = 2.30258509299;
229 
230     const double INF = std::numeric_limits<double>::max(); ///< Infinity
231 
232     const double D_INT_MAX = UINT32_MAX; ///< The UINT32_MAX constant as a \c double
233 
234     // Singular Value Decomposition (SVD) constants:
235     const double SVD_EPS      = 1e-13;      ///< Epsilon for SVD
236     const int    SVD_MAX_MPN  = 1500;       ///< Matrix maximal size (\c m+n )
237     const double SVD_MAX_COND = NOMAD::INF; ///< Max. acceptable cond. number
238 
239     /// Default value for parameter POINT_DISPLAY_LIMIT
240     /** Use Parameters::set_POINT_DISPLAY_LIMIT() or parameter POINT_DISPLAY_LIMIT
241      or Point::set_display_limit() to change it */
242     const int DEFAULT_POINT_DISPLAY_LIMIT = 20;
243 
244     // Display precisions.
245     const int DISPLAY_PRECISION_STD = 10;  ///< Standard display precision
246     const int DISPLAY_PRECISION_BB  = 15;  ///< Display precision for blackboxes
247 
248     /// Constant for blackbox files #1.
249     const std::string BLACKBOX_INPUT_FILE_PREFIX = "nomad";
250 
251     /// Constant for blackbox files #2.
252     const std::string BLACKBOX_INPUT_FILE_EXT = "input";
253 
254     /// Constant for blackbox files #3.
255     const std::string BLACKBOX_OUTPUT_FILE_PREFIX = "nomad";
256 
257     /// Constant for blackbox files #4.
258     const std::string BLACKBOX_OUTPUT_FILE_EXT = "output";
259 
260     /// Display degree type.
261     enum dd_type
262     {
263         NO_DISPLAY     , ///< No display
264         MINIMAL_DISPLAY, ///< Minimal dispay
265         NORMAL_DISPLAY , ///< Normal display
266         FULL_DISPLAY     ///< Full display
267     };
268 
269     /// Types of the variables
270     //  (do not modify this order)
271     enum bb_input_type
272     {
273         CONTINUOUS  ,     ///< Continuous variable (default) (R)
274         INTEGER     ,     ///< Integer variable              (I)
275         CATEGORICAL ,     ///< Categorical variable          (C)
276         BINARY            ///< Binary variable               (B)
277     };
278 
279     /// Blackbox outputs type
280     enum bb_output_type
281     {
282         OBJ         ,    ///< Objective value
283         EB          ,    ///< Extreme barrier constraint
284         PB          ,    ///< progressive barrier constraint
285         // PEB           ///< PB constraint that becomes EB once satisfied
286         PEB_P       ,    ///< PEB constraint, state P (PB)
287         PEB_E       ,    ///< PEB constraint, state E (EB)
288         FILTER      ,    ///< Filter constraint
289         CNT_EVAL    ,    ///< Output set to 0 or 1 to specify to count or not the
290         ///<   blackbox evaluation
291         STAT_AVG    ,    ///< Stat (average)
292         STAT_SUM    ,    ///< Stat (sum)
293         UNDEFINED_BBO    ///< Ignored output
294     };
295 
296     /// Formulation for multi-objective optimization
297     enum multi_formulation_type
298     {
299         NORMALIZED            , ///< Normalized formulation
300         PRODUCT               , ///< Product formulation
301         DIST_L1               , ///< Distance formulation with norm L1
302         DIST_L2               , ///< Distance formulation with norm L2
303         DIST_LINF             , ///< Distance formulation with norm Linf
304         UNDEFINED_FORMULATION   ///< Undefined formulation
305     };
306 
307     /// Poll type
308     enum poll_type
309     {
310         PRIMARY   , ///< Primary poll
311         SECONDARY   ///< Secondary poll
312     };
313 
314     /// Poll center feasibility type
315     enum poll_center_type
316     {
317         FEASIBLE                   , ///< Feasible poll center type
318         INFEASIBLE                 , ///< Infeasible poll center type
319         UNDEFINED_POLL_CENTER_TYPE   ///< Undefined poll center type
320     };
321 
322     /// Search type
323     enum search_type
324     {
325         X0_EVAL          , ///< Starting point evaluation
326         POLL             , ///< Poll
327         EXTENDED_POLL    , ///< Extended poll
328         SEARCH           , ///< Generic search
329         CACHE_SEARCH     , ///< Cache search (does not require evals)
330         SPEC_SEARCH      , ///< MADS speculative search (dynamic order in GPS)
331         LH_SEARCH        , ///< Latin Hypercube (LH) search
332         LH_SEARCH_P1     , ///< Latin Hypercube (LH) search during phase one
333         MODEL_SEARCH     , ///< Model search
334         VNS_SEARCH       , ///< VNS search
335         P1_SEARCH        , ///< Phase one search
336         ASYNCHRONOUS     , ///< Parallel asynchronous final evaluations
337         USER_SEARCH      , ///< User search
338         UNDEFINED_SEARCH   ///< Undefined search
339     };
340 
341     /// Model type
342     enum model_type
343     {
344         QUADRATIC_MODEL , ///< Quadratic model
345         TGP_MODEL       , ///< TGP model
346         NO_MODEL          ///< No models
347     };
348 
349     /// TGP mode
350     enum TGP_mode_type
351     {
352         TGP_FAST    , ///< TGP fast mode.
353         TGP_PRECISE , ///< TGP precise mode.
354         TGP_USER      ///< TGP user mode.
355     };
356 
357     /// Success type of an iteration
358     // (do not modify this order)
359     enum success_type
360     {
361         UNSUCCESSFUL    ,  ///< Failure
362         PARTIAL_SUCCESS ,  ///< Partial success (improving)
363         FULL_SUCCESS       ///< Full success (dominating)
364     };
365 
366     /// Quadratic interpolation type
367     enum interpolation_type
368     {
369         MFN                          , ///< Minimum Frobenius Norm interpolation.
370         REGRESSION                   , ///< Regression.
371         WP_REGRESSION                , ///< Well-poised regression.
372         UNDEFINED_INTERPOLATION_TYPE   ///< Undefined.
373     };
374 
375     /// Stopping criteria
376     enum stop_type
377     {
378         NO_STOP                    ,  ///< No stop
379         ERROR                      ,  ///< Error
380         UNKNOWN_STOP_REASON        ,  ///< Unknown
381         CTRL_C                     ,  ///< Ctrl-C
382         USER_STOPPED               ,  ///< User-stopped in Evaluator::update_iteration()
383         MESH_PREC_REACHED          ,  ///< Mesh minimum precision reached
384         X0_FAIL                    ,  ///< Problem with starting point evaluation
385         P1_FAIL                    ,  ///< Problem with phase one
386         DELTA_M_MIN_REACHED        ,  ///< Min mesh size
387         DELTA_P_MIN_REACHED        ,  ///< Min poll size
388         L_MAX_REACHED              ,  ///< Max mesh index
389         L_MIN_REACHED              ,  ///< Min mesh index
390         L_LIMITS_REACHED           ,  ///< Mesh index limits
391         XL_LIMITS_REACHED          ,  ///< Mesh index limits
392         MAX_TIME_REACHED           ,  ///< Max time
393         MAX_BB_EVAL_REACHED        ,  ///< Max number of blackbox evaluations
394         MAX_SGTE_EVAL_REACHED      ,  ///< Max number of surrogate evaluations
395         MAX_EVAL_REACHED           ,  ///< Max number of evaluations
396         MAX_SIM_BB_EVAL_REACHED    ,  ///< Max number of sim bb evaluations
397         MAX_ITER_REACHED           ,  ///< Max number of iterations
398         MAX_CONS_FAILED_ITER       ,  ///< Max number of consecutive failed iterations
399         FEAS_REACHED               ,  ///< Feasibility
400         F_TARGET_REACHED           ,  ///< F_TARGET
401         STAT_SUM_TARGET_REACHED    ,  ///< STAT_SUM_TARGET
402         L_CURVE_TARGET_REACHED     ,  ///< L_CURVE_TARGET
403         MULTI_MAX_BB_REACHED       ,  ///< Max number of blackbox evaluations (multi obj.)
404         MULTI_NB_MADS_RUNS_REACHED ,  ///< Max number of MADS runs (multi obj.)
405         MULTI_STAGNATION           ,  ///< Stagnation criterion (multi obj.)
406         MULTI_NO_PARETO_PTS        ,  ///< No Pareto points (multi obj.)
407         MAX_CACHE_MEMORY_REACHED      ///< Max cache memory
408     };
409 
410     /// Type of norm used for the computation of h
411     enum hnorm_type
412     {
413         L1   ,  ///< norm L1
414         L2   ,  ///< norm L2
415         LINF    ///< norm Linf
416     };
417 
418     /// Types of directions
419     // (do not modify this order)
420     enum direction_type
421     {
422         UNDEFINED_DIRECTION    , ///< Undefined direction
423         MODEL_SEARCH_DIR       , ///< Model search direction
424         NO_DIRECTION           , ///< No direction
425         ORTHO_1                , ///< OrthoMADS 1
426         ORTHO_2                , ///< OrthoMADS 2
427         ORTHO_NP1_QUAD         , ///< OrthoMADS n+1 use Quad model to determine n+1-th direction
428         ORTHO_NP1_NEG          , ///< OrthoMADS n+1 use negative sum of n first directions to determine n+1-th direction
429         DYN_ADDED              , ///< Dynamic addition (n+1-th direction added for ORTHO n+1)
430         ORTHO_2N               , ///< OrthoMADS 2n
431         LT_1                   , ///< LT-MADS 1
432         LT_2                   , ///< LT-MADS 2
433         LT_2N                  , ///< LT-MADS 2n
434         LT_NP1                 , ///< LT-MADS n+1
435         GPS_BINARY             , ///< GPS for binary variables
436         GPS_2N_STATIC          , ///< GPS 2n static (classic coordinate search)
437         GPS_2N_RAND            , ///< GPS 2n random
438         GPS_NP1_STATIC_UNIFORM , ///< GPS n+1 static uniform
439         GPS_NP1_STATIC         , ///< GPS n+1 static
440         GPS_NP1_RAND_UNIFORM   , ///< GPS n+1 random uniform
441         GPS_NP1_RAND           ,  ///< GPS n+1
442         PROSPECT_DIR            ///< Prospect direction
443     };
444 
445     /// Type for Eval_Point::check() failures
446     enum check_failed_type
447     {
448         CHECK_OK     ,  ///< Correct check
449         LB_FAIL      ,  ///< LB failure
450         UB_FAIL      ,  ///< UB failure
451         FIX_VAR_FAIL ,  ///< Fixed variables failure
452         BIN_FAIL     ,  ///< Binary failure
453         CAT_FAIL     ,  ///< Categorical failure
454         INT_FAIL        ///< Integer failure
455     };
456 
457     /// Type for cache indexes in Cache:
458     enum cache_index_type
459     {
460         CACHE_1         ,  ///< Cache index #1
461         CACHE_2         ,  ///< Cache index #2
462         CACHE_3         ,  ///< Cache index #3
463         UNDEFINED_CACHE    ///< Undefined cache index
464     };
465 
466     /// Type for DISPLAY_STATS parameter
467     // (do not modify this order):
468     enum display_stats_type
469     {
470         DS_OBJ        ,    ///< Objective (f) value
471         //   (keep in first position)
472         DS_SIM_BBE    ,    ///< Number of simulated bb evaluations
473         DS_BBE        ,    ///< Number of bb evaluations
474         DS_BLK_EVA	  ,    ///< Number of block evaluation calls
475         DS_SGTE       ,    ///< Number of surrogate evaluations
476         DS_BBO        ,    ///< All blackbox outputs
477         DS_EVAL       ,    ///< Number of evaluations
478         DS_TIME       ,    ///< Wall-clock time
479         DS_MESH_INDEX ,    ///< Mesh index
480         DS_MESH_SIZE  ,    ///< Mesh size parameter Delta^m_k
481         DS_DELTA_M    ,    ///< Same as \c DS_MESH_SIZE
482         DS_POLL_SIZE  ,    ///< Poll size parameter Delta^p_k
483         DS_DELTA_P    ,    ///< Same as \c DS_POLL_SIZE
484         DS_SOL        ,    ///< Solution vector
485         DS_VAR        ,    ///< One variable
486         DS_STAT_SUM   ,    ///< Stat sum
487         DS_STAT_AVG   ,    ///< Stat avg
488         DS_UNDEFINED       ///< Undefined value
489         //   (keep in last position)
490     };
491 
492     /// Type for evaluation
493     enum eval_type
494     {
495         TRUTH , ///< Truth
496         SGTE    ///< Surrogate
497     };
498 
499     /// Type for an evaluation status
500     enum eval_status_type
501     {
502         EVAL_FAIL        ,  ///< Evaluation failure
503         EVAL_USER_REJECT ,  ///< Evaluation was rejected by user (not failure -> may submitted again)
504         EVAL_OK          ,  ///< Correct evaluation
505         EVAL_IN_PROGRESS ,  ///< Evaluation in progress
506         UNDEFINED_STATUS    ///< Undefined evaluation status
507     };
508 
509 }
510 
511 #endif
512