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   Barrier.hpp
38  \brief  Barrier for constraints handling (headers)
39  \author Sebastien Le Digabel
40  \date   2010-04-12
41  \see    Barrier.cpp
42  */
43 #ifndef __BARRIER__
44 #define __BARRIER__
45 
46 #include "Cache.hpp"
47 #include "Filter_Point.hpp"
48 
49 namespace NOMAD {
50 
51 	/// Barrier class for constraints handling.
52 	/**
53      The barrier is basically a structure that stores evaluation points.
54 	 */
55 	class Barrier : private NOMAD::Uncopyable {
56 
57 	private:
58 
59 		const NOMAD::Parameters & _p;              ///< Parameters.
60 		NOMAD::eval_type          _eval_type;      ///< Truth or surrogate.
61 		NOMAD::Double             _h_max;          ///< Maximal value for \c h.
62 		const NOMAD::Eval_Point * _best_feasible;  ///< Best feasible solution.
63 
64 		/// Progressive barrier reference point.
65 		const NOMAD::Eval_Point * _ref;
66 
67 		std::set<NOMAD::Filter_Point> _filter;     ///< Filter.
68 		std::set<int>                 _prefilter;  ///< Pre-filter based on point tags.
69 
70 		int                           _rho_leaps;  ///< Number of trigger (rho) leaps.
71 
72 		const NOMAD::Eval_Point     * _poll_center;      ///< Primary poll center.
73 		const NOMAD::Eval_Point     * _sec_poll_center;  ///< Secondary poll center.
74 
75 		/**
76 		 Number of constraints that have been changed to NOMAD::PEB_E
77 		 (Extreme status for the PEB strategy).
78 		 */
79 		int _peb_changes;
80 
81 		/**
82 		 Number of times that the filter has been reseted following a PEB
83 		 change of status.
84 		 */
85 		int _peb_filter_reset;
86 
87 		/**
88 		 List of all points that we tried to insert into the filter,
89 		 with PEB constraints.
90 		 */
91 		std::list<const NOMAD::Eval_Point *> _peb_lop;
92 
93 		/// List of all points that we tried to insert into the filter.
94 		std::list<const NOMAD::Eval_Point *> _all_inserted;
95 
96 		NOMAD::success_type _one_eval_succ; ///< Success for one evaluation.
97 		NOMAD::success_type _success;       ///< Success for a list of evaluations.
98 
99 		/*----------------------------------------------------*/
100 
101 		/// Insertion of a feasible point.
102 		/**
103 		 \param  x The feasible point to insert -- \b IN.
104 		 \return Success type of the insertion
105 		 (NOMAD::FULL_SUCCESS or NOMAD::UNSUCCESSFUL).
106 		 */
107 		NOMAD::success_type insert_feasible ( const NOMAD::Eval_Point & x );
108 
109 		/// Insertion of an infeasible point.
110 		/**
111 		 \param  x The infeasible point to insert -- \b IN.
112 		 \return Success type of the insertion
113 		 (NOMAD::FULL_SUCCESS, NOMAD::UNSUCCESSFUL, or NOMAD::PARTIAL_SUCCESS).
114 		 */
115 		NOMAD::success_type insert_infeasible ( const NOMAD::Eval_Point & x );
116 
117 		/// Change the value of \c h_max.
118 		/**
119 		 \param h_max The new value of \c h_max -- \b IN.
120 		 */
121 		void set_h_max ( const NOMAD::Double & h_max );
122 
123 		/// Insertion into the filter.
124 		/**
125 		 \param x      The point to insert -- \b IN.
126 		 \param insert A boolean equal to \c true if the point has been
127 		 inserted into the barrier -- \b OUT.
128 		 */
129 		void filter_insertion ( const NOMAD::Eval_Point & x , bool & insert );
130 
131 		/*----------------------------------------------------*/
132 
133 	public:
134 
135 		/// Exception class for barrier update error.
136 		class Update_Error : public NOMAD::Exception
137 		{
138 		public:
139 			/// Constructor.
Update_Error(const std::string & file,int line,const std::string & msg)140 			Update_Error ( const std::string & file ,
141 						  int                 line ,
142 						  const std::string & msg    )
143 			: NOMAD::Exception ( file , line , msg ) {}
144 		};
145 
146 		/// Exception class for an insertion error.
147 		class Insert_Error : public NOMAD::Exception
148 		{
149 		public:
150 			/// Constructor.
Insert_Error(const std::string & file,int line,const std::string & msg)151 			Insert_Error ( const std::string & file ,
152 						  int                 line ,
153 						  const std::string & msg    )
154 			: NOMAD::Exception ( file , line , msg ) {}
155 		};
156 
157 		/*----------------------------------------------------*/
158 
159 		/// Constructor.
160 		/**
161 		 \param p  Parameters         -- \b IN.
162 		 \param et Truth or surrogate -- \b IN.
163 		 */
Barrier(const NOMAD::Parameters & p,NOMAD::eval_type et)164 		Barrier ( const NOMAD::Parameters & p , NOMAD::eval_type et )
165 		: _p               ( p                   ) ,
166 		_eval_type       ( et                  ) ,
167 		_h_max           ( p.get_h_max_0()     ) ,
168 		_best_feasible   ( NULL                ) ,
169 		_ref             ( NULL                ) ,
170 		_rho_leaps       ( 0                   ) ,
171 		_poll_center     ( NULL                ) ,
172 		_sec_poll_center ( NULL                ) ,
173 		_peb_changes     ( 0                   ) ,
174 		_peb_filter_reset( 0                   ) ,
175 		_one_eval_succ   ( NOMAD::UNSUCCESSFUL ) ,
176 		_success         ( NOMAD::UNSUCCESSFUL )   {}
177 
178 		/// Destructor.
~Barrier(void)179 		virtual ~Barrier ( void ) {}
180 
181 		/// Reset the barrier.
182 		void reset ( void );
183 
184 		/// Reset the success types.
reset_success(void)185 		void reset_success ( void ) { _one_eval_succ = _success = NOMAD::UNSUCCESSFUL; }
186 
187 		/// Poll center selection.
188 		/**
189 		 \param last_it_success Success of the last iteration -- \b IN.
190 		 */
191 		void select_poll_center ( NOMAD::success_type last_it_success );
192 
193 		/// Barrier updates.
194 		void update_and_reset_success ( void );
195 
196 		/// Access to the best infeasible point.
197 		/**
198 		 \return A pointer to the best infeasible point.
199 		 */
200 		const NOMAD::Eval_Point * get_best_infeasible ( void ) const;
201 
202 		/// Access to the best feasible point.
203 		/**
204 		 \return A pointer to the best feasible point.
205 		 */
get_best_feasible(void) const206 		const NOMAD::Eval_Point * get_best_feasible ( void ) const { return _best_feasible; }
207 
208 		/// Access to the best infeasible point with min. violation.
209 		/**
210 		 \return A pointer to the best infeasible point with min. viol.
211 		 */
212 		const NOMAD::Eval_Point * get_best_infeasible_min_viol ( void ) const;
213 
214 		/// Access to \c h_max.
215 		/**
216 		 \return The value of \c h_max.
217 		 */
get_h_max(void) const218 		const NOMAD::Double & get_h_max ( void ) const { return _h_max; }
219 
220 		/// Access to the poll center.
221 		/**
222 		 \return A pointer to the poll center.
223 		 */
get_poll_center(void) const224 		const NOMAD::Eval_Point * get_poll_center ( void ) const { return _poll_center; }
225 
226 		/// Access to the success type of one evaluation.
227 		/**
228 		 \return The success type of one evaluation.
229 		 */
get_one_eval_succ(void) const230 		NOMAD::success_type get_one_eval_succ ( void ) const { return _one_eval_succ;}
231 
232 		/// Access to the success type of a list of evaluations.
233 		/**
234 		 \return The success type of a list of evaluations.
235 		 */
get_success(void) const236 		NOMAD::success_type get_success ( void ) const { return _success; }
237 
238 		/// Access to the secondary poll center.
239 		/**
240 		 \return A pointer to the secondary poll center.
241 		 */
get_sec_poll_center(void) const242 		const NOMAD::Eval_Point * get_sec_poll_center ( void ) const
243 		{
244 			return _sec_poll_center;
245 		}
246 
247 		/// Access the list of all inserted points.
248 		/**
249 		 \return A list with pointers to the inserted points.
250 		 */
get_all_inserted(void) const251 		const std::list<const NOMAD::Eval_Point *> & get_all_inserted ( void ) const
252 		{
253 			return _all_inserted;
254 		}
255 
256 		/// Insertion of a point into the barrier.
257 		/**
258 		 \param x The point -- \b IN.
259 		 */
260 		void insert ( const NOMAD::Eval_Point & x );
261 
262 		/// Update the barrier from another barrier.
263 		/**
264 		 Used by the VNS search.
265 		 \param b The other barrier -- \b IN.
266 		 */
267 		void insert ( const Barrier & b );
268 
269 		/// Check the PEB constraints.
270 		/**
271 		 This will change eventually the status of PEB constraints
272 		 from NOMAD::PEB_P to NOMAD::PEB_E.
273 		 \param x       Point at which the constraints are checked -- \b IN.
274 		 \param display A boolean equal to \c true if displays are authorized -- \b IN.
275 		 */
276 		void check_PEB_constraints ( const NOMAD::Eval_Point & x , bool display );
277 
278 		/// Display.
279 		/**
280 		 \param out The NOMAD::Display object -- \b IN.
281 		 */
282 		void display ( const NOMAD::Display & out ) const;
283 
284 		/// Display.
285 		/**
286 		 Uses the NOMAD::Display object of the NOMAD::Parameters class.
287 		 */
display(void) const288 		void display ( void ) const { display ( _p.out() ); }
289 
290 	};
291 
292 	/// Display a NOMAD::Barrier object.
293 	/**
294      \param out The NOMAD::Display object -- \b IN.
295      \param b   The NOMAD::Barrier object to be displayed -- \b IN.
296      \return    The NOMAD::Display object.
297 	 */
operator <<(const NOMAD::Display & out,const NOMAD::Barrier & b)298 	inline const NOMAD::Display & operator << ( const NOMAD::Display & out ,
299 											   const NOMAD::Barrier & b     )
300 	{
301 		b.display ( out );
302 		return out;
303 	}
304 }
305 
306 #endif
307