7 #ifndef IMPMULTIFIT_MERGE_TREE_UTILS_H
8 #define IMPMULTIFIT_MERGE_TREE_UTILS_H
10 #include <boost/graph/adjacency_matrix.hpp>
11 #include <boost/graph/adjacency_list.hpp>
12 #include <boost/pending/disjoint_sets.hpp>
13 #include <boost/graph/graph_utility.hpp>
14 #include <IMP/multifit/multifit_config.h>
17 #include <boost/graph/kruskal_min_spanning_tree.hpp>
18 #include <boost/graph/prim_minimum_spanning_tree.hpp>
20 IMPMULTIFIT_BEGIN_NAMESPACE
23 typedef boost::adjacency_matrix<boost::undirectedS, boost::no_property,
24 boost::property<boost::edge_weight_t, double>
26 typedef boost::graph_traits<DependencyGraph>::edge_descriptor DGEdge;
27 typedef DependencyGraph::edge_property_type DGWeight;
28 typedef boost::graph_traits<DependencyGraph>::vertex_descriptor DGVertex;
29 typedef base::map<Particle *, DGVertex> PVMAP;
30 typedef base::map<DGVertex,Particle *> VPMAP;
33 class IMPMULTIFITEXPORT DummyRestraint :
public Restraint {
41 class IMPMULTIFITEXPORT MergeTreeBuilder {
43 MergeTreeBuilder(
const atom::Hierarchies &mhs) : g_(mhs.size()),
47 typedef boost::graph_traits<MTU::DependencyGraph>::vertex_iterator
49 VertexIterator v_it, v_it_end;
50 boost::tie(v_it, v_it_end) = boost::vertices(g_);
52 for (; v_it != v_it_end; ++v_it) {
53 mol2node_[mhs_[ind]]=*v_it;
54 node2mol_[*v_it]=mhs_[ind];
60 void increase_edge(atom::Hierarchy mh1,atom::Hierarchy mh2) {
62 if (mh1.get_particle()==mh2.get_particle())
66 u=mol2node_[mh1.get_particle()];
67 v=mol2node_[mh2.get_particle()];
68 if (!boost::edge(u,v,g_).second) {
69 boost::add_edge(u,v,MTU::DGWeight(0.),g_);
73 e=boost::edge(u,v,g_).first;
74 boost::put(boost::edge_weight_t(),g_,e,
75 boost::get(boost::edge_weight_t(),g_,e)-1);
77 void show(std::ostream& out=std::cout)
const {
79 typedef boost::graph_traits<MTU::DependencyGraph>::vertex_iterator
81 std::pair<vertex_iter, vertex_iter> vp;
82 for (vp = vertices(g_); vp.first != vp.second; ++vp.first) {
83 out << node2mol_.find(*vp.first)->second->get_name() <<
" ";
87 boost::graph_traits<MTU::DependencyGraph>::edge_iterator ei, ei_end;
88 for (boost::tie(ei, ei_end) = edges(g_); ei != ei_end; ++ei)
89 out <<
"(" << node2mol_.find(source(*ei, g_))->second->get_name()
90 <<
"," << node2mol_.find(target(*ei, g_))->second->get_name()
91 <<
","<<boost::get(boost::edge_weight_t(),g_,*ei)<<
")"<<std::endl;
95 std::vector<MTU::DGEdge> mst;
96 boost::kruskal_minimum_spanning_tree(g_, std::back_inserter(mst));
99 for(
int i=0;i<(int)mst.size();i++) {
101 pp[0]=node2mol_.find(boost::source(mst[i],g_))->second;
102 pp[1]=node2mol_.find(boost::target(mst[i],g_))->second;
110 atom::Hierarchies mhs_;
111 MTU::PVMAP mol2node_;
112 MTU::VPMAP node2mol_;
115 IMPMULTIFIT_END_NAMESPACE