NOMAD Source  Version 4.0.0 Beta
BBOutputType.hpp
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  \file BBOutputType.hpp
48  \brief types for BBOutput
49  \author Viviane Rochon Montplaisir
50  \date September 2018
51  \see BBOutput.hpp
52  */
53 #ifndef __NOMAD400_BB_OUTPUT_TYPE__
54 #define __NOMAD400_BB_OUTPUT_TYPE__
55 
56 #include <string>
57 #include <sstream>
58 #include <vector>
59 
60 #include "../nomad_nsbegin.hpp"
61 
62 
63 /// Blackbox output types
64 enum class BBOutputType
65 {
66  OBJ, ///< Objective value
67  EB, ///< Extreme barrier constraint
68  PB, ///< Progressive barrier constraint
69  CNT_EVAL, ///< Output set to 0 or 1 to count the blackbox evaluation or not
70  //STAT_AVG, ///< Stat (average)
71  //STAT_SUM, ///< Stat (sum)
72  BBO_UNDEFINED ///< Output ignored
73 };
74 
75 /// Definition for the list of blackbox output types
76 typedef std::vector<BBOutputType> BBOutputTypeList;
77 
78 typedef BBOutputTypeList::const_iterator BBOutputTypeListIt;
79 
80 
81 /// Utility for BBOutputType
82 /**
83  Convert a string (ex "OBJ", "EB", "PB"...)
84  to a BBOutputType.
85  */
86 BBOutputType stringToBBOutputType(const std::string &s);
87 
88 /// Utility for BBOutputType
89 /**
90  Convert a string containing multiple BBOutputTypes (ex "OBJ EB PB PB")
91  to a BBOutputTypeList.
92  */
93 BBOutputTypeList stringToBBOutputTypeList(const std::string &s);
94 
95 /// Utility for BBOutputType
96 /**
97  Convert a BBOutputTypeList into a string
98  */
99 std::string BBOutputTypeListToString ( const BBOutputTypeList & bbotList );
100 
101 /// Helper to test if a BBOutputType is a constraint (PB, EB, ....)
102 bool BBOutputTypeIsConstraint(const BBOutputType & bbotType);
103 
104 /// Count the number of constraints
105 size_t getNbConstraints(const BBOutputTypeList& bbotList);
106 
107 /// Verify if the BBOutputType defines a constraint
108 bool isConstraint(const BBOutputType& bbot);
109 
110 /// Count the number of objectives
111 size_t getNbObj(const BBOutputTypeList& bbotList);
112 
113 /// Read and interpret BBOutputType
114 inline std::ostream& operator<<(std::ostream& os, const BBOutputType &bbot)
115 {
116  switch (bbot)
117  {
118  case BBOutputType::OBJ:
119  os << "OBJ";
120  break;
121  case BBOutputType::PB:
122  os << "PB";
123  break;
124  case BBOutputType::EB:
125  os << "EB";
126  break;
128  os << "CNT_EVAL";
129  break;
131  default:
132  return os << "BBO_UNDEFINED";
133  break;
134  }
135 
136  return os;
137 }
138 
139 /// Display BBOutputType
140 inline std::ostream& operator<<(std::ostream& out, const BBOutputTypeList &bboutputtypelist)
141 {
143  bool first = true;
144  for (it = bboutputtypelist.begin(); it != bboutputtypelist.end(); ++it)
145  {
146  if (!first)
147  {
148  out << " ";
149  }
150  out << *it;
151  first = false;
152  }
153  return out;
154 }
155 
156 
157 
158 #include "../nomad_nsend.hpp"
159 
160 #endif // __NOMAD400_BB_OUTPUT_TYPE__
getNbConstraints
size_t getNbConstraints(const BBOutputTypeList &bbotList)
Count the number of constraints.
Definition: BBOutputType.cpp:142
isConstraint
bool isConstraint(const BBOutputType &bbot)
Verify if the BBOutputType defines a constraint.
Definition: BBOutputType.cpp:157
stringToBBOutputTypeList
BBOutputTypeList stringToBBOutputTypeList(const std::string &s)
Utility for BBOutputType.
Definition: BBOutputType.cpp:117
BBOutputTypeList
std::vector< BBOutputType > BBOutputTypeList
Definition for the list of blackbox output types.
Definition: BBOutputType.hpp:76
BBOutputType
BBOutputType
Blackbox output types.
Definition: BBOutputType.hpp:64
BBOutputTypeIsConstraint
bool BBOutputTypeIsConstraint(const BBOutputType &bbotType)
Helper to test if a BBOutputType is a constraint (PB, EB, ....)
Definition: BBOutputType.cpp:97
operator<<
std::ostream & operator<<(std::ostream &os, const BBOutputType &bbot)
Read and interpret BBOutputType.
Definition: BBOutputType.hpp:114
stringToBBOutputType
BBOutputType stringToBBOutputType(const std::string &s)
Utility for BBOutputType.
Definition: BBOutputType.cpp:62
BBOutputTypeListToString
std::string BBOutputTypeListToString(const BBOutputTypeList &bbotList)
Utility for BBOutputType.
Definition: BBOutputType.cpp:130
BBOutputTypeListIt
BBOutputTypeList::const_iterator BBOutputTypeListIt
Definition: BBOutputType.hpp:78
BBOutputType::BBO_UNDEFINED
@ BBO_UNDEFINED
Output ignored.
BBOutputType::EB
@ EB
Extreme barrier constraint.
BBOutputType::CNT_EVAL
@ CNT_EVAL
Output set to 0 or 1 to count the blackbox evaluation or not.
BBOutputType::PB
@ PB
Progressive barrier constraint.
getNbObj
size_t getNbObj(const BBOutputTypeList &bbotList)
Count the number of objectives.
Definition: BBOutputType.cpp:170
BBOutputType::OBJ
@ OBJ
Objective value.