RMOL Logo  1.00.8
C++ library of Revenue Management and Optimisation classes and functions
OptimizationType.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 #include <sstream>
7 // StdAir
8 #include <stdair/stdair_exceptions.hpp>
9 // RMOL
11 
12 namespace RMOL {
13 
14  // //////////////////////////////////////////////////////////////////////
21  const std::string OptimizationType::_labels[LAST_VALUE] =
22  { "OptimalByMC", "OptimalByDP",
23  "HeuristicByEMSR", "HeuristicByEMSRa", "HeuristicByEMSRb",
24  "HeuristicByMCForQFF", "HeuristicByEMSRbForQFF", "HeuristicByMRTForQFF" };
25 
26  // //////////////////////////////////////////////////////////////////////
27  const char OptimizationType::
28  _typeLabels[LAST_VALUE] = { 'M', 'D', 'E', 'A', 'B', 'Q', 'C', 'R' };
29 
30  // //////////////////////////////////////////////////////////////////////
31  OptimizationType::OptimizationType()
32  : _type (LAST_VALUE) {
33  assert (false);
34  }
35 
36  // //////////////////////////////////////////////////////////////////////
37  OptimizationType::OptimizationType (const OptimizationType& iOptimizationType)
38  : _type (iOptimizationType._type) {
39  }
40 
41  // //////////////////////////////////////////////////////////////////////
42  OptimizationType::
43  OptimizationType (const EN_OptimizationType& iOptimizationType)
44  : _type (iOptimizationType) {
45  }
46 
47  // //////////////////////////////////////////////////////////////////////
48  OptimizationType::OptimizationType (const char iType) {
49  switch (iType) {
50  case 'M': _type = OPT_MC; break;
51  case 'D': _type = OPT_DP; break;
52  case 'E': _type = HEUR_EMSR; break;
53  case 'A': _type = HEUR_EMSRA; break;
54  case 'B': _type = HEUR_EMSRB; break;
55  case 'Q': _type = HEUR_MC_4_QFF; break;
56  case 'C': _type = HEUR_EMSRB_4_QFF; break;
57  case 'R': _type = HEUR_MRT_QFF; break;
58  default: _type = LAST_VALUE; break;
59  }
60 
61  if (_type == LAST_VALUE) {
62  const std::string& lLabels = describeLabels();
63  std::ostringstream oMessage;
64  oMessage << "The optimization type '" << iType
65  << "' is not known. Known optimization types: " << lLabels;
66  throw stdair::CodeConversionException (oMessage.str());
67  }
68  }
69 
70  // //////////////////////////////////////////////////////////////////////
71  OptimizationType::OptimizationType (const std::string& iTypeStr) {
72  for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
73  if (iTypeStr.compare(_labels[idx]) == 0) {
74  _type = static_cast<EN_OptimizationType> (idx);
75  break;
76  } else {
77  _type = LAST_VALUE;
78  }
79  }
80  if (_type == LAST_VALUE) {
81  const std::string& lLabels = describeLabels();
82  std::ostringstream oMessage;
83  oMessage << "The optimization type '" << iTypeStr
84  << "' is not known. Known optimization types: " << lLabels;
85  throw stdair::CodeConversionException (oMessage.str());
86  }
87  }
88 
89  // //////////////////////////////////////////////////////////////////////
90  const std::string& OptimizationType::
91  getLabel (const EN_OptimizationType& iType) {
92  return _labels[iType];
93  }
94 
95  // //////////////////////////////////////////////////////////////////////
97  return _typeLabels[iType];
98  }
99 
100  // //////////////////////////////////////////////////////////////////////
101  std::string OptimizationType::
103  std::ostringstream oStr;
104  oStr << _typeLabels[iType];
105  return oStr.str();
106  }
107 
108  // //////////////////////////////////////////////////////////////////////
110  std::ostringstream ostr;
111  for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
112  if (idx != 0) {
113  ostr << ", ";
114  }
115  ostr << _labels[idx];
116  }
117  return ostr.str();
118  }
119 
120  // //////////////////////////////////////////////////////////////////////
122  return _type;
123  }
124 
125  // //////////////////////////////////////////////////////////////////////
126  std::string OptimizationType::getTypeAsString() const {
127  std::ostringstream oStr;
128  oStr << _typeLabels[_type];
129  return oStr.str();
130  }
131 
132  // //////////////////////////////////////////////////////////////////////
133  const std::string OptimizationType::describe() const {
134  std::ostringstream ostr;
135  ostr << _labels[_type];
136  return ostr.str();
137  }
138 
139  // //////////////////////////////////////////////////////////////////////
141  return (_type == iType);
142  }
143 
144 }
Definition: BasConst.cpp:7
EN_OptimizationType getType() const
bool operator==(const EN_OptimizationType &) const
static const std::string & getLabel(const EN_OptimizationType &)
const std::string describe() const
std::string getTypeAsString() const
static char getTypeLabel(const EN_OptimizationType &)
static std::string getTypeLabelAsString(const EN_OptimizationType &)
static std::string describeLabels()