bpp-core3  3.0.0
DirectionFunction.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_DIRECTIONFUNCTION_H
6 #define BPP_NUMERIC_FUNCTION_DIRECTIONFUNCTION_H
7 
8 
9 #include "../../App/ApplicationTools.h"
10 #include "../../Io/OutputStream.h"
11 #include "../AutoParameter.h"
12 #include "../Parametrizable.h"
13 #include "Functions.h"
14 
15 namespace bpp
16 {
18  public virtual FunctionInterface,
20 {
21 private:
23  std::vector<double> xi_;
24  std::shared_ptr<FunctionInterface> function_;
25  std::string constraintPolicy_;
26  std::shared_ptr<OutputStream> messenger_;
27 
28 public:
29  DirectionFunction(std::shared_ptr<FunctionInterface> function = nullptr) :
30  params_(), p_(), xt_(), xi_(),
31  function_(function), constraintPolicy_(AutoParameter::CONSTRAINTS_KEEP),
32  messenger_(ApplicationTools::message) {}
33 
35  ParametrizableAdapter(df), params_(df.params_), p_(df.p_), xt_(df.p_), xi_(df.xi_),
36  function_(df.function_), constraintPolicy_(df.constraintPolicy_), messenger_(df.messenger_) {}
37 
39  {
40  ParametrizableAdapter::operator=(df);
41  params_ = df.params_;
42  p_ = df.p_;
43  xt_ = df.p_;
44  xi_ = df.xi_;
45  function_ = df.function_;
46  constraintPolicy_ = df.constraintPolicy_;
47  messenger_ = df.messenger_;
48  return *this;
49  }
50 
51  virtual ~DirectionFunction() {}
52 
53  DirectionFunction* clone() const override { return new DirectionFunction(*this); }
54 
55 public:
56  // Function interface implementation:
57  void setParameters(const ParameterList& parameters) override;
58  double getValue() const override;
59  const ParameterList& getParameters() const override;
60 
61 public:
62  // Specific methods:
63  void init(const ParameterList& p, const std::vector<double>& xi);
64  void autoParameter();
65  void ignoreConstraints();
66  void setConstraintPolicy(const std::string& constraintPolicy) { constraintPolicy_ = constraintPolicy; }
67 
68  std::string getConstraintPolicy() const { return constraintPolicy_; }
69 
70  void setMessageHandler(std::shared_ptr<OutputStream> messenger) { messenger_ = messenger; }
71  std::shared_ptr<FunctionInterface> getFunction() const { return function_; }
76 
77  size_t getNumberOfParameters() const override { return p_.size(); }
78 
79 protected:
80  ParameterList& getParameters_() override;
81 };
82 } // end of namespace bpp.
83 #endif // BPP_NUMERIC_FUNCTION_DIRECTIONFUNCTION_H
void setConstraintPolicy(const std::string &constraintPolicy)
void init(const ParameterList &p, const std::vector< double > &xi)
void setParameters(const ParameterList &parameters) override
Set the point where the function must be computed.
DirectionFunction(const DirectionFunction &df)
const ParameterList & getParameters() const override
Get all parameters available.
size_t size() const
Definition: ParameterList.h:56
DirectionFunction & operator=(const DirectionFunction &df)
This is the function abstract class.
Definition: Functions.h:52
ParameterList getFunctionParameters() const
A low-level implementation of the Parametrizable interface with void functions.
DirectionFunction(std::shared_ptr< FunctionInterface > function=nullptr)
The parameter list object.
Definition: ParameterList.h:27
std::string getConstraintPolicy() const
This class provides some common tools for developping applications.
std::shared_ptr< FunctionInterface > function_
ParameterList & getParameters_() override
Get all parameters available.
std::vector< double > xi_
The AutoParameter class.
Definition: AutoParameter.h:23
void setMessageHandler(std::shared_ptr< OutputStream > messenger)
size_t getNumberOfParameters() const override
Get the number of parameters.
double getValue() const override
Get the value of the function at the current point.
std::shared_ptr< FunctionInterface > getFunction() const
std::shared_ptr< OutputStream > messenger_
DirectionFunction * clone() const override
Create a copy of this object and send a pointer to it.