bpp-phyl  2.2.0
NNITopologySearch.h
Go to the documentation of this file.
1 //
2 // File: NNITopologySearch.h
3 // Created by: Julien Dutheil
4 // Created on: Wed Oct 12 10:52 2005
5 //
6 
7 /*
8 Copyright or © or Copr. CNRS, (November 16, 2004)
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 _NNITOPOLOGYSEARCH_H_
41 #define _NNITOPOLOGYSEARCH_H_
42 
43 #include "TopologySearch.h"
44 #include "NNISearchable.h"
45 
46 namespace bpp
47 {
48 
62  public virtual TopologySearch
63 {
64  public:
65  const static std::string FAST;
66  const static std::string BETTER;
67  const static std::string PHYML;
68 
69  private:
71  std::string algorithm_;
72  unsigned int verbose_;
73  std::vector<TopologyListener*> topoListeners_;
74 
75  public:
77  NNISearchable& tree,
78  const std::string& algorithm = FAST,
79  unsigned int verbose = 2) :
80  searchableTree_(&tree), algorithm_(algorithm), verbose_(verbose), topoListeners_()
81  {}
82 
86  verbose_(ts.verbose_),
88  {
89  //Hard-copy all listeners:
90  for (unsigned int i = 0; i < topoListeners_.size(); i++)
91  topoListeners_[i] = dynamic_cast<TopologyListener*>(ts.topoListeners_[i]->clone());
92  }
93 
95  {
98  verbose_ = ts.verbose_;
100  //Hard-copy all listeners:
101  for (unsigned int i = 0; i < topoListeners_.size(); i++)
102  topoListeners_[i] = dynamic_cast<TopologyListener*>(ts.topoListeners_[i]->clone());
103  return *this;
104  }
105 
106 
108  {
109  for (std::vector <TopologyListener*>::iterator it = topoListeners_.begin();
110  it != topoListeners_.end();
111  it++)
112  delete *it;
113  }
114 
115  public:
116  void search() throw (Exception);
117 
127  {
128  if (listener)
129  topoListeners_.push_back(listener);
130  }
131 
132  public:
138  const Tree& getTopology() const { return searchableTree_->getTopology(); }
139 
148 
149  protected:
150  void searchFast() throw (Exception);
151  void searchBetter() throw (Exception);
152  void searchPhyML() throw (Exception);
153 
157  void notifyAllPerformed(const TopologyChangeEvent& event);
161  void notifyAllTested(const TopologyChangeEvent& event);
165  void notifyAllSuccessful(const TopologyChangeEvent& event);
166 
167 };
168 
169 } //end of namespace bpp.
170 
171 #endif //_NNITOPOLOGYSEARCH_H_
172 
void notifyAllTested(const TopologyChangeEvent &event)
Process a TopologyChangeEvent to all listeners.
NNISearchable * searchableTree_
static const std::string FAST
void search()
Performs the search.
void notifyAllPerformed(const TopologyChangeEvent &event)
Process a TopologyChangeEvent to all listeners.
NNITopologySearch(NNISearchable &tree, const std::string &algorithm=FAST, unsigned int verbose=2)
Interface for Nearest Neighbor Interchanges algorithms.
Definition: NNISearchable.h:96
std::vector< TopologyListener * > topoListeners_
Interface for phylogenetic tree objects.
Definition: Tree.h:148
Interface for topology search methods.
NNITopologySearch(const NNITopologySearch &ts)
const Tree & getTopology() const
Retrieve the tree.
const NNISearchable * getSearchableObject() const
void addTopologyListener(TopologyListener *listener)
Add a listener to the list.
NNITopologySearch & operator=(const NNITopologySearch &ts)
Class for notifying new toplogy change events.
NNISearchable * getSearchableObject()
static const std::string BETTER
static const std::string PHYML
Implement this interface to be notified when the topology of a tree has changed during topology searc...
void notifyAllSuccessful(const TopologyChangeEvent &event)
Process a TopologyChangeEvent to all listeners.
NNI topology search method.
virtual const Tree & getTopology() const =0
Get the tree associated to this NNISearchable object.