bpp-phyl  2.2.0
Reward.h
Go to the documentation of this file.
1 //
2 // File: Reward.h
3 // Created by: Laurent Guéguen
4 // Created on: mercredi 27 mars 2013, à 09h 58
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004, 2005, 2006)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _REWARD_H_
41 #define _REWARD_H_
42 
43 #include "../Model/SubstitutionModel.h"
44 
45 #include <Bpp/Numeric/Matrix/Matrix.h>
46 #include <Bpp/Seq/AlphabetIndex/AlphabetIndex1.h>
47 
48 //From the STL:
49 #include <vector>
50 
51 namespace bpp
52 {
53 
70  class Reward:
71  public virtual Clonable
72  {
73  public:
74  Reward() {}
75  virtual ~Reward() {}
76  virtual Reward* clone() const = 0;
77 
78  public:
82  virtual bool hasAlphabetIndex() const = 0;
83 
88  virtual const AlphabetIndex1* getAlphabetIndex() const = 0;
89 
95  virtual AlphabetIndex1* getAlphabetIndex() = 0;
96 
101  virtual void setAlphabetIndex(AlphabetIndex1* alphind) = 0;
102 
108  virtual const Alphabet* getAlphabet() const { return getAlphabetIndex()->getAlphabet(); }
109 
115  virtual size_t getNumberOfStates() const { return getAlphabet()->getSize(); }
116 
117 
127  virtual double getReward(size_t initialState, size_t finalState, double length) const = 0;
128 
136  virtual Matrix<double>* getAllRewards(double length) const = 0;
137 
143  virtual void setSubstitutionModel(const SubstitutionModel* model) = 0;
144  };
145 
152  public virtual Reward
153  {
154  protected:
155  AlphabetIndex1* alphIndex_;
156 
157  public:
158  AbstractReward(AlphabetIndex1* alphIndex):
159  alphIndex_(alphIndex)
160  {}
161 
163  alphIndex_(ar.alphIndex_)//dynamic_cast<AlphabetIndex1*>(ar.alphIndex_->clone()))
164  {}
165 
167  // if (alphIndex_)
168  // delete alphIndex_;
169  alphIndex_ = ar.alphIndex_; //dynamic_cast<AlphabetIndex1*>(ar.alphIndex_->clone());
170  return *this;
171  }
172 
174  // if (alphIndex_)
175  // delete alphIndex_;
176  }
177 
178  public:
179  bool hasAlphabetIndex() const { return (alphIndex_ != 0); }
180 
181  /*
182  *@brief attribution of an AlphabetIndex1
183  *
184  *@param alphIndex pointer to a AlphabetIndex1
185  *
186  */
187 
188  void setAlphabetIndex(AlphabetIndex1* alphIndex) {
189 // if (alphIndex_) delete alphIndex_;
190  alphIndex_ = alphIndex;
192  }
193 
194  const AlphabetIndex1* getAlphabetIndex() const { return alphIndex_; }
195 
196  AlphabetIndex1* getAlphabetIndex() { return alphIndex_; }
197 
198  protected:
199  virtual void alphabetIndexHasChanged() = 0;
200  };
201 
202 } //end of namespace bpp.
203 
204 #endif //_REWARD_H_
205 
Reward()
Definition: Reward.h:74
virtual size_t getNumberOfStates() const
Short cut function, equivalent to getSubstitutionRegister()->getAlphabet()->getSize().
Definition: Reward.h:115
Interface for all substitution models.
AlphabetIndex1 * alphIndex_
Definition: Reward.h:155
bool hasAlphabetIndex() const
Definition: Reward.h:179
virtual void setAlphabetIndex(AlphabetIndex1 *alphind)=0
AbstractReward & operator=(const AbstractReward &ar)
Definition: Reward.h:166
virtual void setSubstitutionModel(const SubstitutionModel *model)=0
Set the substitution model associated with this reward, if relevant.
AbstractReward(const AbstractReward &ar)
Definition: Reward.h:162
virtual const Alphabet * getAlphabet() const
Short cut function, equivalent to getSubstitutionRegister()->getAlphabet().
Definition: Reward.h:108
Basic implementation of the the Reward interface.
Definition: Reward.h:151
virtual const AlphabetIndex1 * getAlphabetIndex() const =0
The Reward interface.
Definition: Reward.h:70
const AlphabetIndex1 * getAlphabetIndex() const
Definition: Reward.h:194
virtual Reward * clone() const =0
virtual bool hasAlphabetIndex() 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...
AlphabetIndex1 * getAlphabetIndex()
Definition: Reward.h:196
AbstractReward(AlphabetIndex1 *alphIndex)
Definition: Reward.h:158
void setAlphabetIndex(AlphabetIndex1 *alphIndex)
Definition: Reward.h:188
virtual ~Reward()
Definition: Reward.h:75
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 void alphabetIndexHasChanged()=0