bpp-phyl3  3.0.0
ParametrizablePhyloTree.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_LIKELIHOOD_PARAMETRIZABLEPHYLOTREE_H
6 #define BPP_PHYL_LIKELIHOOD_PARAMETRIZABLEPHYLOTREE_H
7 
10 
11 #include "../Tree/PhyloBranchParam.h"
12 #include "../Tree/PhyloNode.h"
13 #include "../Tree/PhyloTree.h"
14 
15 // From the stl:
16 #include <string>
17 
18 namespace bpp
19 {
25  public AssociationTreeGlobalGraphObserver<PhyloNode, PhyloBranchParam>,
27 {
28 private:
29  double minimumBrLen_;
30  double maximumBrLen_;
31  std::shared_ptr<ConstraintInterface> brLenConstraint_;
32 
33 public:
34  ParametrizablePhyloTree(const PhyloTree& tree, const std::string& prefix = "");
35 
37 
39 
40  ParametrizablePhyloTree* clone() const { return new ParametrizablePhyloTree(*this); }
41 
42 public:
43  std::vector<std::string> getAllLeavesNames() const;
44 
45  Vdouble getBranchLengths() const;
46 
47  virtual void setMinimumBranchLength(double minimum)
48  {
49  if (minimum > maximumBrLen_)
50  throw Exception("ParametrizablePhyloTree::setMinimumBranchLength. Minimum branch length should be lower than the maximum one: " + TextTools::toString(maximumBrLen_));
51  minimumBrLen_ = minimum;
52  if (!brLenConstraint_)
53  {
54  brLenConstraint_ = std::make_shared<IntervalConstraint>(minimumBrLen_, maximumBrLen_, true, true);
56  }
57  else
58  dynamic_cast<IntervalConstraint&>(*brLenConstraint_).setLowerBound(minimumBrLen_, false);
59  }
60 
61  virtual void setMaximumBranchLength(double maximum)
62  {
63  if (maximum < minimumBrLen_)
64  throw Exception("ParametrizablePhyloTree::setMaximumBranchLength. Maximum branch length should be higher than the minimum one: " + TextTools::toString(minimumBrLen_));
65  maximumBrLen_ = maximum;
66  if (!brLenConstraint_)
67  {
68  brLenConstraint_ = std::make_shared<IntervalConstraint>(minimumBrLen_, maximumBrLen_, true, true);
70  }
71  else
72  dynamic_cast<IntervalConstraint&>(*brLenConstraint_).setUpperBound(minimumBrLen_, false);
73  }
74 
75  virtual double getMinimumBranchLength() const { return minimumBrLen_; }
76  virtual double getMaximumBranchLength() const { return maximumBrLen_; }
77 
78 private:
79  void fireParameterChanged (const ParameterList& parameters);
80 };
81 } // end of namespace bpp
82 #endif // BPP_PHYL_LIKELIHOOD_PARAMETRIZABLEPHYLOTREE_H
void setLowerBound(double lowerBound, bool strict)
void setUpperBound(double upperBound, bool strict)
PhyloTree with Parametrizable Phylo Branches. They SHARE their branch length parameters.
ParametrizablePhyloTree(const PhyloTree &tree, const std::string &prefix="")
void fireParameterChanged(const ParameterList &parameters)
virtual double getMinimumBranchLength() const
virtual double getMaximumBranchLength() const
std::vector< std::string > getAllLeavesNames() const
ParametrizablePhyloTree * clone() const
ParametrizablePhyloTree & operator=(const ParametrizablePhyloTree &pTree)
virtual void setMaximumBranchLength(double maximum)
std::shared_ptr< ConstraintInterface > brLenConstraint_
virtual void setMinimumBranchLength(double minimum)
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble