NOMAD Source  Version 4.0.0 Beta
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Subproblem.cpp
Go to the documentation of this file.
1 /**
2  \file Subproblem.cpp
3  \brief Subproblem of lesser dimension than the original problem
4  \author Viviane Rochon Montplaisir
5  \date February 2019
6  */
7 #include "Subproblem.hpp"
8 #include "../Output/OutputQueue.hpp"
9 
10 
11 /*------------*/
12 /* Subproblem */
13 /*------------*/
14 void NOMAD::Subproblem::init()
15 {
16  if (nullptr == _refPbParams)
17  {
18  throw NOMAD::Exception(__FILE__, __LINE__,
19  "A valid PbParameters must be provided to the Subproblem constructor.");
20  }
21 
22  // Compute new dimension
23  auto nbFixed = _fixedVariable.nbDefined();
24  const size_t refDimension = _refPbParams->getAttributeValue<size_t>("DIMENSION");
25  _dimension = refDimension - nbFixed;
26 
27  std::string s = "FIXED_VARIABLE set to " + _fixedVariable.display();
28  NOMAD::OutputQueue::Add(s, NOMAD::OutputLevel::LEVEL_INFO);
29 
30  setupProblemParameters();
31 }
32 
33 
34 NOMAD::Subproblem::~Subproblem()
35 {
36 }
37 
38 
39 void NOMAD::Subproblem::setupProblemParameters()
40 {
41  // VRM Note: If a new parameter is added to the class PbParameters,
42  // this method will break.
43  // It could be generalized by going through each parameter, and adjust it only
44  // if it is an ArrayOfDouble, Point, or Dimension. Backlog task.
45  const size_t refDimension = _refPbParams->getAttributeValue<size_t>("DIMENSION");
46  size_t n = _dimension;
47 
48  _subPbParams = std::make_shared<NOMAD::PbParameters>();
49  _subPbParams->setAttributeValue("DIMENSION", n);
50 
51  // Get reference values for parameters
52  const auto refX0s = _refPbParams->getAttributeValue<NOMAD::ArrayOfPoint>("X0");
53  const auto refLowerBound = _refPbParams->getAttributeValue<NOMAD::ArrayOfDouble>("LOWER_BOUND");
54  const auto refUpperBound = _refPbParams->getAttributeValue<NOMAD::ArrayOfDouble>("UPPER_BOUND");
55  const auto refBBInputType = _refPbParams->getAttributeValue<NOMAD::BBInputTypeList>("BB_INPUT_TYPE");
56  const auto refInitMeshSize = _refPbParams->getAttributeValue<NOMAD::ArrayOfDouble>("INITIAL_MESH_SIZE");
57  const auto refInitFrameSize = _refPbParams->getAttributeValue<NOMAD::ArrayOfDouble>("INITIAL_FRAME_SIZE");
58  const auto refMinMeshSize = _refPbParams->getAttributeValue<NOMAD::ArrayOfDouble>("MIN_MESH_SIZE");
59  const auto refMinFrameSize = _refPbParams->getAttributeValue<NOMAD::ArrayOfDouble>("MIN_FRAME_SIZE");
60  const auto refGranularity = _refPbParams->getAttributeValue<NOMAD::ArrayOfDouble>("GRANULARITY");
61 
62  // Initialize new arrays
64  for (size_t x0index = 0; x0index < refX0s.size(); x0index++)
65  {
66  NOMAD::Point x0(n);
67  x0s.push_back(x0);
68  }
69  NOMAD::ArrayOfDouble lb(n), ub(n);
70  NOMAD::BBInputTypeList bbInputType;
71  NOMAD::ArrayOfDouble initialMeshSize(n), initialFrameSize(n), minMeshSize(n), minFrameSize(n);
72  NOMAD::ArrayOfDouble granularity(n);
73 
74  // Compute new values, simply using the values on the positions of non-fixed variables.
75  // VRM TODO: Use Converter.
76  size_t i = 0;
77  for (size_t refIndex = 0; refIndex < refDimension; refIndex++)
78  {
79  if (_fixedVariable[refIndex].isDefined())
80  {
81  continue;
82  }
83 
84  for (size_t x0index = 0; x0index < refX0s.size(); x0index++)
85  {
86  auto refX0 = refX0s[x0index];
87  x0s[x0index][i] = refX0[refIndex];
88  }
89  lb[i] = refLowerBound[refIndex];
90  ub[i] = refUpperBound[refIndex];
91  bbInputType.push_back(refBBInputType[refIndex]);
92  initialMeshSize[i] = refInitMeshSize[refIndex];
93  initialFrameSize[i] = refInitFrameSize[refIndex];
94  minMeshSize[i] = refMinMeshSize[refIndex];
95  minFrameSize[i] = refMinFrameSize[refIndex];
96  granularity[i] = refGranularity[refIndex];
97 
98  i++;
99  }
100 
101  // Set new values to _subPbParams
102  _subPbParams->setAttributeValue("X0", x0s);
103  _subPbParams->setAttributeValue("LOWER_BOUND", lb);
104  _subPbParams->setAttributeValue("UPPER_BOUND", ub);
105  _subPbParams->setAttributeValue("BB_INPUT_TYPE", bbInputType);
106  _subPbParams->setAttributeValue("INITIAL_MESH_SIZE", initialMeshSize);
107  _subPbParams->setAttributeValue("INITIAL_FRAME_SIZE", initialFrameSize);
108  _subPbParams->setAttributeValue("MIN_MESH_SIZE", minMeshSize);
109  _subPbParams->setAttributeValue("MIN_FRAME_SIZE", minFrameSize);
110  _subPbParams->setAttributeValue("GRANULARITY", granularity);
111 
112 
113  _subPbParams->checkAndComply();
114 }
std::vector< BBInputType > BBInputTypeList
Definition: BBInputType.hpp:32
std::vector< Point > ArrayOfPoint
Representation of a vector of points.
Subproblem of lesser dimension than the original problem.