bpp-phyl3  3.0.0
Reward.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_PHYL_MAPPING_REWARD_H
6 #define BPP_PHYL_MAPPING_REWARD_H
7 
10 
11 #include "../Model/SubstitutionModel.h"
12 
13 // From the STL:
14 #include <vector>
15 
16 namespace bpp
17 {
34 class Reward :
35  public virtual Clonable
36 {
37 public:
38  Reward() {}
39  virtual ~Reward() {}
40  virtual Reward* clone() const = 0;
41 
42 public:
46  virtual bool hasAlphabetIndex() const = 0;
47 
52  virtual std::shared_ptr<const AlphabetIndex1> getAlphabetIndex() const = 0;
53 
58  virtual void setAlphabetIndex(std::shared_ptr<const AlphabetIndex1> alphind) = 0;
59 
65  virtual std::shared_ptr<const Alphabet> getAlphabet() const
66  {
67  return getAlphabetIndex()->getAlphabet();
68  }
69 
75  virtual size_t getNumberOfStates() const { return getAlphabet()->getSize(); }
76 
77 
87  virtual double getReward(size_t initialState, size_t finalState, double length) const = 0;
88 
96  virtual Matrix<double>* getAllRewards(double length) const = 0;
97 
105  virtual void storeAllRewards(double length, Eigen::MatrixXd& mat) const = 0;
106 
112  virtual void setSubstitutionModel(std::shared_ptr<const SubstitutionModelInterface> model) = 0;
113 };
114 
115 
123  public virtual Reward
124 {
125 protected:
126  std::shared_ptr<const AlphabetIndex1> alphIndex_;
127 
128 public:
129  AbstractReward(std::shared_ptr<const AlphabetIndex1> alphIndex) :
130  alphIndex_(alphIndex)
131  {}
132 
135  {}
136 
138  {
139  alphIndex_ = ar.alphIndex_;
140  return *this;
141  }
142 
143  virtual ~AbstractReward() {}
144 
145 public:
146  bool hasAlphabetIndex() const { return alphIndex_ != 0; }
147 
153  void setAlphabetIndex(std::shared_ptr<const AlphabetIndex1> alphIndex)
154  {
155  alphIndex_ = alphIndex;
157  }
158 
159  std::shared_ptr<const AlphabetIndex1> getAlphabetIndex() const { return alphIndex_; }
160 
161  const AlphabetIndex1& alphabetIndex() const { return *alphIndex_; }
162 
163 protected:
164  virtual void alphabetIndexHasChanged() = 0;
165 };
166 } // end of namespace bpp.
167 #endif // BPP_PHYL_MAPPING_REWARD_H
Basic implementation of the the Reward interface.
Definition: Reward.h:124
std::shared_ptr< const AlphabetIndex1 > alphIndex_
Definition: Reward.h:126
AbstractReward(const AbstractReward &ar)
Definition: Reward.h:133
const AlphabetIndex1 & alphabetIndex() const
Definition: Reward.h:161
bool hasAlphabetIndex() const
Definition: Reward.h:146
AbstractReward(std::shared_ptr< const AlphabetIndex1 > alphIndex)
Definition: Reward.h:129
std::shared_ptr< const AlphabetIndex1 > getAlphabetIndex() const
Definition: Reward.h:159
void setAlphabetIndex(std::shared_ptr< const AlphabetIndex1 > alphIndex)
attribution of an AlphabetIndex1
Definition: Reward.h:153
virtual ~AbstractReward()
Definition: Reward.h:143
virtual void alphabetIndexHasChanged()=0
AbstractReward & operator=(const AbstractReward &ar)
Definition: Reward.h:137
The Reward interface.
Definition: Reward.h:36
Reward()
Definition: Reward.h:38
virtual std::shared_ptr< const Alphabet > getAlphabet() const
Short cut function, equivalent to getSubstitutionRegister()->getAlphabet().
Definition: Reward.h:65
virtual size_t getNumberOfStates() const
Short cut function, equivalent to getSubstitutionRegister()->getAlphabet()->getSize().
Definition: Reward.h:75
virtual void setAlphabetIndex(std::shared_ptr< const AlphabetIndex1 > alphind)=0
virtual void storeAllRewards(double length, Eigen::MatrixXd &mat) const =0
Store the rewards on a branch, for each initial and final states, and given the branch length.
virtual bool hasAlphabetIndex() const =0
virtual void setSubstitutionModel(std::shared_ptr< const SubstitutionModelInterface > model)=0
Set the substitution model associated with this reward, if relevant.
virtual double getReward(size_t initialState, size_t finalState, double length) const =0
Get the reward of susbstitutions on a branch, given the initial and final states, and the branch leng...
virtual ~Reward()
Definition: Reward.h:39
virtual Reward * clone() const =0
virtual std::shared_ptr< const AlphabetIndex1 > getAlphabetIndex() const =0
virtual Matrix< double > * getAllRewards(double length) const =0
Get the rewards on a branch, for each initial and final states, and given the branch length.
Defines the basic types of data flow nodes.