/** * \file KMRectangle.cpp \brief Orthogonal (axis aligned) rectangle * * Copyright 2007-2013 IMP Inventors. All rights reserved. * */ #include #include #include #include #include #include #include #include #include #if BOOST_VERSION > 103900 namespace boost { // work around bug in bc_clustering using graph::has_no_edges; } #endif #include IMPSTATISTICS_BEGIN_INTERNAL_NAMESPACE namespace { /*struct centrality_t { typedef boost::edge_property_tag kind; } centrality;*/ typedef boost::adjacency_matrix > > Graph; /*typedef boost::adjacency_list > Graph;*/ typedef boost::graph_traits Traits; typedef boost::disjoint_sets DS; struct Done { typedef double centrality_type; int k_; Ints rank_, parent_; Done(int k, int n): k_(k), rank_(n), parent_(n){} template bool operator()(centrality_type c, const B & e, const Graph &g) { /* std::cout << "Done called on " << boost::source(e, g) << "--" << boost::target(e, g) << ": " << c << std::endl; */ IMP_UNUSED(c); IMP_UNUSED(e); DS ds(&rank_[0], &parent_[0]); boost::initialize_incremental_components(g, ds); boost::incremental_components(g, ds); unsigned int s= ds.count_sets(boost::vertices(g).first, boost::vertices(g).second); return s >= static_cast(k_); } }; } PartitionalClustering *get_centrality_clustering(CentralityGraph &g, unsigned int k) { boost::property_map::type m = boost::get(boost::edge_centrality, g); unsigned int n=boost::num_vertices(g); boost::betweenness_centrality_clustering(g, Done(k, n), m); Ints rank(n), parent(n); DS ds(&rank[0], &parent[0]); boost::initialize_incremental_components(g, ds); boost::incremental_components(g, ds); IMP::base::map sets; for (unsigned int i=0; i< boost::num_vertices(g); ++i) { int s= ds.find_set(i); sets[s].push_back(i); } IMP::base::Vector clusters; for (IMP::base::map::const_iterator it = sets.begin(); it != sets.end(); ++it) { clusters.push_back(it->second); } IMP_NEW(internal::TrivialPartitionalClustering, ret, (clusters)); return ret.release(); } IMPSTATISTICS_END_INTERNAL_NAMESPACE