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 OrthogonalMesh.hpp 38 \brief Virtual class for the MADS orthogonal meshes (headers) 39 \author Christophe Tribes 40 \date 2010-04-06 41 \see Mesh.cpp XMesh.cpp 42 */ 43 #ifndef __ORTHOGONALMESH__ 44 #define __ORTHOGONALMESH__ 45 46 #include "Point.hpp" 47 #include "Direction.hpp" 48 49 namespace NOMAD { 50 51 /// Virtual class for the MADS orthogonal meshes. 52 /** 53 - An orthogonal mesh in NOMAD is defined with the basic orthogonal directions the 54 mesh size parameter delta^k. 55 - The poll size parameter Delta^k is not used to define the mesh but 56 to define the poll trial points. 57 - At each MADS iteration the mesh is updated. 58 - Mesh and poll size parameters are stored as NOMAD::Point objects. 59 */ 60 class OrthogonalMesh { 61 62 /*--------------------------------------------------------------*/ 63 private: 64 65 66 /*--------------------------------------------------------------*/ 67 68 /// Private affectation operator. 69 /** 70 \param m The right-hand side object -- \b IN. 71 */ 72 const OrthogonalMesh & operator = ( const OrthogonalMesh & m ); 73 74 75 /*--------------------------------------------------------------*/ 76 protected: 77 78 79 NOMAD::Point _delta_0; 80 NOMAD::Point _Delta_0; 81 NOMAD::Point _Delta_min; 82 NOMAD::Point _delta_min; 83 84 85 NOMAD::Double _update_basis; 86 int _coarsening_step; 87 int _refining_step ; 88 89 int _n; 90 91 bool _Delta_min_is_defined; 92 bool _Delta_min_is_complete; 93 94 int _n_free_variables; 95 96 int _limit_mesh_index; // Limit max or min of the mesh index for fine mesh (SMesh->max, XMesh->min) 97 98 /// Constructor (called only by derived objects). 99 /** 100 \param Delta_0 Initial poll size Delta_0 -- \b IN. 101 \param Delta_min Minimal poll size Delta_min (may be undefined) -- \b IN. 102 \param delta_min Minimal mesh size delta_min (may be undefined) -- \b IN. 103 \param fixed_variables Fixed variables -- \b IN. 104 \param update_basis Mesh/poll update basis (tau) -- \b IN. 105 \param coarsening_step Mesh/poll coarsening exponent (w+) -- \b IN. 106 \param refining_step Mesh/poll refining exponent (w-) -- \b IN. 107 \param limit_mesh_index Limit mesh index to trigger stopping criterion -- \b IN. 108 */ 109 OrthogonalMesh (const NOMAD::Point & Delta_0 , 110 const NOMAD::Point & Delta_min , 111 const NOMAD::Point & delta_min , 112 const NOMAD::Point & fixed_variables , 113 NOMAD::Double update_basis, 114 int coarsening_step, 115 int refining_step, 116 int limit_mesh_index ) ; 117 118 119 /// Copy constructor (called only by derived objects). 120 /** 121 \param m The copied object -- \b IN. 122 */ OrthogonalMesh(const OrthogonalMesh & m)123 OrthogonalMesh ( const OrthogonalMesh & m ) 124 : _delta_0 ( m._delta_0 ), 125 _Delta_0 ( m._Delta_0 ), 126 _Delta_min ( m._Delta_min ), 127 _delta_min ( m._delta_min ), 128 _update_basis ( m._update_basis ), 129 _coarsening_step ( m._coarsening_step ), 130 _refining_step ( m._refining_step ), 131 _n ( m._n ), 132 _Delta_min_is_defined ( m._Delta_min_is_defined ), 133 _Delta_min_is_complete ( m._Delta_min_is_complete ), 134 _n_free_variables ( m._n_free_variables ), 135 _limit_mesh_index ( m._limit_mesh_index){} 136 137 138 /*--------------------------------------------------------------*/ 139 public: 140 141 142 /// Destructor. ~OrthogonalMesh(void)143 virtual ~OrthogonalMesh ( void ){;} 144 145 146 /// Update the Mesh (poll and mesh sizes). 147 /** 148 \param success Type of success of the iteration -- \b IN. 149 \param dir Direction of the iteration (optional) -- \b IN. 150 */ 151 virtual void update ( NOMAD::success_type success, const NOMAD::Direction * dir=NULL) = 0; 152 153 154 /// Update the provided mesh indices (the Mesh is unchanged). 155 /** 156 \param success Type of success of the iteration -- \b IN. 157 \param mesh_indices Provided mesh indices for update -- \b IN/OUT. 158 \param dir Direction of the iteration (optional) -- \b IN. 159 */ 160 virtual void update ( NOMAD::success_type success, NOMAD::Point & mesh_indices, const NOMAD::Direction * dir=NULL ) const = 0; 161 162 163 164 /// Reset the Mesh to its original sizes (poll and mesh sizes). 165 virtual void reset ( void ) = 0; 166 167 168 /// Access to the initial mesh size. 169 /** 170 \return A NOMAD::Point for the initial mesh size. 171 */ get_initial_mesh_size(void) const172 const NOMAD::Point & get_initial_mesh_size ( void ) const { return _delta_0; } 173 174 /// Access to the initial poll size. 175 /** 176 \return A NOMAD::Point for the initial poll size. 177 */ get_initial_poll_size(void) const178 const NOMAD::Point & get_initial_poll_size ( void ) const { return _Delta_0; } 179 180 181 /// Access to the minimal mesh size. 182 /** 183 \return A NOMAD::Point for the minimal mesh size. 184 */ get_min_mesh_size(void) const185 const NOMAD::Point & get_min_mesh_size ( void ) const { return _delta_min; } 186 187 188 /// Access to the minimal poll size. 189 /** 190 \return A NOMAD::Point for the minimal poll size. 191 */ get_min_poll_size(void) const192 const NOMAD::Point & get_min_poll_size ( void ) const { return _Delta_min; } 193 194 195 /// Test if mesh is finest so far. 196 /** 197 \return True if mesh is the finest so far, False otherwise. 198 */ 199 virtual bool is_finest(void) const = 0; 200 201 202 /// Test if current mesh is finer than initial mesh (used by VNS search). 203 /** 204 \return True if mesh size is smaller than initial mesh size for all components. 205 */ 206 bool is_finer_than_initial (void) const; 207 208 209 /// Access to the mesh/poll update basis tau. 210 /** 211 \return A double with the update basis tau. 212 */ get_update_basis(void) const213 double get_update_basis ( void ) const { return _update_basis.value(); } 214 215 216 /// Access to the mesh ratio after a success 217 /** 218 \return A point with the ratio for each coordinate 219 */ 220 virtual NOMAD::Point get_mesh_ratio_if_success( void ) const = 0; 221 222 223 /// Access to the number of variables. 224 /** 225 \return An integer with the number of variables. 226 */ get_n(void) const227 int get_n ( void ) const { return _n; } 228 229 230 /// Access to the number of free variables. 231 /** 232 \return An integer with the number of free variables. 233 */ get_n_free_variables(void) const234 int get_n_free_variables ( void ) const { return _n_free_variables; } 235 236 237 /// Access to the mesh size parameter delta^k. 238 /** 239 \return delta The mesh size parameter delta^k -- \b OUT. 240 */ get_delta(void) const241 NOMAD::Point get_delta ( void ) const 242 { 243 NOMAD::Point delta; 244 get_delta(delta); 245 return delta; 246 } 247 248 /// Access to the mesh size parameter delta^k. 249 /** 250 \param delta The mesh size parameter delta^k -- \b OUT. 251 \return A boolean equal to \c true if all values are 252 strictly inferior than the associated minimal 253 mesh size delta_min 254 (stopping criterion MIN_MESH_SIZE). 255 */ 256 virtual bool get_delta ( NOMAD::Point & delta ) const = 0; 257 258 /// Access to the largest mesh size. 259 /** 260 \return The largest mesh size -- \b OUT. 261 */ 262 virtual NOMAD::Point get_delta_max ( void ) const = 0; 263 264 265 /// Access to the poll size parameter Delta^k. 266 /** 267 \return Delta The poll size parameter Delta^k -- \b OUT. 268 */ get_Delta(void)269 NOMAD::Point get_Delta ( void ) 270 { 271 NOMAD::Point Delta; 272 get_Delta(Delta); 273 return Delta; 274 } 275 276 /// Access to the poll size parameter Delta^k. 277 /** 278 \param Delta The poll size parameter Delta^k -- \b OUT. 279 \return A boolean equal to \c true if all values are 280 strictly inferior than the associated minimal 281 mesh size delta_min 282 (stopping criterion MIN_POLL_SIZE). 283 */ 284 virtual bool get_Delta ( NOMAD::Point & Delta ) const = 0 ; 285 286 287 /// Display. 288 /** 289 \param out The NOMAD::Display object -- \b IN. 290 */ 291 virtual void display ( const NOMAD::Display & out ) const = 0; 292 293 /// Check the stopping conditions on the minimal poll and mesh sizes. 294 /** 295 \param stop Stop flag -- \b IN/OUT. 296 \param stop_reason Stop reason -- \b OUT. 297 */ 298 virtual void check_min_mesh_sizes ( bool & stop , 299 NOMAD::stop_type & stop_reason ) const = 0; 300 301 /// Access to the mesh indices per coordinate. 302 /** 303 \return A point with the mesh index for each coordinate. 304 */ 305 virtual const NOMAD::Point get_mesh_indices ( void ) const = 0; 306 307 /// Manually set the mesh indices per coordinate (virtual). 308 /** 309 \param r The mesh index per coordinate -- \b IN. 310 */ 311 virtual void set_mesh_indices ( const NOMAD::Point & r ) =0 ; 312 313 /// Manually set the min mesh size per coordinate. 314 /** 315 \param delta_min The min mesh sizes per coordinate (can be undefined) -- \b IN. 316 */ 317 void set_min_mesh_sizes ( const NOMAD::Point & delta_min ); 318 319 /// Manually set intial mesh size per coordinate. 320 /** 321 \param d The initial mesh sizes per coordinate -- \b IN. 322 */ 323 void set_delta_0 ( const NOMAD::Point & d ); 324 325 /// Manually set intial poll size per coordinate. 326 /** 327 \param d The initial poll sizes per coordinate -- \b IN. 328 */ 329 void set_Delta_0 ( const NOMAD::Point & d ); 330 331 332 /// Access to the min mesh indices reached so far. 333 /** 334 \return A point with the mesh index for each coordinate. 335 */ 336 virtual const NOMAD::Point get_min_mesh_indices ( void ) const = 0; 337 338 /// Access to the max mesh indices reached so far. 339 /** 340 \return A point with the mesh index for each coordinate. 341 */ 342 virtual const NOMAD::Point get_max_mesh_indices ( void ) const = 0; 343 344 345 /// Access to the limit mesh index. 346 /** 347 \return An integer with the limit mesh index. 348 */ get_limit_mesh_index(void) const349 int get_limit_mesh_index ( void ) const { return _limit_mesh_index;} 350 351 352 /// Manually set the limit mesh index. 353 /** 354 \param limit_mesh_index The limit mesh index. 355 */ 356 virtual void set_limit_mesh_index ( int limit_mesh_index ) = 0; 357 358 359 /// Scale and project the ith component of a vector on the mesh 360 /** 361 \param i The vector component number -- \b IN. 362 \param l The vector component value -- \b IN. 363 \return The ith component of a vector after mesh scaling and projection 364 */ 365 virtual NOMAD::Double scale_and_project(int i, const NOMAD::Double & l) const = 0 ; 366 367 368 }; 369 370 /// Display a NOMAD::OrthogonalMesh object. 371 /** 372 \param out The NOMAD::Display object -- \b IN. 373 \param m The NOMAD::OrthogonalMesh object to be displayed -- \b IN. 374 \return The NOMAD::Display object. 375 */ operator <<(const NOMAD::Display & out,const NOMAD::OrthogonalMesh & m)376 inline const NOMAD::Display & operator << ( const NOMAD::Display & out , 377 const NOMAD::OrthogonalMesh & m ) 378 { 379 m.display ( out ); 380 return out; 381 } 382 } 383 384 #endif 385