Mantid
Loading...
Searching...
No Matches
IFuncMinimizer.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
11
12namespace Mantid::API {
13
20bool IFuncMinimizer::minimize(size_t maxIterations) {
21 m_errorString = ""; // iterate() may modify it
22 size_t iter = 0;
23 bool success = false;
24 do {
25 if (!iterate(iter)) {
26 success = m_errorString.empty() || m_errorString == "success";
27 if (success) {
28 m_errorString = "success";
29 }
30 break;
31 }
32 iter++;
33 } while (iter < maxIterations);
34
35 if (iter >= maxIterations) {
36 success = false;
37 if (!m_errorString.empty()) {
38 m_errorString += '\n';
39 }
40 m_errorString += "Failed to converge after " + std::to_string(maxIterations) + " iterations.";
41 }
42
43 return success;
44}
45
46} // namespace Mantid::API
virtual bool iterate(size_t iteration)=0
Do one iteration.
std::string m_errorString
Error string.
virtual bool minimize(size_t maxIterations=1000)
Perform iteration with minimizer and return true if successful.
std::string to_string(const wide_integer< Bits, Signed > &n)