diff --git a/Makefile.am b/Makefile.am index d24ded0cfdfe62cfd50f4c1c9da08e344950dfed..8729cc4beaff5631eaefd03c05b319fb3a8db069 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,7 +12,7 @@ graphtooldoc_DATA = \ TODO -EXTRA_DIST = $(graphtooldoc_DATA) +EXTRA_DIST = $(graphtooldoc_DATA) # Copy all the spec files. Of cource, only one is actually used. dist-hook: diff --git a/configure.in b/configure.in index 7da17ade9cf4db1cb155809a728499a82e92d322..37c009eb8e3ca605fb7c9005f98e67adbcc2feb8 100644 --- a/configure.in +++ b/configure.in @@ -204,6 +204,7 @@ AC_OUTPUT([ Makefile src/Makefile src/graph/Makefile +src/graph/correlations/Makefile src/graph_tool/Makefile ]) diff --git a/src/boost-workaround/boost/graph/betweenness_centrality.hpp b/src/boost-workaround/boost/graph/betweenness_centrality.hpp index 74999249f8c294ebf4283353114e765734653b69..9bf6ad127b2b06c9edfbbc086fb3f96bc69b940d 100644 --- a/src/boost-workaround/boost/graph/betweenness_centrality.hpp +++ b/src/boost-workaround/boost/graph/betweenness_centrality.hpp @@ -49,7 +49,7 @@ namespace detail { namespace graph { IncomingMap incoming, DistanceMap distance, PathCountMap path_count) - : ordered_vertices(ordered_vertices), weight(weight), + : ordered_vertices(ordered_vertices), weight(weight), incoming(incoming), distance(distance), path_count(path_count) { } @@ -59,8 +59,8 @@ namespace detail { namespace graph { * for w is set to {(v, w)} and the shortest path count of w is set to * the number of paths that reach {v}. */ - void edge_relaxed(edge_descriptor e, const Graph& g) - { + void edge_relaxed(edge_descriptor e, const Graph& g) + { vertex_descriptor v = source(e, g), w = target(e, g); incoming[w].clear(); incoming[w].push_back(e); @@ -73,7 +73,7 @@ namespace detail { namespace graph { * incoming edges of w and add all of the shortest paths to v to the * shortest path count of w. */ - void edge_not_relaxed(edge_descriptor e, const Graph& g) + void edge_not_relaxed(edge_descriptor e, const Graph& g) { typedef typename property_traits::value_type weight_type; typedef typename property_traits::value_type distance_type; @@ -89,8 +89,8 @@ namespace detail { namespace graph { } /// Keep track of vertices as they are reached - void examine_vertex(vertex_descriptor w, const Graph&) - { + void examine_vertex(vertex_descriptor w, const Graph&) + { ordered_vertices.push(w); } @@ -110,13 +110,13 @@ namespace detail { namespace graph { template struct brandes_dijkstra_shortest_paths { - brandes_dijkstra_shortest_paths(WeightMap weight_map) + brandes_dijkstra_shortest_paths(WeightMap weight_map) : weight_map(weight_map) { } - template - void - operator()(Graph& g, + void + operator()(Graph& g, typename graph_traits::vertex_descriptor s, std::stack::vertex_descriptor>& ov, IncomingMap incoming, @@ -124,11 +124,11 @@ namespace detail { namespace graph { PathCountMap path_count, VertexIndexMap vertex_index) { - typedef brandes_dijkstra_visitor visitor_type; visitor_type visitor(ov, weight_map, incoming, distance, path_count); - dijkstra_shortest_paths(g, s, + dijkstra_shortest_paths(g, s, boost::weight_map(weight_map) .vertex_index_map(vertex_index) .distance_map(distance) @@ -150,18 +150,18 @@ namespace detail { namespace graph { * records predecessor and the number of shortest paths to each * vertex. */ - template struct visitor_type : public bfs_visitor<> { typedef typename graph_traits::edge_descriptor edge_descriptor; - typedef typename graph_traits::vertex_descriptor + typedef typename graph_traits::vertex_descriptor vertex_descriptor; - - visitor_type(IncomingMap incoming, DistanceMap distance, - PathCountMap path_count, + + visitor_type(IncomingMap incoming, DistanceMap distance, + PathCountMap path_count, std::stack& ordered_vertices) - : incoming(incoming), distance(distance), + : incoming(incoming), distance(distance), path_count(path_count), ordered_vertices(ordered_vertices) { } /// Keep track of vertices as they are reached @@ -180,7 +180,7 @@ namespace detail { namespace graph { vertex_descriptor v = source(e, g); vertex_descriptor w = target(e, g); put(distance, w, get(distance, v) + 1); - + put(path_count, w, get(path_count, v)); incoming[w].push_back(e); } @@ -208,10 +208,10 @@ namespace detail { namespace graph { std::stack& ordered_vertices; }; - template - void - operator()(Graph& g, + void + operator()(Graph& g, typename graph_traits::vertex_descriptor s, std::stack::vertex_descriptor>& ov, IncomingMap incoming, @@ -224,12 +224,12 @@ namespace detail { namespace graph { visitor_type visitor(incoming, distance, path_count, ov); - - std::vector + + std::vector colors(num_vertices(g), color_traits::white()); boost::queue Q; - breadth_first_visit(g, s, Q, visitor, - make_iterator_property_map(colors.begin(), + breadth_first_visit(g, s, Q, visitor, + make_iterator_property_map(colors.begin(), vertex_index)); } }; @@ -237,16 +237,16 @@ namespace detail { namespace graph { // When the edge centrality map is a dummy property map, no // initialization is needed. template - inline void + inline void init_centrality_map(std::pair, dummy_property_map) { } // When we have a real edge centrality map, initialize all of the // centralities to zero. template - void + void init_centrality_map(std::pair keys, Centrality centrality_map) { - typedef typename property_traits::value_type + typedef typename property_traits::value_type centrality_type; while (keys.first != keys.second) { put(centrality_map, *keys.first, centrality_type(0)); @@ -257,22 +257,22 @@ namespace detail { namespace graph { // When the edge centrality map is a dummy property map, no update // is performed. template - inline void + inline void update_centrality(dummy_property_map, const Key&, const T&) { } // When we have a real edge centrality map, add the value to the map template - inline void + inline void update_centrality(CentralityMap centrality_map, Key k, const T& x) { put(centrality_map, k, get(centrality_map, k) + x); } template - inline void + inline void divide_centrality_by_two(std::pair, dummy_property_map) {} template inline void - divide_centrality_by_two(std::pair keys, + divide_centrality_by_two(std::pair keys, CentralityMap centrality_map) { typename property_traits::value_type two(2); @@ -283,11 +283,11 @@ namespace detail { namespace graph { } template - void - brandes_betweenness_centrality_impl(const Graph& g, + void + brandes_betweenness_centrality_impl(const Graph& g, CentralityMap centrality, // C_B EdgeCentralityMap edge_centrality_map, IncomingMap, //incoming, // P @@ -306,7 +306,7 @@ namespace detail { namespace graph { init_centrality_map(edges(g), edge_centrality_map); int i, N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor s = vertex(i, g); @@ -328,24 +328,24 @@ namespace detail { namespace graph { put(dependency, *w, 0); } put(path_count, s, 1); - + // Execute the shortest paths algorithm. This will be either // Dijkstra's algorithm or a customized breadth-first search, // depending on whether the graph is weighted or unweighted. shortest_paths(g, s, ordered_vertices, incoming, distance, path_count, vertex_index); - - while (!ordered_vertices.empty()) + + while (!ordered_vertices.empty()) { vertex_descriptor w = ordered_vertices.top(); ordered_vertices.pop(); - + typedef typename property_traits::value_type incoming_type; typedef typename incoming_type::iterator incoming_iterator; - typedef typename property_traits::value_type + typedef typename property_traits::value_type dependency_type; - + for (incoming_iterator vw = incoming[w].begin(); vw != incoming[w].end(); ++vw) { vertex_descriptor v = source(*vw, g); @@ -355,17 +355,17 @@ namespace detail { namespace graph { put(dependency, v, get(dependency, v) + factor); update_centrality(edge_centrality_map, *vw, factor); } - + if (w != s) { update_centrality(centrality, w, get(dependency, w)); } - } + } } - + typedef typename graph_traits::directed_category directed_category; - const bool is_undirected = + const bool is_undirected = is_convertible::value; if (is_undirected) { divide_centrality_by_two(vertices(g), centrality); @@ -376,11 +376,11 @@ namespace detail { namespace graph { } } // end namespace detail::graph template -void -brandes_betweenness_centrality(const Graph& g, +void +brandes_betweenness_centrality(const Graph& g, CentralityMap centrality, // C_B EdgeCentralityMap edge_centrality_map, IncomingMap incoming, // P @@ -391,20 +391,20 @@ brandes_betweenness_centrality(const Graph& g, { detail::graph::brandes_unweighted_shortest_paths shortest_paths; - detail::graph::brandes_betweenness_centrality_impl(g, centrality, + detail::graph::brandes_betweenness_centrality_impl(g, centrality, edge_centrality_map, incoming, distance, dependency, path_count, - vertex_index, + vertex_index, shortest_paths); } -template -void -brandes_betweenness_centrality(const Graph& g, +template +void +brandes_betweenness_centrality(const Graph& g, CentralityMap centrality, // C_B EdgeCentralityMap edge_centrality_map, IncomingMap incoming, // P @@ -417,18 +417,18 @@ brandes_betweenness_centrality(const Graph& g, detail::graph::brandes_dijkstra_shortest_paths shortest_paths(weight_map); - detail::graph::brandes_betweenness_centrality_impl(g, centrality, + detail::graph::brandes_betweenness_centrality_impl(g, centrality, edge_centrality_map, incoming, distance, dependency, path_count, - vertex_index, + vertex_index, shortest_paths); } namespace detail { namespace graph { template - void + void brandes_betweenness_centrality_dispatch2(const Graph& g, CentralityMap centrality, EdgeCentralityMap edge_centrality_map, @@ -438,15 +438,15 @@ namespace detail { namespace graph { typedef typename graph_traits::degree_size_type degree_size_type; typedef typename graph_traits::vertex_descriptor vertex_descriptor; typedef typename graph_traits::edge_descriptor edge_descriptor; - typedef typename mpl::if_c<(is_same::value), - EdgeCentralityMap, + EdgeCentralityMap, CentralityMap>::type a_centrality_map; - typedef typename property_traits::value_type + typedef typename property_traits::value_type centrality_type; typename graph_traits::vertices_size_type V = num_vertices(g); - + std::vector > incoming(V); std::vector distance(V); std::vector dependency(V); @@ -461,11 +461,11 @@ namespace detail { namespace graph { vertex_index, weight_map); } - + template - void + void brandes_betweenness_centrality_dispatch2(const Graph& g, CentralityMap centrality, EdgeCentralityMap edge_centrality_map, @@ -474,15 +474,15 @@ namespace detail { namespace graph { typedef typename graph_traits::degree_size_type degree_size_type; typedef typename graph_traits::vertex_descriptor vertex_descriptor; typedef typename graph_traits::edge_descriptor edge_descriptor; - typedef typename mpl::if_c<(is_same::value), - EdgeCentralityMap, + EdgeCentralityMap, CentralityMap>::type a_centrality_map; - typedef typename property_traits::value_type + typedef typename property_traits::value_type centrality_type; typename graph_traits::vertices_size_type V = num_vertices(g); - + std::vector > incoming(V); std::vector distance(V); std::vector dependency(V); @@ -500,10 +500,10 @@ namespace detail { namespace graph { template struct brandes_betweenness_centrality_dispatch1 { - template - static void - run(const Graph& g, CentralityMap centrality, + static void + run(const Graph& g, CentralityMap centrality, EdgeCentralityMap edge_centrality_map, VertexIndexMap vertex_index, WeightMap weight_map) { @@ -515,10 +515,10 @@ namespace detail { namespace graph { template<> struct brandes_betweenness_centrality_dispatch1 { - template - static void - run(const Graph& g, CentralityMap centrality, + static void + run(const Graph& g, CentralityMap centrality, EdgeCentralityMap edge_centrality_map, VertexIndexMap vertex_index, error_property_not_found) { @@ -530,25 +530,25 @@ namespace detail { namespace graph { } } // end namespace detail::graph template -void -brandes_betweenness_centrality(const Graph& g, +void +brandes_betweenness_centrality(const Graph& g, const bgl_named_params& params) { typedef bgl_named_params named_params; typedef typename property_value::type ew; detail::graph::brandes_betweenness_centrality_dispatch1::run( - g, - choose_param(get_param(params, vertex_centrality), + g, + choose_param(get_param(params, vertex_centrality), dummy_property_map()), - choose_param(get_param(params, edge_centrality), + choose_param(get_param(params, edge_centrality), dummy_property_map()), choose_const_pmap(get_param(params, vertex_index), g, vertex_index), get_param(params, edge_weight)); } template -void +void brandes_betweenness_centrality(const Graph& g, CentralityMap centrality) { detail::graph::brandes_betweenness_centrality_dispatch2( @@ -556,7 +556,7 @@ brandes_betweenness_centrality(const Graph& g, CentralityMap centrality) } template -void +void brandes_betweenness_centrality(const Graph& g, CentralityMap centrality, EdgeCentralityMap edge_centrality_map) { @@ -571,7 +571,7 @@ brandes_betweenness_centrality(const Graph& g, CentralityMap centrality, * given centrality map. */ template -void +void relative_betweenness_centrality(const Graph& g, CentralityMap centrality) { typedef typename graph_traits::vertex_iterator vertex_iterator; diff --git a/src/boost-workaround/boost/graph/filtered_graph.hpp b/src/boost-workaround/boost/graph/filtered_graph.hpp index cb81d7ff5fd1ab6befd202bfe40be55db8555d7a..dba556d01e4091a7fd53865d9eac939ab38b3c04 100644 --- a/src/boost-workaround/boost/graph/filtered_graph.hpp +++ b/src/boost-workaround/boost/graph/filtered_graph.hpp @@ -60,13 +60,13 @@ namespace boost { } const Set* m_s; }; - + namespace detail { template struct out_edge_predicate { out_edge_predicate() { } - out_edge_predicate(EdgePredicate ep, VertexPredicate vp, + out_edge_predicate(EdgePredicate ep, VertexPredicate vp, const Graph& g) : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) { } @@ -82,7 +82,7 @@ namespace boost { template struct in_edge_predicate { in_edge_predicate() { } - in_edge_predicate(EdgePredicate ep, VertexPredicate vp, + in_edge_predicate(EdgePredicate ep, VertexPredicate vp, const Graph& g) : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) { } @@ -98,7 +98,7 @@ namespace boost { template struct edge_predicate { edge_predicate() { } - edge_predicate(EdgePredicate ep, VertexPredicate vp, + edge_predicate(EdgePredicate ep, VertexPredicate vp, const Graph& g) : m_edge_pred(ep), m_vertex_pred(vp), m_g(&g) { } @@ -134,7 +134,7 @@ namespace boost { const G& m_g; }; - template class filtered_graph : public filtered_graph_base { @@ -143,11 +143,11 @@ namespace boost { typedef filtered_graph self; public: typedef Graph graph_type; - typedef detail::out_edge_predicate OutEdgePred; - typedef detail::in_edge_predicate InEdgePred; - typedef detail::edge_predicate EdgePred; // Constructors @@ -168,7 +168,7 @@ namespace boost { typedef filter_iterator< OutEdgePred, typename Traits::out_edge_iterator > out_edge_iterator; - + typedef typename Traits::degree_size_type degree_size_type; // AdjacencyGraph requirements @@ -221,13 +221,13 @@ namespace boost { #ifndef BOOST_GRAPH_NO_BUNDLED_PROPERTIES template - struct vertex_bundle_type > + struct vertex_bundle_type > : vertex_bundle_type { }; template - struct edge_bundle_type > + struct edge_bundle_type > : edge_bundle_type { }; #endif // BOOST_GRAPH_NO_BUNDLED_PROPERTIES @@ -251,11 +251,11 @@ namespace boost { typename filtered_graph::vertex_iterator> vertices(const filtered_graph& g) { - typedef filtered_graph Graph; + typedef filtered_graph Graph; typename graph_traits::vertex_iterator f, l; tie(f, l) = vertices(g.m_g); typedef typename Graph::vertex_iterator iter; - return std::make_pair(iter(g.m_vertex_pred, f, l), + return std::make_pair(iter(g.m_vertex_pred, f, l), iter(g.m_vertex_pred, l, l)); } @@ -285,18 +285,18 @@ namespace boost { // tie(vi, viend) = vertices(g); // assert(std::distance(vi, viend) == num_vertices(g)); - template + template typename filtered_graph::vertices_size_type num_vertices(const filtered_graph& g) { return num_vertices(g.m_g); } - template + template typename filtered_graph::edges_size_type num_edges(const filtered_graph& g) { return num_edges(g.m_g); } - + template typename filtered_graph_base::vertex_descriptor source(typename filtered_graph_base::edge_descriptor e, @@ -352,7 +352,7 @@ namespace boost { return std::make_pair(adjacency_iterator(f, const_cast(&g)), adjacency_iterator(l, const_cast(&g))); } - + template std::pair::in_edge_iterator, typename filtered_graph::in_edge_iterator> @@ -426,14 +426,14 @@ namespace boost { typedef typename Map::type type; typedef typename Map::const_type const_type; }; - }; + }; } // namespace detail - template <> + template <> struct vertex_property_selector { typedef detail::filtered_graph_property_selector type; }; - template <> + template <> struct edge_property_selector { typedef detail::filtered_graph_property_selector type; }; @@ -460,7 +460,7 @@ namespace boost { return get(p, (const G&)g.m_g, k); } - template void put(Property p, const filtered_graph& g, const Key& k, diff --git a/src/boost-workaround/boost/graph/fruchterman_reingold.hpp b/src/boost-workaround/boost/graph/fruchterman_reingold.hpp index 85f3f40fd68dedd5f9cab869dae5db4895a0893f..69ef145c70eb46c5b9823db60720813d326174e5 100644 --- a/src/boost-workaround/boost/graph/fruchterman_reingold.hpp +++ b/src/boost-workaround/boost/graph/fruchterman_reingold.hpp @@ -74,7 +74,7 @@ struct all_force_pairs { typedef typename graph_traits::vertex_iterator vertex_iterator; int i, N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); @@ -119,7 +119,7 @@ struct grid_force_pairs buckets_t buckets(rows * columns); int i, N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); @@ -137,7 +137,7 @@ struct grid_force_pairs } N = rows * columns; - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { std::size_t row = i / rows; @@ -158,11 +158,11 @@ struct grid_force_pairs std::size_t adj_end_column = column == columns - 1? column : column + 1; for (std::size_t other_row = adj_start_row; other_row <= adj_end_row; ++other_row) - for (std::size_t other_column = adj_start_column; + for (std::size_t other_column = adj_start_column; other_column <= adj_end_column; ++other_column) if (other_row != row || other_column != column) { // Repulse vertices in this bucket - bucket_t& other_bucket + bucket_t& other_bucket = buckets[other_row * columns + other_column]; for (v = other_bucket.begin(); v != other_bucket.end(); ++v) apply_force(*u, *v); @@ -300,14 +300,14 @@ fruchterman_reingold_force_directed_layout std::vector edge_list; edge_list.reserve(num_edges(g)); edge_iterator e, e_end; - for (tie(e, e_end) = edges(g); e != e_end; ++e) + for (tie(e, e_end) = edges(g); e != e_end; ++e) edge_list.push_back(*e); Dim temp = cool(); if (temp) do { // Calculate repulsive forces int i, N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); @@ -320,7 +320,7 @@ fruchterman_reingold_force_directed_layout // Calculate attractive forces N = edge_list.size(); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { edge_descriptor e = edge_list[i]; @@ -339,7 +339,7 @@ fruchterman_reingold_force_directed_layout // Update positions N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); @@ -350,17 +350,17 @@ fruchterman_reingold_force_directed_layout BOOST_USING_STD_MAX(); Dim disp_size = sqrt(displacement[v].x * displacement[v].x + displacement[v].y * displacement[v].y); - position[v].x += displacement[v].x / disp_size + position[v].x += displacement[v].x / disp_size * min BOOST_PREVENT_MACRO_SUBSTITUTION (disp_size, temp); - position[v].y += displacement[v].y / disp_size + position[v].y += displacement[v].y / disp_size * min BOOST_PREVENT_MACRO_SUBSTITUTION (disp_size, temp); - position[v].x = min BOOST_PREVENT_MACRO_SUBSTITUTION - (width / 2, - max BOOST_PREVENT_MACRO_SUBSTITUTION(-width / 2, + position[v].x = min BOOST_PREVENT_MACRO_SUBSTITUTION + (width / 2, + max BOOST_PREVENT_MACRO_SUBSTITUTION(-width / 2, position[v].x)); position[v].y = min BOOST_PREVENT_MACRO_SUBSTITUTION - (height / 2, - max BOOST_PREVENT_MACRO_SUBSTITUTION(-height / 2, + (height / 2, + max BOOST_PREVENT_MACRO_SUBSTITUTION(-height / 2, position[v].y)); } } while ( (temp = cool()) ); diff --git a/src/boost-workaround/boost/graph/graphml.hpp b/src/boost-workaround/boost/graph/graphml.hpp index 475f13e5fc05234dd274b3ffe61c76eb28ad619c..7272067997575210c9533b49def154f927d9f06a 100644 --- a/src/boost-workaround/boost/graph/graphml.hpp +++ b/src/boost-workaround/boost/graph/graphml.hpp @@ -25,15 +25,15 @@ #include #include -namespace boost +namespace boost { ///////////////////////////////////////////////////////////////////////////// // Graph reader exceptions ///////////////////////////////////////////////////////////////////////////// -struct parse_error: public graph_exception +struct parse_error: public graph_exception { - parse_error(const std::string& err) {error = err; statement = "parse error: " + error;} + parse_error(const std::string& err) {error = err; statement = "parse error: " + error;} virtual ~parse_error() throw() {} virtual const char* what() const throw() {return statement.c_str();} std::string statement; @@ -49,14 +49,14 @@ public: virtual boost::any do_add_vertex() = 0; virtual std::pair do_add_edge(boost::any source, boost::any target) = 0; - - virtual void + + virtual void set_graph_property(const std::string& name, const std::string& value, const std::string& value_type) = 0; - virtual void + virtual void set_vertex_property(const std::string& name, boost::any vertex, const std::string& value, const std::string& value_type) = 0; - - virtual void + + virtual void set_edge_property(const std::string& name, boost::any edge, const std::string& value, const std::string& value_type) = 0; }; @@ -88,27 +88,27 @@ class mutate_graph_impl : public mutate_graph return std::make_pair(any(retval.first), retval.second); } - virtual void + virtual void set_graph_property(const std::string& name, const std::string& value, const std::string& value_type) { bool type_found = false; try { mpl::for_each(put_property - (name, m_dp, graph_property_tag(), value, value_type, m_type_names, type_found)); + (name, m_dp, graph_property_tag(), value, value_type, m_type_names, type_found)); } catch (bad_lexical_cast) { - throw parse_error("invalid value \"" + value + "\" for key \"" + + throw parse_error("invalid value \"" + value + "\" for key \"" + name + "\" of type \"" + value_type + "\""); } if (!type_found) - throw parse_error("unrecognized type \"" + value_type + + throw parse_error("unrecognized type \"" + value_type + "\" for key " + name + "\""); - + } - - virtual void + + virtual void set_vertex_property(const std::string& name, any vertex, const std::string& value, const std::string& value_type) { bool type_found = false; @@ -116,20 +116,20 @@ class mutate_graph_impl : public mutate_graph { mpl::for_each(put_property (name, m_dp, any_cast(vertex), - value, value_type, m_type_names, type_found)); + value, value_type, m_type_names, type_found)); } catch (bad_lexical_cast) { - throw parse_error("invalid value \"" + value + "\" for key " + + throw parse_error("invalid value \"" + value + "\" for key " + name + " of type " + value_type); } if (!type_found) - throw parse_error("unrecognized type \"" + value_type + + throw parse_error("unrecognized type \"" + value_type + "\" for key " + name); - + } - - virtual void + + virtual void set_edge_property(const std::string& name, any edge, const std::string& value, const std::string& value_type) { bool type_found = false; @@ -137,15 +137,15 @@ class mutate_graph_impl : public mutate_graph { mpl::for_each(put_property (name, m_dp, any_cast(edge), - value, value_type, m_type_names, type_found)); + value, value_type, m_type_names, type_found)); } catch (bad_lexical_cast) { - throw parse_error("invalid value \"" + value + "\" for key " + + throw parse_error("invalid value \"" + value + "\" for key " + name + " of type " + value_type); } if (!type_found) - throw parse_error("unrecognized type \"" + value_type + + throw parse_error("unrecognized type \"" + value_type + "\" for key " + name); } @@ -153,11 +153,11 @@ class mutate_graph_impl : public mutate_graph class put_property { public: - put_property(const std::string& name, dynamic_properties& dp, const Key& key, - const std::string& value, const std::string& value_type, + put_property(const std::string& name, dynamic_properties& dp, const Key& key, + const std::string& value, const std::string& value_type, const char** type_names, bool& type_found) - : m_name(name), m_dp(dp), m_key(key), m_value(value), - m_value_type(value_type), m_type_names(type_names), + : m_name(name), m_dp(dp), m_key(key), m_value(value), + m_value_type(value_type), m_type_names(type_names), m_type_found(type_found) {} template void operator()(Value) @@ -176,13 +176,13 @@ class mutate_graph_impl : public mutate_graph const std::string& m_value_type; const char** m_type_names; bool& m_type_found; - }; - + }; + protected: MutableGraph& m_g; dynamic_properties& m_dp; typedef mpl::vector value_types; - static const char* m_type_names[]; + static const char* m_type_names[]; }; template @@ -194,7 +194,7 @@ read_graphml(std::istream& in, mutate_graph& g); template void read_graphml(std::istream& in, MutableGraph& g, dynamic_properties& dp) -{ +{ mutate_graph_impl mg(g,dp); read_graphml(in, mg); } @@ -227,22 +227,22 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, typedef typename graph_traits::edge_descriptor edge_descriptor; typedef typename graph_traits::vertex_descriptor vertex_descriptor; - BOOST_STATIC_CONSTANT(bool, - graph_is_directed = + BOOST_STATIC_CONSTANT(bool, + graph_is_directed = (is_convertible::value)); out << "\n" << "\n"; typedef mpl::vector value_types; - const char* type_names[] = {"boolean", "int", "int", "int", "int", "long", "long", "long", "long", "float", "double", "double", "string"}; + const char* type_names[] = {"boolean", "int", "int", "int", "int", "long", "long", "long", "long", "float", "double", "double", "string"}; std::map graph_key_ids; std::map vertex_key_ids; std::map edge_key_ids; int key_count = 0; // Output keys - for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i) + for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i) { std::string key_id = "key" + lexical_cast(key_count++); if (i->second->key() == typeid(graph_property_tag)) @@ -255,14 +255,14 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, continue; std::string type_name = "string"; mpl::for_each(get_type_name(i->second->value(), type_names, type_name)); - out << " second->key() == typeid(graph_property_tag) ? "graph" : (i->second->key() == typeid(vertex_descriptor) ? "node" : "edge")) << "\"" << " attr.name=\"" << i->first << "\"" << " attr.type=\"" << type_name << "\"" << " />\n"; } - out << " \n"; @@ -270,13 +270,13 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, // Output graph data for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i) { - if (i->second->key() == typeid(graph_property_tag)) + if (i->second->key() == typeid(graph_property_tag)) { out << " first] << "\">" << i->second->get_string(graph_property_tag()) << "\n"; } } - + typedef typename graph_traits::vertex_iterator vertex_iterator; vertex_iterator v, v_end; for (tie(v, v_end) = vertices(g); v != v_end; ++v) @@ -285,7 +285,7 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, // Output data for (dynamic_properties::const_iterator i = dp.begin(); i != dp.end(); ++i) { - if (i->second->key() == typeid(vertex_descriptor)) + if (i->second->key() == typeid(vertex_descriptor)) { out << " first] << "\">" << i->second->get_string(*v) << "\n"; @@ -297,7 +297,7 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, typedef typename graph_traits::edge_iterator edge_iterator; edge_iterator e, e_end; typename graph_traits::edges_size_type edge_count = 0; - for (tie(e, e_end) = edges(g); e != e_end; ++e) + for (tie(e, e_end) = edges(g); e != e_end; ++e) { out << " second->key() == typeid(edge_descriptor)) + if (i->second->key() == typeid(edge_descriptor)) { out << " first] << "\">" << i->second->get_string(*e) << "\n"; @@ -322,7 +322,7 @@ write_graphml(std::ostream& out, const Graph& g, VertexIndexMap vertex_index, template void -write_graphml(std::ostream& out, const Graph& g, const dynamic_properties& dp, +write_graphml(std::ostream& out, const Graph& g, const dynamic_properties& dp, bool ordered_vertices=false) { write_graphml(out, g, get(vertex_index, g), dp, ordered_vertices); diff --git a/src/boost-workaround/boost/graph/kamada_kawai_spring_layout.hpp b/src/boost-workaround/boost/graph/kamada_kawai_spring_layout.hpp index 556f1f5d77aafe4af273c73d089bfd88756d304c..0c2a30c673ca1969cac71959ae368023723031eb 100644 --- a/src/boost-workaround/boost/graph/kamada_kawai_spring_layout.hpp +++ b/src/boost-workaround/boost/graph/kamada_kawai_spring_layout.hpp @@ -35,9 +35,9 @@ namespace boost { /** * Compute the edge length from an edge length. This is trivial. */ - template - T compute_edge_length(const Graph&, DistanceMap, IndexMap, + T compute_edge_length(const Graph&, DistanceMap, IndexMap, edge_or_side length) { return length.value; } @@ -46,7 +46,7 @@ namespace boost { length. We do this by dividing the side length by the largest shortest distance between any two vertices in the graph. */ - template T compute_edge_length(const Graph& g, DistanceMap distance, IndexMap index, @@ -83,9 +83,9 @@ namespace boost { vertex_descriptor; kamada_kawai_spring_layout_impl( - const Graph& g, + const Graph& g, PositionMap position, - WeightMap weight, + WeightMap weight, EdgeOrSideLength edge_or_side_length, Done done, weight_type spring_constant, @@ -93,10 +93,10 @@ namespace boost { DistanceMatrix distance, SpringStrengthMatrix spring_strength, PartialDerivativeMap partial_derivatives) - : g(g), position(position), weight(weight), + : g(g), position(position), weight(weight), edge_or_side_length(edge_or_side_length), done(done), spring_constant(spring_constant), index(index), distance(distance), - spring_strength(spring_strength), + spring_strength(spring_strength), partial_derivatives(partial_derivatives) {} // Compute contribution of vertex i to the first partial @@ -113,9 +113,9 @@ namespace boost { weight_type x_diff = position[m].x - position[i].x; weight_type y_diff = position[m].y - position[i].y; weight_type dist = sqrt(x_diff * x_diff + y_diff * y_diff); - result.first = spring_strength[get(index, m)][get(index, i)] + result.first = spring_strength[get(index, m)][get(index, i)] * (x_diff - distance[get(index, m)][get(index, i)]*x_diff/dist); - result.second = spring_strength[get(index, m)][get(index, i)] + result.second = spring_strength[get(index, m)][get(index, i)] * (y_diff - distance[get(index, m)][get(index, i)]*y_diff/dist); } @@ -123,7 +123,7 @@ namespace boost { } // Compute partial derivatives dE/dx_m and dE/dy_m - deriv_type + deriv_type compute_partial_derivatives(vertex_descriptor m) { #ifndef BOOST_NO_STDC_NAMESPACE @@ -134,7 +134,7 @@ namespace boost { weight_type second = 0; // TBD: looks like an accumulate to me int i, N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) reduction(+:first) reduction(+:second) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) reduction(+:first) reduction(+:second) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); @@ -156,15 +156,15 @@ namespace boost { #endif // BOOST_NO_STDC_NAMESPACE // Compute d_{ij} and place it in the distance matrix - if (!johnson_all_pairs_shortest_paths(g, distance, index, weight, + if (!johnson_all_pairs_shortest_paths(g, distance, index, weight, weight_type(0))) return false; // Compute L based on side length (if needed), or retrieve L - weight_type edge_length = + weight_type edge_length = detail::graph::compute_edge_length(g, distance, index, edge_or_side_length); - + // Compute l_{ij} and k_{ij} const weight_type K = spring_constant; vertex_iterator ui, end = vertices(g).second; @@ -180,7 +180,7 @@ namespace boost { spring_strength[get(index, *vi)][get(index, *ui)] = K/(dij*dij); } } - + // Compute Delta_i and find max vertex_descriptor p = *vertices(g).first; weight_type delta_p(0); @@ -189,7 +189,7 @@ namespace boost { deriv_type deriv = compute_partial_derivatives(*ui); put(partial_derivatives, *ui, deriv); - weight_type delta = + weight_type delta = sqrt(deriv.first*deriv.first + deriv.second*deriv.second); if (delta > delta_p) { @@ -206,7 +206,7 @@ namespace boost { // time. std::vector p_partials(num_vertices(g)); int i, N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); @@ -219,7 +219,7 @@ namespace boost { // Compute the 4 elements of the Jacobian weight_type dE_dx_dx = 0, dE_dx_dy = 0, dE_dy_dx = 0, dE_dy_dy = 0; N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); @@ -243,11 +243,11 @@ namespace boost { weight_type dE_dx = get(partial_derivatives, p).first; weight_type dE_dy = get(partial_derivatives, p).second; - weight_type delta_x = + weight_type delta_x = (dE_dx_dy * dE_dy - dE_dy_dy * dE_dx) / (dE_dx_dx * dE_dy_dy - dE_dx_dy * dE_dy_dx); - weight_type delta_y = + weight_type delta_y = (dE_dx_dx * dE_dy - dE_dy_dx * dE_dx) / (dE_dy_dx * dE_dx_dy - dE_dx_dx * dE_dy_dy); @@ -260,21 +260,21 @@ namespace boost { deriv_type deriv = compute_partial_derivatives(p); put(partial_derivatives, p, deriv); - delta_p = + delta_p = sqrt(deriv.first*deriv.first + deriv.second*deriv.second); } while (!done(delta_p, p, g, false)); // Select new p by updating each partial derivative and delta vertex_descriptor old_p = p; N = num_vertices(g); - #pragma omp parallel for default(shared) private(i) schedule(dynamic) + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); if (v == graph_traits::null_vertex()) continue; deriv_type old_deriv_p = p_partials[get(index, v)]; - deriv_type old_p_partial = + deriv_type old_p_partial = compute_partial_derivative(v, old_p); deriv_type deriv = get(partial_derivatives, v); @@ -282,7 +282,7 @@ namespace boost { deriv.second += old_p_partial.second - old_deriv_p.second; put(partial_derivatives, v, deriv); - weight_type delta = + weight_type delta = sqrt(deriv.first*deriv.first + deriv.second*deriv.second); #pragma omp critical @@ -290,7 +290,7 @@ namespace boost { if (delta > delta_p) { p = v; delta_p = delta; - } + } } } } @@ -298,9 +298,9 @@ namespace boost { return true; } - const Graph& g; + const Graph& g; PositionMap position; - WeightMap weight; + WeightMap weight; EdgeOrSideLength edge_or_side_length; Done done; weight_type spring_constant; @@ -312,20 +312,20 @@ namespace boost { } } // end namespace detail::graph /// States that the given quantity is an edge length. - template + template inline detail::graph::edge_or_side - edge_length(T x) + edge_length(T x) { return detail::graph::edge_or_side(x); } /// States that the given quantity is a display area side length. - template + template inline detail::graph::edge_or_side - side_length(T x) + side_length(T x) { return detail::graph::edge_or_side(x); } - /** + /** * \brief Determines when to terminate layout of a particular graph based - * on a given relative tolerance. + * on a given relative tolerance. */ template struct layout_tolerance @@ -335,8 +335,8 @@ namespace boost { last_local_energy((std::numeric_limits::max)()) { } template - bool - operator()(T delta_p, + bool + operator()(T delta_p, typename boost::graph_traits::vertex_descriptor p, const Graph& g, bool global) @@ -346,7 +346,7 @@ namespace boost { last_energy = delta_p; return false; } - + T diff = last_energy - delta_p; if (diff < T(0)) diff = -diff; bool done = (delta_p == T(0) || diff / last_energy < tolerance); @@ -357,7 +357,7 @@ namespace boost { last_local_energy = delta_p; return delta_p == T(0); } - + T diff = last_local_energy - delta_p; bool done = (delta_p == T(0) || (diff / last_local_energy) < tolerance); last_local_energy = delta_p; @@ -445,11 +445,11 @@ namespace boost { typename T, bool EdgeOrSideLength, typename Done, typename VertexIndexMap, typename DistanceMatrix, typename SpringStrengthMatrix, typename PartialDerivativeMap> - bool + bool kamada_kawai_spring_layout( - const Graph& g, + const Graph& g, PositionMap position, - WeightMap weight, + WeightMap weight, detail::graph::edge_or_side edge_or_side_length, Done done, typename property_traits::value_type spring_constant, @@ -464,8 +464,8 @@ namespace boost { >::value)); detail::graph::kamada_kawai_spring_layout_impl< - Graph, PositionMap, WeightMap, - detail::graph::edge_or_side, Done, VertexIndexMap, + Graph, PositionMap, WeightMap, + detail::graph::edge_or_side, Done, VertexIndexMap, DistanceMatrix, SpringStrengthMatrix, PartialDerivativeMap> alg(g, position, weight, edge_or_side_length, done, spring_constant, index, distance, spring_strength, partial_derivatives); @@ -476,13 +476,13 @@ namespace boost { * \overload */ template - bool + bool kamada_kawai_spring_layout( - const Graph& g, + const Graph& g, PositionMap position, - WeightMap weight, + WeightMap weight, detail::graph::edge_or_side edge_or_side_length, Done done, typename property_traits::value_type spring_constant, @@ -497,7 +497,7 @@ namespace boost { std::vector spring_strength(n, weight_vec(n)); std::vector > partial_derivatives(n); - return + return kamada_kawai_spring_layout( g, position, weight, edge_or_side_length, done, spring_constant, index, distance.begin(), @@ -511,17 +511,17 @@ namespace boost { */ template - bool + bool kamada_kawai_spring_layout( - const Graph& g, + const Graph& g, PositionMap position, - WeightMap weight, + WeightMap weight, detail::graph::edge_or_side edge_or_side_length, Done done, typename property_traits::value_type spring_constant) { return kamada_kawai_spring_layout(g, position, weight, edge_or_side_length, - done, spring_constant, + done, spring_constant, get(vertex_index, g)); } @@ -530,17 +530,17 @@ namespace boost { */ template - bool + bool kamada_kawai_spring_layout( - const Graph& g, + const Graph& g, PositionMap position, - WeightMap weight, + WeightMap weight, detail::graph::edge_or_side edge_or_side_length, Done done) { typedef typename property_traits::value_type weight_type; return kamada_kawai_spring_layout(g, position, weight, edge_or_side_length, - done, weight_type(1)); + done, weight_type(1)); } /** @@ -548,17 +548,17 @@ namespace boost { */ template - bool + bool kamada_kawai_spring_layout( - const Graph& g, + const Graph& g, PositionMap position, - WeightMap weight, + WeightMap weight, detail::graph::edge_or_side edge_or_side_length) { typedef typename property_traits::value_type weight_type; return kamada_kawai_spring_layout(g, position, weight, edge_or_side_length, layout_tolerance(), - weight_type(1.0), + weight_type(1.0), get(vertex_index, g)); } } // end namespace boost diff --git a/src/graph/Makefile.am b/src/graph/Makefile.am index 3cd64079d918cc6b1cfa36f5f38615f4f928ac83..2fd9b9fe2f07ac4a1c57cbed05bda5a0280d3390 100644 --- a/src/graph/Makefile.am +++ b/src/graph/Makefile.am @@ -1,5 +1,7 @@ ## Process this file with automake to produce Makefile.in +SUBDIRS = correlations + AM_CPPFLAGS =\ -I. -I.. \ -I../boost-workaround \ @@ -12,78 +14,33 @@ AM_CXXFLAGS =\ AM_CFLAGS=$(AM_CXXFLAGS) -libgraph_tooldir = $(pythondir)/graph_tool +libgraph_tool_coredir = $(pythondir)/graph_tool -libgraph_tool_LTLIBRARIES = libgraph_tool.la +libgraph_tool_core_LTLIBRARIES = libgraph_tool_core.la -libgraph_tool_la_includedir = $(pythondir)/graph_tool/include +libgraph_tool_core_la_includedir = $(pythondir)/graph_tool/include -libgraph_tool_la_SOURCES = \ - graph_assortativity.cc \ - graph_betweenness.cc \ +libgraph_tool_core_la_SOURCES = \ graph_bind.cc \ graph.cc \ - graph_clustering.cc \ - graph_community.cc \ - graph_community_network.cc \ - graph_correlations.cc \ - graph_correlations_combined.cc \ - graph_correlations_combined_corr.cc \ - graph_correlations_imp1.cc \ - graph_correlations_imp2.cc \ - graph_correlations_imp3.cc \ - graph_correlations_neighbours.cc \ - graph_correlations_neighbours_imp1.cc \ - graph_correlations_neighbours_imp2.cc \ - graph_correlations_neighbours_imp3.cc \ - graph_correlations_neighbours_imp4.cc \ - graph_correlations_neighbours_imp5.cc \ - graph_correlations_neighbours_imp6.cc \ - graph_distance.cc \ - graph_distance_sampled.cc \ - graph_edge_correlations.cc \ - graph_edge_correlations_imp1.cc \ - graph_edge_correlations_imp2.cc \ - graph_edge_correlations_imp3.cc \ - graph_edge_correlations_imp4.cc \ - graph_edge_correlations_imp5.cc \ - graph_extended_clustering.cc \ + graph_copy.cc \ graph_filtering.cc \ - graph_generation.cc \ graph_io.cc \ - graph_layout.cc \ - graph_line_graph.cc \ - graph_minimum_spanning_tree.cc \ graph_properties.cc \ graph_python_interface.cc \ graph_python_interface_export.cc \ - graph_reciprocity.cc \ - graph_rewiring.cc \ graph_selectors.cc \ graphml.cpp\ read_graphviz_spirit.cpp\ ../boost-workaround/boost/graph/filtered_graph.hpp\ - ../boost-workaround/boost/graph/fruchterman_reingold.hpp\ ../boost-workaround/boost/graph/graphml.hpp -libgraph_tool_la_include_HEADERS = \ +libgraph_tool_core_la_include_HEADERS = \ graph_adaptor.hh \ - graph_assortativity.hh \ - graph_clustering.hh \ - graph_community.hh \ - graph_community_network.hh \ - graph_correlations_combined.hh \ - graph_correlations.hh \ - graph_correlations_neighbours.hh \ - graph_distance.hh \ - graph_distance_sampled.hh \ - graph_edge_correlations.hh \ - graph_extended_clustering.hh \ graph_filtering.hh \ graph.hh \ graph_properties.hh \ graph_python_interface.hh \ - graph_rewiring.hh \ graph_selectors.hh \ graph_util.hh \ histogram.hh \ @@ -91,19 +48,20 @@ libgraph_tool_la_include_HEADERS = \ shared_map.hh \ ../../config.h -BUILT_SOURCES = \ - graph_filtering.hh.gch +# leave out precompiled headers for now, since it doesn't seem to help much +# BUILT_SOURCES = \ +# graph_filtering.hh.gch -## Header precompilation -## FIXME: need a better way to convince libtool to let us do this. -$(libgraph_tool_la_include_HEADERS): +# ## Header precompilation +# ## FIXME: need a better way to convince libtool to let us do this. +# $(libgraph_tool_la_include_HEADERS): -$(BUILT_SOURCES): - $(CXXCOMPILE) $(CXXFLAGS) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -fPIC -DPIC -x c++-header `basename $@ .gch` -mostlyclean-local: - -rm -f *.gch +# $(BUILT_SOURCES): +# $(CXXCOMPILE) $(CXXFLAGS) $(AM_CXXFLAGS) $(AM_CPPFLAGS) -fPIC -DPIC -x c++-header `basename $@ .gch` +# mostlyclean-local: +# -rm -f *.gch -libgraph_tool_la_LIBADD = \ +libgraph_tool_core_la_LIBADD = \ $(PYTHON_LDFLAGS) \ $(BOOST_LDFLAGS) \ $(OPENMP_LDFLAGS) \ @@ -113,7 +71,7 @@ libgraph_tool_la_LIBADD = \ # needed for typeinfo objects to work across DSO boundaries. # see http://gcc.gnu.org/faq.html#dso -libgraph_tool_la_LDFLAGS = \ +libgraph_tool_core_la_LDFLAGS = \ -module \ -avoid-version \ -export-dynamic \ diff --git a/src/graph/graph_clustering.cc b/src/graph/clustering/graph_clustering.cc similarity index 98% rename from src/graph/graph_clustering.cc rename to src/graph/clustering/graph_clustering.cc index 470bdbd0969f74f522676c35b8834ee6712db6c0..ce052126975433faf7223ef8f385d47fc5a98669 100644 --- a/src/graph/graph_clustering.cc +++ b/src/graph/clustering/graph_clustering.cc @@ -35,7 +35,7 @@ GraphInterface::GetGlobalClustering() bool directed = _directed; _directed = false; run_action() - (*this, bind(get_global_clustering(), _1, var(c), var(c_err)))(); + (*this, bind(get_global_clustering(), _1, var(c), var(c_err)))(); _directed = directed; return make_pair(c,c_err); } @@ -49,7 +49,7 @@ void GraphInterface::SetLocalClusteringToProperty(string property) find_property_map(_properties, property, typeid(vertex_t)); vertex_prop = prop(property, _vertex_index, _properties); if (!belongs()(vertex_prop)) - throw GraphException("vertex property " + property + + throw GraphException("vertex property " + property + " is not of floating type"); } catch (property_not_found) @@ -63,6 +63,6 @@ void GraphInterface::SetLocalClusteringToProperty(string property) bool directed = _directed; _directed = false; run_action() - (*this, bind(set_clustering_to_property(), _1, _2))(vertex_prop); + (*this, bind(set_clustering_to_property(), _1, _2))(vertex_prop); _directed = directed; } diff --git a/src/graph/graph_clustering.hh b/src/graph/clustering/graph_clustering.hh similarity index 94% rename from src/graph/graph_clustering.hh rename to src/graph/clustering/graph_clustering.hh index de6ce48ccd1f74d098f60e93b6ecfd356c81574e..3b7761f8e6ce2bb1b20826cf0105eb75acebe223 100644 --- a/src/graph/graph_clustering.hh +++ b/src/graph/clustering/graph_clustering.hh @@ -27,14 +27,14 @@ using namespace boost; // calculates the number of triangles to which v belongs template -pair +pair get_triangles(typename graph_traits::vertex_descriptor v, const Graph &g) { - tr1::unordered_set::vertex_descriptor> + tr1::unordered_set::vertex_descriptor> neighbour_set1, neighbour_set2, neighbour_set3; - + size_t triangles = 0, k = 0; - + typename graph_traits::adjacency_iterator n1_begin, n1_end, n1; tie(n1_begin, n1_end) = adjacent_vertices(v, g); for (n1 = n1_begin; n1 != n1_end; ++n1) @@ -45,7 +45,7 @@ get_triangles(typename graph_traits::vertex_descriptor v, const Graph &g) continue; else neighbour_set1.insert(*n1); - + typename graph_traits::adjacency_iterator n2_begin, n2_end, n2; tie(n2_begin, n2_end) = adjacent_vertices(*n1, g); for (n2 = n2_begin; n2 != n2_end; ++n2) @@ -56,8 +56,8 @@ get_triangles(typename graph_traits::vertex_descriptor v, const Graph &g) continue; else neighbour_set2.insert(*n2); - - typename graph_traits::adjacency_iterator + + typename graph_traits::adjacency_iterator n3_begin, n3_end, n3; tie(n3_begin, n3_end) = adjacent_vertices(*n2, g); for (n3 = n3_begin; n3 != n3_end; ++n3) @@ -68,9 +68,9 @@ get_triangles(typename graph_traits::vertex_descriptor v, const Graph &g) continue; else neighbour_set3.insert(*n3); - + if (*n3 == v) //found a triangle - triangles++; + triangles++; } neighbour_set3.clear(); } @@ -103,14 +103,14 @@ struct get_global_clustering continue; temp = get_triangles(v, g); - triangles += temp.first; + triangles += temp.first; n += temp.second; } c = double(triangles)/n; // "jackknife" variance c_err = 0.0; - + #pragma omp parallel for default(shared) private(i,temp) \ schedule(dynamic) reduction(+|c_err) for (i = 0; i < N; ++i) @@ -122,7 +122,7 @@ struct get_global_clustering temp = get_triangles(v, g); double cl = double(triangles - temp.first)/(n - temp.second); - c_err += (c - cl)*(c - cl); + c_err += (c - cl)*(c - cl); } c_err = sqrt(c_err); } @@ -138,26 +138,26 @@ struct set_clustering_to_property const Graph& g = *gp; typename get_undirected_graph::type ug(g); int i, N = num_vertices(g); - + #pragma omp parallel for default(shared) private(i) schedule(dynamic) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); if (v == graph_traits::null_vertex()) continue; - + pair triangles = get_triangles(v,ug); // get from ug double clustering = (triangles.second > 0) ? double(triangles.first)/triangles.second : 0.0; - + #pragma omp critical { clust_map[v] = clustering; } } } - + template struct get_undirected_graph { @@ -169,6 +169,6 @@ struct set_clustering_to_property }; }; -} //graph-tool namespace +} //graph-tool namespace #endif // GRAPH_CLUSTERING_HH diff --git a/src/graph/graph_extended_clustering.cc b/src/graph/clustering/graph_extended_clustering.cc similarity index 97% rename from src/graph/graph_extended_clustering.cc rename to src/graph/clustering/graph_extended_clustering.cc index 6377d4c0e4ed1e3ddecfdec77a1dea6d35f034a7..9f18a2aeb8b5fe2ec8ddc73cc041d508325bf213 100644 --- a/src/graph/graph_extended_clustering.cc +++ b/src/graph/clustering/graph_extended_clustering.cc @@ -34,7 +34,7 @@ using namespace graph_tool; template struct prop_vector -{ +{ boost::any operator()(const vector& props, bool& found) const { boost::any prop_vec; @@ -49,7 +49,7 @@ struct prop_vector template void operator()(Property, const vector& props, boost::any& prop_vec, bool& found) const - { + { if (typeid(Property) == props[0].type()) { try @@ -100,18 +100,18 @@ void GraphInterface::SetExtendedClusteringToProperty(string property_prefix, } } - typedef mpl::transform::type property_vectors; bool found = false; run_action<>() - (*this, bind(get_extended_clustering(), _1, _vertex_index,_2), + (*this, bind(get_extended_clustering(), _1, _vertex_index,_2), property_vectors()) (prop_vector()(cmaps, found)); if (!found) - throw GraphException("All vertex properties " + property_prefix + + throw GraphException("All vertex properties " + property_prefix + "* must be of the same floating point type!"); } diff --git a/src/graph/graph_extended_clustering.hh b/src/graph/clustering/graph_extended_clustering.hh similarity index 100% rename from src/graph/graph_extended_clustering.hh rename to src/graph/clustering/graph_extended_clustering.hh diff --git a/src/graph/graph_community.cc b/src/graph/community/graph_community.cc similarity index 93% rename from src/graph/graph_community.cc rename to src/graph/community/graph_community.cc index a48b51149eae723bb07bfda3ab3613c24b98f4c6..37208549809997e208c4dbee835251035bc9b3ed 100644 --- a/src/graph/graph_community.cc +++ b/src/graph/community/graph_community.cc @@ -30,16 +30,16 @@ using namespace boost; using namespace boost::lambda; using namespace graph_tool; -void GraphInterface::GetCommunityStructure(double gamma, comm_corr_t corr, - size_t n_iter, double Tmin, - double Tmax, size_t Nspins, - size_t seed, bool verbose, - string history_file, string weight, +void GraphInterface::GetCommunityStructure(double gamma, comm_corr_t corr, + size_t n_iter, double Tmin, + double Tmax, size_t Nspins, + size_t seed, bool verbose, + string history_file, string weight, string property) { typedef property_map_types::apply, vertex_index_map_t, - mpl::bool_ >::type + mpl::bool_ >::type allowed_spin_properties; boost::any vertex_prop; @@ -49,7 +49,7 @@ void GraphInterface::GetCommunityStructure(double gamma, comm_corr_t corr, find_property_map(_properties, property, typeid(vertex_t)); vertex_prop = prop(property, _vertex_index, _properties); if (!belongs()(vertex_prop)) - throw GraphException("vertex property " + property + + throw GraphException("vertex property " + property + " is not of integer type int32_t or int64_t"); new_spins = false; } @@ -69,7 +69,7 @@ void GraphInterface::GetCommunityStructure(double gamma, comm_corr_t corr, if(weight != "") { - try + try { weight_map_t wrap(find_property_map(_properties, weight, typeid(edge_t))); @@ -91,9 +91,9 @@ void GraphInterface::GetCommunityStructure(double gamma, comm_corr_t corr, { run_action() (*this, bind(get_communities_selector(corr), - _1, _2, _3, gamma, n_iter, - make_pair(Tmin, Tmax), - make_pair(Nspins, new_spins), + _1, _2, _3, gamma, n_iter, + make_pair(Tmin, Tmax), + make_pair(Nspins, new_spins), seed, make_pair(verbose,history_file)), weight_properties(), allowed_spin_properties()) (edge_prop, vertex_prop); @@ -121,7 +121,7 @@ double GraphInterface::GetModularity(string weight, string property) edge_prop = prop(weight, _edge_index, _properties); else edge_prop = weight_map_t(1); - + typedef mpl::push_back::type weight_properties; @@ -137,7 +137,7 @@ double GraphInterface::GetModularity(string weight, string property) catch (property_not_found& e) { _directed = directed; - throw GraphException("error getting scalar property: " + + throw GraphException("error getting scalar property: " + string(e.what())); } _directed = directed; diff --git a/src/graph/graph_community.hh b/src/graph/community/graph_community.hh similarity index 98% rename from src/graph/graph_community.hh rename to src/graph/community/graph_community.hh index 3c1ebdccae2d46ea8468ed150705f5fdd3b4f581..056622e2590fd105404d9923b42b76aeff11f3a9 100644 --- a/src/graph/graph_community.hh +++ b/src/graph/community/graph_community.hh @@ -44,7 +44,7 @@ template