// graph-tool -- a general graph modification and manipulation thingy // // Copyright (C) 2007-2012 Tiago de Paula Peixoto // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 3 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // based on code written by Alexandre Hannud Abdo #include "graph_filtering.hh" #include "graph_selectors.hh" #include "graph_properties.hh" #include "graph_extended_clustering.hh" #include using namespace std; using namespace boost; using namespace graph_tool; template struct prop_vector { boost::any operator()(const vector& props, size_t size) const { boost::any prop_vec; mpl::for_each (bind(get_prop_vector(), _1, ref(props), ref(prop_vec), size)); return prop_vec; } struct get_prop_vector { template void operator()(Property, const vector& props, boost::any& prop_vec, size_t size) const { if (typeid(Property) == props[0].type()) { try { vector vec; vec.resize(props.size()); for (size_t i = 0; i < props.size(); ++i) vec[i] = any_cast(props[i]).get_unchecked(size); prop_vec = vec; } catch (bad_any_cast){} } } }; }; struct get_property_vector_type { template struct apply { typedef vector type; }; }; void extended_clustering(GraphInterface& g, python::list props) { vector cmaps(python::len(props)); for (size_t i = 0; i < cmaps.size(); ++i) cmaps[i] = python::extract(props[i])(); boost::any vprop = prop_vector() (cmaps, num_vertices(g.GetGraph())); if (vprop.empty()) throw ValueException("all vertex properties must be of the same" " floating point type"); typedef mpl::transform::type properties_vector; run_action<>() (g, bind(get_extended_clustering(), _1, any_cast (g.GetVertexIndex()), _2), properties_vector()) (vprop); }