NOMAD Source  Version 4.0.0 Beta
LHSearchMethod.cpp
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------------*/
2 /* NOMAD - Nonlinear Optimization by Mesh Adaptive Direct Search - */
3 /* */
4 /* NOMAD - Version 4.0.0 has been created by */
5 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
6 /* Christophe Tribes - Polytechnique Montreal */
7 /* */
8 /* The copyright of NOMAD - version 4.0.0 is owned by */
9 /* Charles Audet - Polytechnique Montreal */
10 /* Sebastien Le Digabel - Polytechnique Montreal */
11 /* Viviane Rochon Montplaisir - Polytechnique Montreal */
12 /* Christophe Tribes - Polytechnique Montreal */
13 /* */
14 /* NOMAD v4 has been funded by Rio Tinto, Hydro-Québec, NSERC (Natural */
15 /* Sciences and Engineering Research Council of Canada), InnovÉÉ (Innovation */
16 /* en Énergie Électrique) and IVADO (The Institute for Data Valorization) */
17 /* */
18 /* NOMAD v3 was created and developed by Charles Audet, Sebastien Le Digabel, */
19 /* Christophe Tribes and Viviane Rochon Montplaisir and was funded by AFOSR */
20 /* and Exxon Mobil. */
21 /* */
22 /* NOMAD v1 and v2 were created and developed by Mark Abramson, Charles Audet, */
23 /* Gilles Couture, and John E. Dennis Jr., and were funded by AFOSR and */
24 /* Exxon Mobil. */
25 /* */
26 /* Contact information: */
27 /* Polytechnique Montreal - GERAD */
28 /* C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada */
29 /* e-mail: nomad@gerad.ca */
30 /* */
31 /* This program is free software: you can redistribute it and/or modify it */
32 /* under the terms of the GNU Lesser General Public License as published by */
33 /* the Free Software Foundation, either version 3 of the License, or (at your */
34 /* option) any later version. */
35 /* */
36 /* This program is distributed in the hope that it will be useful, but WITHOUT */
37 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
38 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License */
39 /* for more details. */
40 /* */
41 /* You should have received a copy of the GNU Lesser General Public License */
42 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
43 /* */
44 /* You can find information on the NOMAD software at www.gerad.ca/nomad */
45 /*---------------------------------------------------------------------------------*/
46 
47 #include "../../Algos/Mads/LHSearchMethod.hpp"
48 #include "../../Algos/Mads/MadsIteration.hpp"
49 #include "../../Math/LHS.hpp"
50 #include "../../Type/LHSearchType.hpp"
51 
52 void NOMAD::LHSearchMethod::init()
53 {
54  _name = "Latin Hypercube Search Method";
55  //setComment("(LHSearch)");
56 
57  auto lhSearch = _runParams->getAttributeValue<NOMAD::LHSearchType>("LH_SEARCH");
58  setEnabled(lhSearch.isEnabled());
59 }
60 
61 
62 void NOMAD::LHSearchMethod::generateTrialPointsImp()
63 {
64 
65  if (nullptr == _iterAncestor)
66  {
67  throw NOMAD::Exception(__FILE__,__LINE__,"LHSearchMethod: must have an iteration ancestor");
68  }
69  auto mesh = _iterAncestor->getMesh();
70  if (nullptr == mesh)
71  {
72  throw NOMAD::Exception(__FILE__,__LINE__,"LHSearchMethod: must have a mesh");
73  }
74  auto frameCenter = _iterAncestor->getFrameCenter();
75  if (nullptr == frameCenter)
76  {
77  throw NOMAD::Exception(__FILE__,__LINE__,"LHSearchMethod: must have a frameCenter");
78  }
79 
80  auto lhSearch = _runParams->getAttributeValue<NOMAD::LHSearchType>("LH_SEARCH");
81  size_t n = _pbParams->getAttributeValue<size_t>("DIMENSION");
82  size_t p = (0 == _iterAncestor->getK()) ? lhSearch.getNbInitial() : lhSearch.getNbIteration();
83  auto lowerBound = _pbParams->getAttributeValue<NOMAD::ArrayOfDouble>("LOWER_BOUND");
84  auto upperBound = _pbParams->getAttributeValue<NOMAD::ArrayOfDouble>("UPPER_BOUND");
85 
86 
87  // Update undefined values of lower and upper bounds to use values based
88  // on DeltaFrameSize.
89  // Based on the code in NOMAD 3, but slightly different.
90  // If we used INF values instead of these, we get huge values for the
91  // generated points. It is not elegant.
92  NOMAD::ArrayOfDouble deltaFrameSize = mesh->getDeltaFrameSize();
93  NOMAD::Double scaleFactor = sqrt(-log(NOMAD::DEFAULT_EPSILON));
94 
95  for (size_t i = 0; i < n; i++)
96  {
97  if (!lowerBound[i].isDefined())
98  {
99  lowerBound[i] = (*frameCenter)[i] - 10.0 * deltaFrameSize[i] * scaleFactor;
100  }
101  if (!upperBound[i].isDefined())
102  {
103  upperBound[i] = (*frameCenter)[i] + 10.0 * deltaFrameSize[i] * scaleFactor;
104  }
105  }
106 
107  // Apply Latin Hypercube algorithm
108  NOMAD::LHS lhs(n, p, lowerBound, upperBound);
109  auto pointVector = lhs.Sample();
110 
111  // Insert the point. Projection on mesh and snap to bounds is done in SearchMethod
112  for (auto point : pointVector)
113  {
114  // Insert point (if possible)
115  insertTrialPoint(NOMAD::EvalPoint(point));
116 
117  }
118 }
DEFAULT_EPSILON
const double DEFAULT_EPSILON
Default epsilon used by Double.
Definition: defines.hpp:108