bpp-phyl3  3.0.0
DRTreeParsimonyScore.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_PARSIMONY_DRTREEPARSIMONYSCORE_H
6 #define BPP_PHYL_PARSIMONY_DRTREEPARSIMONYSCORE_H
7 
8 
9 #include "../Tree/NNISearchable.h"
10 #include "../Tree/TreeTools.h"
12 #include "DRTreeParsimonyData.h"
13 
14 namespace bpp
15 {
23  public virtual NNISearchable
24 {
25 private:
26  std::unique_ptr<DRTreeParsimonyData> parsimonyData_;
28 
29 public:
31  std::shared_ptr<TreeTemplate<Node>> tree,
32  std::shared_ptr<const SiteContainerInterface> data,
33  bool verbose = true,
34  bool includeGaps = false);
35 
37  std::shared_ptr<TreeTemplate<Node>> tree,
38  std::shared_ptr<const SiteContainerInterface> data,
39  std::shared_ptr<const StateMapInterface> statesMap,
40  bool verbose = true);
41 
43 
45 
46  virtual ~DRTreeParsimonyScore();
47 
48  DRTreeParsimonyScore* clone() const override { return new DRTreeParsimonyScore(*this); }
49 
50 private:
51  void init_(std::shared_ptr<const SiteContainerInterface> data, bool verbose);
52 
53 protected:
59  virtual void computeScores();
63  virtual void computeScoresPreorder(const Node*);
67  virtual void computeScoresPostorder(const Node*);
68 
69 public:
70  unsigned int getScore() const override;
71  unsigned int getScoreForSite(size_t site) const override;
72 
81  const DRTreeParsimonyNodeData& pData,
82  std::vector<Bitset>& rBitsets,
83  std::vector<unsigned int>& rScores);
84 
93  static void computeScoresPreorderForNode(
94  const DRTreeParsimonyNodeData& pData,
95  const Node* source,
96  std::vector<Bitset>& rBitsets,
97  std::vector<unsigned int>& rScores);
98 
106  static void computeScoresForNode(
107  const DRTreeParsimonyNodeData& pData, std::vector<Bitset>& rBitsets,
108  std::vector<unsigned int>& rScores);
109 
122  static void computeScoresFromArrays(
123  const std::vector<const std::vector<Bitset>*>& iBitsets,
124  const std::vector<const std::vector<unsigned int>*>& iScores,
125  std::vector<Bitset>& oBitsets,
126  std::vector<unsigned int>& oScores);
127 
133  double getTopologyValue() const override { return getScore(); }
134 
135  double testNNI(int nodeId) const override;
136 
137  void doNNI(int nodeId) override;
138 
139  const Tree& topology() const override { return tree(); }
140 
141  void topologyChangeTested(const TopologyChangeEvent& event) override
142  {
143  parsimonyData_->reInit();
144  computeScores();
145  }
146 
147  void topologyChangeSuccessful(const TopologyChangeEvent& event) override {}
149 };
150 } // end of namespace bpp.
151 #endif // BPP_PHYL_PARSIMONY_DRTREEPARSIMONYSCORE_H
Partial implementation of the TreeParsimonyScore interface.
const Tree & tree() const override
Get the tree for which scores are computed.
Parsimony data structure for a node.
Double recursive implementation of interface TreeParsimonyScore.
static void computeScoresPostorderForNode(const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in postorder.
void init_(std::shared_ptr< const SiteContainerInterface > data, bool verbose)
static void computeScoresFromArrays(const std::vector< const std::vector< Bitset > * > &iBitsets, const std::vector< const std::vector< unsigned int > * > &iScores, std::vector< Bitset > &oBitsets, std::vector< unsigned int > &oScores)
Compute bitsets and scores from an array of arrays.
unsigned int getScoreForSite(size_t site) const override
Get the score for a given site for the current tree, i.e. the total minimum number of changes in the ...
void topologyChangeSuccessful(const TopologyChangeEvent &event) override
Tell that a topology change is definitive.
void topologyChangeTested(const TopologyChangeEvent &event) override
Notify a topology change event.
virtual void computeScoresPreorder(const Node *)
Compute scores (preorder algorithm).
DRTreeParsimonyScore(std::shared_ptr< TreeTemplate< Node >> tree, std::shared_ptr< const SiteContainerInterface > data, bool verbose=true, bool includeGaps=false)
std::unique_ptr< DRTreeParsimonyData > parsimonyData_
DRTreeParsimonyScore & operator=(const DRTreeParsimonyScore &tp)
unsigned int getScore() const override
Get the score for the current tree, i.e. the total minimum number of changes in the tree.
const Tree & topology() const override
Get the tree associated to this NNISearchable object.
DRTreeParsimonyScore * clone() const override
virtual void computeScores()
Compute all scores.
double getTopologyValue() const override
Get the current score of this NNISearchable object.
double testNNI(int nodeId) const override
Send the score of a NNI movement, without performing it.
static void computeScoresForNode(const DRTreeParsimonyNodeData &pData, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in all directions.
virtual void computeScoresPostorder(const Node *)
Compute scores (postorder algorithm).
void doNNI(int nodeId) override
Perform a NNI movement.
static void computeScoresPreorderForNode(const DRTreeParsimonyNodeData &pData, const Node *source, std::vector< Bitset > &rBitsets, std::vector< unsigned int > &rScores)
Compute bitsets and scores for each site for a node, in preorder.
Interface for Nearest Neighbor Interchanges algorithms.
Definition: NNISearchable.h:63
The phylogenetic node class.
Definition: Node.h:59
Class for notifying new toplogy change events.
The phylogenetic tree class.
Definition: TreeTemplate.h:59
Interface for phylogenetic tree objects.
Definition: Tree.h:115
Defines the basic types of data flow nodes.