BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
MinimizerOptions Class Reference

Collection of internal minimizer settings. More...

Inheritance diagram for MinimizerOptions:
[legend]
Collaboration diagram for MinimizerOptions:
[legend]

Public Types

using const_iterator = container_t::const_iterator
 
using container_t = std::vector< option_t >
 
using iterator = container_t::iterator
 
using option_t = std::shared_ptr< MultiOption >
 

Public Member Functions

template<class T >
option_t addOption (const std::string &optionName, T value, const std::string &description="")
 
iterator begin ()
 
const_iterator begin () const
 
bool empty () const
 
iterator end ()
 
const_iterator end () const
 
option_t option (const std::string &optionName)
 
const option_t option (const std::string &optionName) const
 
template<class T >
optionValue (const std::string &optionName) const
 
void setOptionString (const std::string &options)
 Set options from their string representation. More...
 
template<class T >
void setOptionValue (const std::string &optionName, T value)
 Sets the value of option. Option should hold same value type already. More...
 
size_t size () const
 
std::string toOptionString () const
 Returns string with all options (i.e. "Strategy=1;Tolerance=0.01;") More...
 

Protected Member Functions

bool exists (const std::string &name)
 
void swapContent (OptionContainer &other)
 

Protected Attributes

container_t m_options
 

Private Member Functions

void processCommand (const std::string &command)
 Process single option string 'Tolerance=0.01' and sets the value to corresponding MultiOption. More...
 

Detailed Description

Collection of internal minimizer settings.

Definition at line 28 of file MinimizerOptions.h.

Member Typedef Documentation

◆ const_iterator

using OptionContainer::const_iterator = container_t::const_iterator
inherited

Definition at line 37 of file OptionContainer.h.

◆ container_t

using OptionContainer::container_t = std::vector<option_t>
inherited

Definition at line 35 of file OptionContainer.h.

◆ iterator

using OptionContainer::iterator = container_t::iterator
inherited

Definition at line 36 of file OptionContainer.h.

◆ option_t

using OptionContainer::option_t = std::shared_ptr<MultiOption>
inherited

Definition at line 34 of file OptionContainer.h.

Member Function Documentation

◆ addOption()

template<class T >
OptionContainer::option_t OptionContainer::addOption ( const std::string &  optionName,
value,
const std::string &  description = "" 
)
inherited

Definition at line 70 of file OptionContainer.h.

72 {
73  if (exists(optionName))
74  throw std::runtime_error("OptionContainer::addOption() -> Error. Option '" + optionName
75  + "' exists.");
76 
77  option_t result(new MultiOption(optionName, value, description));
78  m_options.push_back(result);
79  return result;
80 }
Stores a single option for minimization algorithm.
Definition: MultiOption.h:30
std::shared_ptr< MultiOption > option_t
container_t m_options
bool exists(const std::string &name)

References OptionContainer::exists(), and OptionContainer::m_options.

Referenced by MinimizerAdapter::addOption().

Here is the call graph for this function:

◆ begin() [1/2]

iterator OptionContainer::begin ( )
inlineinherited

Definition at line 54 of file OptionContainer.h.

54 { return m_options.begin(); }

References OptionContainer::m_options.

◆ begin() [2/2]

const_iterator OptionContainer::begin ( ) const
inlineinherited

Definition at line 55 of file OptionContainer.h.

55 { return m_options.begin(); }

References OptionContainer::m_options.

◆ empty()

bool OptionContainer::empty ( ) const
inlineinherited

Definition at line 61 of file OptionContainer.h.

61 { return size() == 0; }
size_t size() const

References OptionContainer::size().

Here is the call graph for this function:

◆ end() [1/2]

iterator OptionContainer::end ( )
inlineinherited

Definition at line 57 of file OptionContainer.h.

57 { return m_options.end(); }

References OptionContainer::m_options.

◆ end() [2/2]

const_iterator OptionContainer::end ( ) const
inlineinherited

Definition at line 58 of file OptionContainer.h.

58 { return m_options.end(); }

References OptionContainer::m_options.

◆ exists()

bool OptionContainer::exists ( const std::string &  name)
protectedinherited

Definition at line 56 of file OptionContainer.cpp.

57 {
58  for (const auto& option : m_options) {
59  if (option->name() == name)
60  return true;
61  }
62  return false;
63 }
option_t option(const std::string &optionName)
QString const & name(EShape k)
Definition: particles.cpp:21

References OptionContainer::m_options, RealSpace::Particles::name(), and OptionContainer::option().

Referenced by OptionContainer::addOption().

Here is the call graph for this function:

◆ option() [1/2]

OptionContainer::option_t OptionContainer::option ( const std::string &  optionName)
inherited

Definition at line 34 of file OptionContainer.cpp.

35 {
36  for (const auto& option : m_options) {
37  if (option->name() == optionName)
38  return option;
39  }
40 
41  throw std::runtime_error("Configurable::getOption() -> Error. No option with name '"
42  + optionName + "'.");
43 }

References OptionContainer::m_options.

Referenced by OptionContainer::OptionContainer(), OptionContainer::exists(), OptionContainer::option(), OptionContainer::optionValue(), processCommand(), OptionContainer::setOptionValue(), and toOptionString().

◆ option() [2/2]

const OptionContainer::option_t OptionContainer::option ( const std::string &  optionName) const
inherited

Definition at line 45 of file OptionContainer.cpp.

46 {
47  for (const auto& option : m_options) {
48  if (option->name() == optionName)
49  return option;
50  }
51 
52  throw std::runtime_error("Configurable::getOption() -> Error. No option with name '"
53  + optionName + "'.");
54 }

References OptionContainer::m_options, and OptionContainer::option().

Here is the call graph for this function:

◆ optionValue()

template<class T >
T OptionContainer::optionValue ( const std::string &  optionName) const
inherited

Definition at line 82 of file OptionContainer.h.

83 {
84  return option(optionName)->get<T>();
85 }

References OptionContainer::option().

Referenced by MinimizerAdapter::optionValue().

Here is the call graph for this function:

◆ processCommand()

void MinimizerOptions::processCommand ( const std::string &  command)
private

Process single option string 'Tolerance=0.01' and sets the value to corresponding MultiOption.

Definition at line 53 of file MinimizerOptions.cpp.

54 {
55  std::vector<std::string> tokens = mumufit::stringUtils::split(command, "=");
56  if (tokens.size() != 2)
57  throw std::runtime_error("MinimizerOptions::processOption() -> Can't parse option '"
58  + command + "'");
59 
60  std::string name = tokens[0];
61  std::string value = tokens[1];
62 
64  opt->setFromString(value);
65 }
std::vector< std::string > split(const std::string &text, const std::string &delimeter)
Split string into vector of string using delimeter.
Definition: StringUtils.cpp:51

References RealSpace::Particles::name(), OptionContainer::option(), and mumufit::stringUtils::split().

Referenced by setOptionString().

Here is the call graph for this function:

◆ setOptionString()

void MinimizerOptions::setOptionString ( const std::string &  options)

Set options from their string representation.

Definition at line 34 of file MinimizerOptions.cpp.

35 {
36  // splits multiple option string "Strategy=1;Tolerance=0.01;"
37  std::vector<std::string> tokens = mumufit::stringUtils::split(options, delimeter);
38  try {
39  for (std::string opt : tokens)
40  if (!opt.empty())
41  processCommand(opt);
42  } catch (std::exception& ex) {
43  std::ostringstream ostr;
44  ostr << "MinimizerOptions::setOptions() -> Error. Can't parse option string '" << options
45  << "'.\n, error message '" << ex.what() << "'";
46  throw std::runtime_error(ostr.str());
47  }
48 }
void processCommand(const std::string &command)
Process single option string 'Tolerance=0.01' and sets the value to corresponding MultiOption.

References processCommand(), and mumufit::stringUtils::split().

Referenced by MinimizerAdapter::setOptions().

Here is the call graph for this function:

◆ setOptionValue()

template<class T >
void OptionContainer::setOptionValue ( const std::string &  optionName,
value 
)
inherited

Sets the value of option. Option should hold same value type already.

Definition at line 87 of file OptionContainer.h.

88 {
89  option(optionName)->value() = value;
90  if (option(optionName)->value().which() != option(optionName)->defaultValue().which())
91  throw std::runtime_error(
92  "OptionContainer::setOptionValue() -> Error. Attempt to set different"
93  "type to option '"
94  + optionName + "'");
95 }

References OptionContainer::option().

Referenced by MinimizerAdapter::setOptionValue().

Here is the call graph for this function:

◆ size()

size_t OptionContainer::size ( ) const
inlineinherited

Definition at line 60 of file OptionContainer.h.

60 { return m_options.size(); }

References OptionContainer::m_options.

Referenced by OptionContainer::empty().

◆ swapContent()

void OptionContainer::swapContent ( OptionContainer other)
protectedinherited

Definition at line 65 of file OptionContainer.cpp.

66 {
68 }
void swap(OutputDataIterator< TValue, TContainer > &left, OutputDataIterator< TValue, TContainer > &right)
make Swappable

References OptionContainer::m_options, and swap().

Referenced by OptionContainer::operator=().

Here is the call graph for this function:

◆ toOptionString()

std::string MinimizerOptions::toOptionString ( ) const

Returns string with all options (i.e. "Strategy=1;Tolerance=0.01;")

Definition at line 25 of file MinimizerOptions.cpp.

26 {
27  std::ostringstream result;
28  for (auto option : m_options) {
29  result << option->name() << "=" << option->value() << delimeter;
30  }
31  return result.str();
32 }

References OptionContainer::m_options, and OptionContainer::option().

Here is the call graph for this function:

Member Data Documentation

◆ m_options


The documentation for this class was generated from the following files: