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: Christophe Tribes */ 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 XMesh.hpp 38 \brief Class for the xmesh (extensible mesh) (headers) 39 \author Christophe Tribes 40 \date 2014-07 41 \see XMesh.cpp 42 */ 43 #ifndef __XMESH__ 44 #define __XMESH__ 45 46 #include "OrthogonalMesh.hpp" 47 48 namespace NOMAD { 49 50 /// Class for the MADS Xmesh. 51 /** 52 - The Xmesh in NOMAD is defined with the basic directions and the 53 mesh size parameter delta^k for each coordinate. 54 */ 55 56 class XMesh : public NOMAD::OrthogonalMesh { 57 58 /*--------------------------------------------------------------*/ 59 private: 60 61 NOMAD::Point _r; // Mesh index per coordinate. 62 NOMAD::Point _r_min; 63 NOMAD::Point _r_max; 64 bool _anisotropic_mesh; 65 66 67 68 /*--------------------------------------------------------------*/ 69 70 /// Private affectation operator. 71 /** 72 \param m The right-hand side object -- \b IN. 73 */ 74 const XMesh & operator = ( const XMesh & m ); 75 76 /// Check the minimal poll size criterion. 77 bool check_min_poll_size_criterion ( ) const; 78 79 /// Check the minimal mesh size criterion. 80 bool check_min_mesh_size_criterion ( ) const; 81 82 83 /// Access to the mesh size parameter delta^k. 84 /** 85 \return delta The mesh size parameter delta^k -- \b OUT. 86 \param i The index of the mesh size 87 */ 88 NOMAD::Double get_delta ( int i ) const ; 89 90 91 /// Access to the poll size parameter Delta^k. 92 /** 93 \return Delta The poll size parameter Delta^k -- \b OUT. 94 \param i The index of the poll size 95 */ 96 NOMAD::Double get_Delta ( int i ) const ; 97 98 void init ( ); 99 100 public: 101 102 /// Constructor. 103 /** 104 \param anistropic_mesh Use anisotropic mesh or not -- \b IN. 105 \param Delta_0 Initial poll size Delta^0 -- \b IN. 106 \param Delta_min Minimal poll size Delta^min (may be undefined) -- \b IN. 107 \param delta_min Minimal mesh size delta^min (may be undefined) -- \b IN. 108 \param poll_update_basis Poll update basis (b); default=2 -- \b IN. 109 \param poll_coarsening_step Poll coarsening step (w+); default=1 -- \b IN. 110 \param poll_refining_step Poll refining step (w-); default=-1 -- \b IN. 111 \param fixed_variables Fixed variables -- \b IN. 112 \param limit_min_mesh_index Limit mesh index (<0) -- \b IN. 113 */ XMesh(bool anisotropic_mesh,const NOMAD::Point & Delta_0,const NOMAD::Point & Delta_min,const NOMAD::Point & delta_min,const NOMAD::Point & fixed_variables,NOMAD::Double poll_update_basis=2.0,int poll_coarsening_step=1,int poll_refining_step=-1,int limit_min_mesh_index=NOMAD::XL_LIMITS)114 XMesh (bool anisotropic_mesh, 115 const NOMAD::Point & Delta_0 , 116 const NOMAD::Point & Delta_min , 117 const NOMAD::Point & delta_min , 118 const NOMAD::Point & fixed_variables, 119 NOMAD::Double poll_update_basis=2.0, 120 int poll_coarsening_step=1, 121 int poll_refining_step=-1 , 122 int limit_min_mesh_index=NOMAD::XL_LIMITS ) 123 : NOMAD::OrthogonalMesh ( Delta_0, 124 Delta_min, 125 delta_min, 126 fixed_variables, 127 poll_update_basis, 128 poll_coarsening_step, 129 poll_refining_step , 130 limit_min_mesh_index ), 131 _anisotropic_mesh ( anisotropic_mesh ){ init();} 132 133 134 135 136 /// Copy constructor. 137 /** 138 \param m The copied object -- \b IN. 139 */ XMesh(const XMesh & m)140 XMesh ( const XMesh & m ) 141 : OrthogonalMesh ( m ) , 142 _r ( m._r ), 143 _r_min ( m._r_min ), 144 _r_max ( m._r_max ), 145 _anisotropic_mesh ( m._anisotropic_mesh ){} 146 147 /// Destructor. ~XMesh(void)148 ~XMesh ( void ) 149 { 150 _delta_0.clear(); 151 _Delta_0.clear(); 152 _delta_min.clear(); 153 _Delta_min.clear(); 154 } 155 156 157 /// Access to the mesh size parameter delta^k for earch coordinate. 158 /** 159 - It is a NOMAD::Point of size \c nc the number of free variables. 160 \param delta The mesh size parameter delta^k -- \b OUT. 161 -- \b optional (default = the current mesh index ell_k.) 162 \return A boolean equal to \c true if all values are 163 strictly inferior than the associated minimal 164 mesh size delta_min (stopping criterion MIN_MESH_SIZE). 165 */ 166 bool get_delta ( NOMAD::Point & delta ) const ; 167 168 169 /// Access to the largest mesh size for earch coordinate. 170 /** 171 \return delta_max 172 */ get_delta_max(void) const173 NOMAD::Point get_delta_max ( void ) const { return _delta_0;} 174 175 176 /// Access to the poll size Delta^k for each coordinate. 177 /** 178 - It is a NOMAD::Point of size \c nc the number of free variables. 179 \param Delta The poll size parameter Delta^k -- \b OUT. 180 \return A boolean equal to \c true if all values are 181 strictly inferior than the associated minimal 182 poll size Delta_min 183 (stopping criterion MIN_POLL_SIZE). 184 */ 185 bool get_Delta ( NOMAD::Point & Delta) const ; 186 187 188 /// Update the provided mesh indices (the Mesh is unchanged). 189 /** 190 \param success Type of success of the iteration -- \b IN. 191 \param mesh_indices The mesh indices before and after the update -- \b IN/OUT. 192 \param dir The direction that is considered (opt) -- \b IN. 193 */ 194 void update ( NOMAD::success_type success , NOMAD::Point & mesh_indices, const NOMAD::Direction *dir=NULL ) const ; 195 196 197 /// Test if mesh finer than initial. 198 /** 199 \return True if mesh size is smaller than initial mesh size for all components; False otherwise. 200 */ is_finer_than_initial(void) const201 bool is_finer_than_initial (void) const {return true;} 202 203 204 205 /// Update the XMesh (poll and mesh sizes). 206 /** 207 \param success Type of success of the iteration -- \b IN. 208 \param dir Direction of the iteration -- \b IN. 209 */ 210 void update ( NOMAD::success_type success, const NOMAD::Direction * dir=NULL); 211 212 /// Reset the mesh to its original size (mesh indices). reset(void)213 void reset ( void ) { init() ;} 214 215 216 /// Display. 217 /** 218 \param out The NOMAD::Display object -- \b IN. 219 */ 220 void display ( const NOMAD::Display & out ) const; 221 222 /// Test if r < r_min so far for all coordinates. 223 /** 224 \return True if mesh is the finest so far, False otherwise. 225 */ 226 bool is_finest ( void ) const; 227 228 229 /// Scale and project the ith component of a vector on the mesh 230 /** 231 \param i The vector component number -- \b IN. 232 \param l The vector component value -- \b IN. 233 \return The ith component of a vector after mesh scaling and projection 234 */ 235 NOMAD::Double scale_and_project(int i, const NOMAD::Double & l) const ; 236 237 238 /// Check the stopping conditions on the minimal poll and mesh sizes. 239 /** 240 \param stop Stop flag -- \b IN/OUT. 241 \param stop_reason Stop reason -- \b OUT. 242 */ 243 void check_min_mesh_sizes ( bool & stop , 244 NOMAD::stop_type & stop_reason ) const; 245 246 /// Access to the mesh indices per coordinate. 247 /** 248 \return A point with the mesh index for each coordinate. 249 */ get_mesh_indices(void) const250 const NOMAD::Point get_mesh_indices ( void ) const { return _r; } 251 252 /// Access to the min mesh indices reached so far. 253 /** 254 \return A point with the mesh index for each coordinate. 255 */ get_min_mesh_indices(void) const256 const NOMAD::Point get_min_mesh_indices ( void ) const { return _r_min; } 257 258 259 /// Access to the max mesh indices reached so far. 260 /** 261 \return A point with the mesh index for each coordinate. 262 */ get_max_mesh_indices(void) const263 const NOMAD::Point get_max_mesh_indices ( void ) const { return _r_max; } 264 265 266 /// Manually set the mesh index. 267 /** 268 \param r The mesh index provided as a point -- \b IN. 269 */ 270 void set_mesh_indices ( const NOMAD::Point & r ); 271 272 273 274 /// Manually set the limit mesh index (termination criterion). 275 /** 276 \param l The limit mesh index for all coordinates -- \b IN. 277 */ 278 void set_limit_mesh_index ( int l ); 279 280 281 282 /// Access to the mesh ratios after a success 283 /** 284 \return A point with the ratio for each coordinate 285 */ 286 NOMAD::Point get_mesh_ratio_if_success ( void ) const; 287 288 289 290 }; 291 292 /// Display a NOMAD::XMesh object. 293 /** 294 \param out The NOMAD::Display object -- \b IN. 295 \param m The NOMAD::XMesh object to be displayed -- \b IN. 296 \return The NOMAD::Display object. 297 */ operator <<(const NOMAD::Display & out,const NOMAD::XMesh & m)298 inline const NOMAD::Display & operator << ( const NOMAD::Display & out , 299 const NOMAD::XMesh & m ) 300 { 301 m.display ( out ); 302 return out; 303 } 304 305 } 306 307 #endif 308