bpp-core3  3.0.0
ComputationTree.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_NUMERIC_FUNCTION_OPERATORS_COMPUTATIONTREE_H
6 #define BPP_NUMERIC_FUNCTION_OPERATORS_COMPUTATIONTREE_H
7 
8 #include <memory>
9 
10 #include "../../../Graph/AssociationTreeGraphImplObserver.h"
11 #include "../Functions.h"
12 #include "Operator.h"
13 
14 namespace bpp
15 {
22  public AssociationTreeGlobalGraphObserver<Operator, short>
23 {
24 private:
25  std::shared_ptr<Operator> readFormula_(const std::string& formula, const std::map<std::string, std::shared_ptr<FunctionInterface>>& functionNames);
26 
27 public:
28  /*
29  * @brief Tree for numerical computation given a formula (such as
30  * 2*f+g), and given a map from function name (f) to real
31  * function.
32  *
33  */
34 
35  ComputationTree(const std::string& formula, const std::map<std::string, std::shared_ptr<FunctionInterface>>& functionNames);
36 
38  {
39  return new ComputationTree(*this);
40  }
41 
42  double getValue() const
43  {
44  return getRoot()->getValue();
45  }
46 
47  double getFirstOrderDerivative(const std::string& variable) const
48  {
49  return getRoot()->getFirstOrderDerivative(variable);
50  }
51 
52  double getSecondOrderDerivative(const std::string& variable) const
53  {
54  return getRoot()->getSecondOrderDerivative(variable);
55  }
56 
57  void readFormula(const std::string& formula, const std::map<std::string, std::shared_ptr<FunctionInterface>>& functionNames)
58  {
59  readFormula_(formula, functionNames);
60  }
61 
62  std::string output() const;
63 
64  /*
65  * Return true if all binary operators are '+' or '-'
66  *
67  */
68 
69  bool isAllSum();
70 };
71 }
72 #endif // BPP_NUMERIC_FUNCTION_OPERATORS_COMPUTATIONTREE_H
double getValue() const
double getSecondOrderDerivative(const std::string &variable) const
ComputationTree(const std::string &formula, const std::map< std::string, std::shared_ptr< FunctionInterface >> &functionNames)
std::string output() const
double getFirstOrderDerivative(const std::string &variable) const
ComputationTree * clone() const
Defines a Computation Tree based on Operators.
std::shared_ptr< Operator > readFormula_(const std::string &formula, const std::map< std::string, std::shared_ptr< FunctionInterface >> &functionNames)
void readFormula(const std::string &formula, const std::map< std::string, std::shared_ptr< FunctionInterface >> &functionNames)