$treeview $search $mathjax
StdAir Logo  1.00.2
$projectbrief
$projectbrief
$searchbox

stdair/basic/OptimisationMethod.cpp

Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 #include <sstream>
00007 // StdAir
00008 #include <stdair/stdair_exceptions.hpp>
00009 #include <stdair/basic/OptimisationMethod.hpp>
00010 
00011 namespace stdair {
00012   
00013   // //////////////////////////////////////////////////////////////////////
00014   const std::string OptimisationMethod::_labels[LAST_VALUE] =
00015     { "Leg based Monte Carlo", "Leg based EMSRb"};
00016 
00017   // //////////////////////////////////////////////////////////////////////
00018   const char OptimisationMethod::
00019   _methodLabels[LAST_VALUE] = { 'M', 'E'};
00020 
00021   
00022   // //////////////////////////////////////////////////////////////////////
00023   OptimisationMethod::OptimisationMethod()
00024     : _method (LAST_VALUE) {
00025     assert (false);
00026   }
00027 
00028   // //////////////////////////////////////////////////////////////////////
00029   OptimisationMethod::
00030   OptimisationMethod (const OptimisationMethod& iOptimisationMethod)
00031     : _method (iOptimisationMethod._method) {
00032   }
00033 
00034   // //////////////////////////////////////////////////////////////////////
00035   OptimisationMethod::
00036   OptimisationMethod (const EN_OptimisationMethod& iOptimisationMethod)
00037     : _method (iOptimisationMethod) {
00038   }
00039 
00040   // //////////////////////////////////////////////////////////////////////
00041   OptimisationMethod::OptimisationMethod (const char iMethod) {
00042     switch (iMethod) {
00043     case 'M': _method = LEG_BASED_MC; break;
00044     case 'E': _method = LEG_BASED_EMSR_B; break;
00045     default: _method = LAST_VALUE; break;
00046     }
00047 
00048     if (_method == LAST_VALUE) {
00049       const std::string& lLabels = describeLabels();
00050       std::ostringstream oMessage;
00051       oMessage << "The optimisation method '" << iMethod
00052                << "' is not known. Known optimisation methods: " << lLabels;
00053       throw CodeConversionException (oMessage.str());
00054     }
00055   }
00056   
00057   // //////////////////////////////////////////////////////////////////////
00058   const std::string& OptimisationMethod::
00059   getLabel (const EN_OptimisationMethod& iMethod) {
00060     return _labels[iMethod];
00061   }
00062   
00063   // //////////////////////////////////////////////////////////////////////
00064   char OptimisationMethod::getMethodLabel (const EN_OptimisationMethod& iMethod) {
00065     return _methodLabels[iMethod];
00066   }
00067 
00068   // //////////////////////////////////////////////////////////////////////
00069   std::string OptimisationMethod::
00070   getMethodLabelAsString (const EN_OptimisationMethod& iMethod) {
00071     std::ostringstream oStr;
00072     oStr << _methodLabels[iMethod];
00073     return oStr.str();
00074   }
00075 
00076   // //////////////////////////////////////////////////////////////////////
00077   std::string OptimisationMethod::describeLabels() {
00078     std::ostringstream ostr;
00079     for (unsigned short idx = 0; idx != LAST_VALUE; ++idx) {
00080       if (idx != 0) {
00081         ostr << ", ";
00082       }
00083       ostr << _labels[idx] << " (" << _methodLabels[idx] << ")";
00084     }
00085     return ostr.str();
00086   }
00087 
00088   // //////////////////////////////////////////////////////////////////////
00089   OptimisationMethod::EN_OptimisationMethod OptimisationMethod::getMethod() const {
00090     return _method;
00091   }
00092   
00093   // //////////////////////////////////////////////////////////////////////
00094   std::string OptimisationMethod::getMethodAsString() const {
00095     std::ostringstream oStr;
00096     oStr << _methodLabels[_method];
00097     return oStr.str();
00098   }
00099   
00100   // //////////////////////////////////////////////////////////////////////
00101   const std::string OptimisationMethod::describe() const {
00102     std::ostringstream ostr;
00103     ostr << _labels[_method];
00104     return ostr.str();
00105   }
00106 
00107   // //////////////////////////////////////////////////////////////////////
00108   bool OptimisationMethod::
00109   operator== (const EN_OptimisationMethod& iMethod) const {
00110     return (_method == iMethod);
00111   }
00112   
00113 }