// graph-tool -- a general graph modification and manipulation thingy // // Copyright (C) 2006-2015 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 . #include "graph_python_interface.hh" #include "graph.hh" #include "graph_properties.hh" #include "graph_filtering.hh" #include "graph_selectors.hh" #include "graph_util.hh" using namespace std; using namespace boost; using namespace graph_tool; template struct do_edge_endpoint { template void operator()(Graph& g, EdgeIndexMap, VertexPropertyMap prop, boost::any aeprop) const { typedef typename property_traits::value_type vval_t; typedef typename boost::mpl::if_, int64_t, vval_t>::type val_t; typedef typename property_map_type::apply::type eprop_t; eprop_t eprop = any_cast(aeprop); eprop.reserve(num_edges(g)); int i, N = num_vertices(g); #pragma omp parallel for default(shared) private(i) \ schedule(runtime) if (N > 100) for (i = 0; i < N; ++i) { typename graph_traits::vertex_descriptor v = vertex(i, g); if (v == graph_traits::null_vertex()) continue; for (auto e : out_edges_range(v, g)) { auto s = v; auto t = target(e, g); if (!is_directed::apply::type::value && s > t) continue; if (src) eprop[e] = prop[s]; else eprop[e] = prop[t]; } } } }; void edge_endpoint(GraphInterface& gi, boost::any prop, boost::any eprop, std::string endpoint) { if (endpoint == "source") run_action<>()(gi, std::bind(do_edge_endpoint(), placeholders::_1, gi.GetEdgeIndex(), placeholders::_2, eprop), vertex_properties())(prop); else run_action<>()(gi, std::bind(do_edge_endpoint(), placeholders::_1, gi.GetEdgeIndex(), placeholders::_2, eprop), vertex_properties())(prop); }