/*-------------------------------------------------------------------------------------*/
/*  NOMAD - Nonsmooth Optimization by Mesh Adaptive Direct search - version 3.0.0      */
/*                                                                                     */
/*  Copyright (C) 2001-2008  Mark Abramson        - the Boeing Company, Seattle        */
/*                           Charles Audet        - Ecole Polytechnique, Montreal      */
/*                           Gilles Couture       - Ecole Polytechnique, Montreal      */
/*                           John Dennis          - Rice University, Houston           */
/*                           Sebastien Le Digabel - Ecole Polytechnique, Montreal      */
/*                                                                                     */
/*  funded in part by AFOSR and Exxon Mobil                                            */
/*                                                                                     */
/*  Author: Sebastien Le Digabel                                                       */
/*                                                                                     */
/*  Contact information:                                                               */
/*    Ecole Polytechnique de Montreal - GERAD                                          */
/*    C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada                  */
/*    e-mail: Sebastien.Le.Digabel@gerad.ca                                            */
/*    phone : 1-514-340-6053 #6673                                                     */
/*    fax   : 1-514-340-5665                                                           */
/*                                                                                     */
/*  This program is free software: you can redistribute it and/or modify it under the  */
/*  terms of the GNU General Public License as published by the Free Software          */
/*  Foundation, either version 3 of the License, or (at your option) any later         */
/*  version.                                                                           */
/*                                                                                     */
/*  This program is distributed in the hope that it will be useful, but WITHOUT ANY    */
/*  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A    */
/*  PARTICULAR PURPOSE.  See the GNU General Public License for more details.          */
/*                                                                                     */
/*  You should have received a copy of the GNU General Public License along with this  */
/*  program. If not, see <http://www.gnu.org/licenses/>.                               */
/*                                                                                     */
/*  You can find information on the NOMAD software at www.gerad.ca/nomad               */
/*-------------------------------------------------------------------------------------*/
#ifndef __DEFINES__
#define __DEFINES__

#include <string>
#include <iostream>
#include <sstream>
#include <limits>
#include <limits.h>
#include <cstdlib>

// #define DEBUG is obtained by 'make debug'
// #ifndef DEBUG
// #define DEBUG // temporary replacement of 'make debug'
// #endif

/*-------------------------------------------------------------------*/
/*  one of these flags is active in the makefile                     */
/*-------------------------------------------------------------------*/
/* #define GCC_X                 // g++        (Linux/Unix/Mac-osX)  */
/* #define GCC_WINDOWS           // minGW      (gcc Windows)         */
/* #define _MSC_VER              // visual C++ (Windows)             */
/*-------------------------------------------------------------------*/

#ifdef GCC_WINDOWS
#define WINDOWS
#endif

#ifdef _MSC_VER
#define WINDOWS
#endif

// current version:
const std::string NOMAD_VERSION = "3.0.0";

// directory separator:
#ifdef WINDOWS
const char DIR_SEP = '\\';
#else
const char DIR_SEP = '/';
#endif

// tag for valid cache files:
#ifdef GCC_X
const int CACHE_FILE_ID = 197704131;
#endif

#ifdef GCC_WINDOWS
const int CACHE_FILE_ID = 197704132;
#endif

#ifdef _MSC_VER
const int CACHE_FILE_ID = 197704133;
#endif

// mesh index constants:
const int L_LIMITS    = 50;
const int UNDEFINED_L = L_LIMITS+1;

// default epsilon used by NOMAD::Double
// (use Parameters::set_EPSILON(), or parameter EPSILON,
//  or NOMAD::Double::set_epsilon() to change it):
const double DEFAULT_EPSILON = 1e-13;

// some constants:
const double LOG10     = 2.30258509299;                      // log(10) (for display widths)
const double INF       = std::numeric_limits<double>::max(); // infinity
const double D_INT_MAX = INT_MAX;                            // the INT_MAX constant in double

// default value for parameter POINT_DISPLAY_LIMIT
// (use Parameters::set_POINT_DISPLAY_LIMIT() or parameter POINT_DISPLAY_LIMIT
//  or Point::set_display_limit() to change it):
const int DEFAULT_POINT_DISPLAY_LIMIT = 20;

// display precisions:
const int DISPLAY_PRECISION_STD = 10;
const int DISPLAY_PRECISION_BB  = 15;

// constants for black-box file operations:
const std::string BLACK_BOX_INPUT_FILE_PREFIX  = "nomad";
const std::string BLACK_BOX_INPUT_FILE_EXT     = "input";
const std::string BLACK_BOX_OUTPUT_FILE_PREFIX = "nomad";
const std::string BLACK_BOX_OUTPUT_FILE_EXT    = "output";

// inputs type (types of the variables, don't touch this order):
enum bb_input_type { _CONTINUOUS_     ,     // continuous variable (default)  (R)
		     _INTEGER_        ,     // integer variable               (I)
		     _CATEGORICAL_    ,     // caterogical variable           (C)
		     _BINARY_           };  // binary variable                (B)

// black-box outputs type:
enum bb_output_type { _OBJ_      ,  // objective value
		      _EB_       ,  // extreme barrier constraint
		      _PB_       ,  // progressive barrier constraint
		      // _PEB_      // PB constraint that becomes EB once satisfied
		      _PEB_P_    ,  //   state P (PB)
		      _PEB_E_    ,  //   state E (EB)
		      _F_        ,  // Filter constraint
		      _STAT_AVG_ ,  // stat (average)
		      _STAT_SUM_ ,  // stat (sum)
		      _NOTHING_  }; // ignored output

// poll type:
enum poll_type { _PRIMARY_ , _SECONDARY_ };

// poll center feasibility type:
enum poll_center_type { _FEASIBLE_ , _INFEASIBLE_ , _UNDEFINED_POLL_CENTER_TYPE_ };

// search type:
enum search_type { _UNDEFINED_SEARCH_ ,
		   _X0_               ,     // x0
		   _POLL_             ,     // poll
		   _SEARCH_           ,     // generic search
		   _CACHE_SEARCH_     ,     // cache search (does not require evaluations)
		   _MADS_SEARCH_      ,     // MADS search (= dynamic order in GPS)
		   _LH_SEARCH_        ,     // Latin Hypercube search
		   _VNS_SEARCH_         };  // VNS search

// success type of an iteration (don't touch this order):
enum success_type { _UNSUCCESSFUL_,
		    _PARTIAL_SUCCESS_,   // better than a failure.
		    _FULL_SUCCESS_ };    // better than a partial success.

// stopping criteria:
enum stop_type { _NO_STOP_                 ,
		 _ERROR_                   ,
		 _UNKNOWN_                 ,
		 _CTRL_C_                  ,
		 _TRIAL_PT_CONSTRUCTION_   ,
		 _X0_EVAL_                 ,
		 _PHASE_1_FAIL_            ,
		 _DELTA_M_MIN_REACHED_     ,
		 _DELTA_P_MIN_REACHED_     ,
		 _L_MAX_REACHED_           ,
		 _L_LIMITS_REACHED_        ,
		 _MAX_TIME_REACHED_        ,
		 _MAX_BB_EVAL_REACHED_     ,
		 _MAX_SGTE_EVAL_REACHED_   ,
		 _MAX_EVAL_REACHED_        ,
		 _MAX_SIM_BB_EVAL_REACHED_ ,
		 _MAX_ITER_REACHED_        ,
		 _MIN_EPS_REACHED_         ,
		 _MIN_PROGRESS_REACHED_    ,
		 _F_TARGET_REACHED_        ,
		 _STAT_SUM_TARGET_REACHED_   };

// type of norm used for the computation of h:
enum hnorm_type { _L1_ , _L2_ , _LINF_ };

// types of directions (don't touch this order):
enum direction_type { _UNDEFINED_DIRECTION_    ,
		      _NO_DIRECTION_           ,
		      _ORTHO_1_                ,
		      _ORTHO_2_                ,
		      _ORTHO_2N_               ,
		      _LT_1_                   ,
		      _LT_2_                   ,
		      _LT_2N_                  ,
		      _LT_NP1_                 ,
		      _GPS_BINARY_             ,
		      _GPS_2N_STATIC_          ,
		      _GPS_2N_RAND_            ,
		      _GPS_NP1_STATIC_UNIFORM_ ,
		      _GPS_NP1_STATIC_         ,
		      _GPS_NP1_RAND_UNIFORM_   ,
		      _GPS_NP1_RAND_             };

// type for Eval_Point::check() failures:
enum check_failed_type { _OK_           ,
			 _LB_FAIL_      ,
			 _UB_FAIL_      ,
			 _FIX_VAR_FAIL_ ,
			 _BIN_FAIL_     ,
			 _CAT_FAIL_     ,
			 _INT_FAIL_       };

// type for cache indexes in Cache:
enum cache_index_type { _UNDEFINED_CACHE_ ,
			_CACHE_1_         ,
			_CACHE_2_         ,
			_CACHE_3_           };

// type for DISPLAY_STATS parameter:
enum display_stats_type { _DS_OBJ_       ,    // objective (f) value (keep in first position)
			  _DS_SIM_BBE_   ,    // number of simulated bb evaluations
			  _DS_BBE_       ,    // number of bb evaluations
			  _DS_BBO_       ,    // all black-box outputs
			  _DS_EVAL_      ,    // number of evaluations
			  _DS_TIME_      ,    // wall-clock time
			  _DS_SOL_       ,    // solution vector
			  _DS_STAT_SUM_  ,    // stat sum
			  _DS_STAT_AVG_  ,    // stat avg
			  _DS_UNDEFINED_   }; // undefined value (keep in last position)

#endif
