BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MinimizerCatalog.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Fit/Minimizer/MinimizerCatalog.cpp
6 //! @brief Implements class MinimizerCatalog.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
17 #include <boost/format.hpp>
18 #include <sstream>
19 
21 {
28 }
29 
30 //! Returns multiline string representing catalog content.
31 
32 std::string MinimizerCatalog::toString() const
33 {
34  const int text_width = 80;
35  std::ostringstream result;
36 
37  result << std::string(text_width, '-') << "\n";
38  result << boost::format("%-15s|%-65s\n") % "Minimizer" % " Algorithms";
39  result << std::string(text_width, '-') << "\n";
40 
41  for (const auto& info : m_minimizers) {
42  result << boost::format("%-15s| %-64s\n") % info.name()
43  % MinimizerUtils::toString(info.algorithmNames(), " ");
44  }
45  return result.str();
46 }
47 
48 std::vector<std::string> MinimizerCatalog::minimizerNames() const
49 {
50  std::vector<std::string> result;
51  for (const auto& info : m_minimizers)
52  result.push_back(info.name());
53 
54  return result;
55 }
56 
57 //! Returns list of algorithms defined for the minimizer with a given name.
58 
59 std::vector<std::string> MinimizerCatalog::algorithmNames(const std::string& minimizerName) const
60 {
61  return minimizerInfo(minimizerName).algorithmNames();
62 }
63 
64 //! Returns list of algorithm's descriptions for the minimizer with a given name .
65 
66 std::vector<std::string>
67 MinimizerCatalog::algorithmDescriptions(const std::string& minimizerName) const
68 {
69  return minimizerInfo(minimizerName).algorithmDescriptions();
70 }
71 
72 //! Returns info for minimizer with given name.
73 
74 const MinimizerInfo& MinimizerCatalog::minimizerInfo(const std::string& minimizerName) const
75 {
76  for (const auto& info : m_minimizers)
77  if (info.name() == minimizerName)
78  return info;
79 
80  throw std::runtime_error("MinimizerCatalog::minimizerInfo -> Error. "
81  "No minimizer with the name '"
82  + minimizerName + "'");
83 }
84 
85 //! Adds minimizer info to the catalog.
86 
88 {
89  m_minimizers.push_back(info);
90 }
Defines class MinimizerCatalog.
Declares namespace MinimizerUtils.
std::vector< std::string > minimizerNames() const
std::vector< std::string > algorithmDescriptions(const std::string &minimizerName) const
Returns list of algorithm's descriptions for the minimizer with a given name .
const MinimizerInfo & minimizerInfo(const std::string &minimizerName) const
Returns info for minimizer with given name.
std::vector< MinimizerInfo > m_minimizers
std::string toString() const
Returns multiline string representing catalog content.
void addMinimizerInfo(const MinimizerInfo &info)
Adds minimizer info to the catalog.
std::vector< std::string > algorithmNames(const std::string &minimizerName) const
Returns list of algorithms defined for the minimizer with a given name.
Info about a minimizer, including list of defined minimization algorithms.
Definition: MinimizerInfo.h:45
static MinimizerInfo buildGeneticInfo()
Creates information for TMVA genetic minimizer.
static MinimizerInfo buildGSLSimAnInfo()
Creates information for GSL's simmulated annealing algorithm.
std::vector< std::string > algorithmDescriptions() const
Returns list of string with description of all available algorithms.
static MinimizerInfo buildGSLLMAInfo()
Creates information for GSL's Levenberg-Marquardt.
static MinimizerInfo buildGSLMultiMinInfo(const std::string &defaultAlgo="")
Creates information for GSLMultiMinMinimizer.
static MinimizerInfo buildTestMinimizerInfo()
Creates information for simple test minimizer.
std::vector< std::string > algorithmNames() const
Return list of defined algorithm names.
static MinimizerInfo buildMinuit2Info(const std::string &defaultAlgo="")
Creates information for Minuit2Minimizer.
std::string toString(const std::vector< std::string > &v, const std::string &delim="")