11#include <boost/lexical_cast.hpp>
12#include <boost/regex.hpp>
24 :
ParameterReference(funct, funct->parameterIndex(parName), isDefault), m_parser(
std::make_unique<
mu::Parser>()),
26 m_parser->DefineNameChars(
"0123456789_."
27 "abcdefghijklmnopqrstuvwxyz"
28 "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
37 for (std::map<double *, ParameterReference>::const_iterator it =
m_varMap.begin(); it !=
m_varMap.end(); ++it) {
51 auto var =
new double;
63 for (std::map<double *, ParameterReference>::const_iterator it =
m_varMap.begin(); it !=
m_varMap.end(); ++it) {
73 throw std::invalid_argument(
"Function index was not specified in a parameter name");
74 }
catch (std::exception &) {
77 throw std::runtime_error(
"Error in expresseion " + expr);
81 static const boost::regex rx(R
"(\b(([[:alpha:]]|_)([[:alnum:]]|_|\.)*)\b(?!(\s*\()))");
82 std::string input = expr;
84 std::string::const_iterator start = input.begin();
85 std::string::const_iterator end = input.end();
87 std::map<std::string, int> varNames;
89 for (std::map<double *, ParameterReference>::const_iterator it =
m_varMap.begin(); it !=
m_varMap.end(); ++it) {
95 while (boost::regex_search(start, end, res, rx)) {
98 start = res[0].second;
106 for (std::map<double *, ParameterReference>::const_iterator it =
m_varMap.begin(); it !=
m_varMap.end(); ++it) {
107 *(it->first) = it->second.getParameter();
110 }
catch (mu::ParserError &e) {
111 throw std::runtime_error(
"Error in expression: " + e.GetMsg());
114 if (setParameterValue)
129 std::string res_expression;
138 static const boost::regex rx(std::string(
"#(\\d+)"));
140 std::string::const_iterator start =
m_expression.begin();
143 while (boost::regex_search(start, end, res, rx)) {
144 res_expression.append(start, res[0].first);
146 auto iTemp = boost::lexical_cast<int>(res[1]);
156 start = res[0].second;
158 res_expression.append(start, end);
162 return res_expression;
176 [fun](
const auto &element) { return element.second.isParameterOf(fun); });
187 std::vector<ParameterReference> out;
190 [](
auto &&varPair) { return varPair.second; });
This is an interface to a fitting function - a semi-abstarct class.
virtual size_t getParameterIndex(const ParameterReference &ref) const =0
Return parameter index from a parameter reference.
virtual std::string parameterName(size_t i) const =0
Returns the name of parameter i.
virtual size_t parameterIndex(const std::string &name) const =0
Returns the index of parameter name.
A reference to a parameter in a function.
void setParameter(const double &value, bool isExplicitlySet=true)
Set the parameter.
IFunction * getLocalFunction() const
Return pointer to the local function.
virtual void set(const std::string &expr)
Set the tie expression.
std::map< double *, ParameterReference > m_varMap
Store for parameters used in the tie.
std::string m_expression
Keep the template for the input string passed to this->set(...) In the template CompositeFunction pre...
std::unique_ptr< mu::Parser > m_parser
math parser
bool isConstant() const
Check if the tie is a constant.
bool findParametersOf(const IFunction *fun) const
Check if the tie has any references to certain parameters.
~ParameterTie() override
Destructor.
virtual double eval(bool setParameterValue=true)
Evaluate the expression.
ParameterTie(IFunction *funct, const std::string &parName, const std::string &expr="", bool isDefault=false)
Constructor.
virtual std::string asString(const IFunction *fun=nullptr) const
Return the string that can be used to recreate this tie.
static double * AddVariable(const char *varName, void *palg)
MuParser callback function.
std::vector< ParameterReference > getRHSParameters() const
Get a list of parameters on the right-hand side of the equation.
IFunction * m_function1
Keep the function that was passed to the constructor.
Marks code as not implemented yet.
std::string to_string(const wide_integer< Bits, Signed > &n)