inline OutputIterator
 kruskal_minimum_spanning_tree(const Graph& g,
                               OutputIterator spanning_tree_edges, 
                               const bgl_named_params<P, T, R>& params)
 {
   typedef typename graph_traits<Graph>::vertices_size_type size_type;
   typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
   if (num_vertices(g) == 0) return spanning_tree_edges; // Nothing to do in this case
   typename graph_traits<Graph>::vertices_size_type n;
   n = is_default_param(get_param(params, vertex_rank))
                                  ? num_vertices(g) : 1;
   std::vector<size_type> rank_map(n);
   n = is_default_param(get_param(params, vertex_predecessor))
                                  ? num_vertices(g) : 1;
   std::vector<vertex_t> pred_map(n);
   
   return detail::kruskal_mst_impl
     (g, spanning_tree_edges, 
      choose_param
      (get_param(params, vertex_rank), 
       make_iterator_property_map
       (rank_map.begin(), 
        choose_pmap(get_param(params, vertex_index), g, vertex_index), rank_map[0])),
      choose_param
      (get_param(params, vertex_predecessor), 
       make_iterator_property_map
       (pred_map.begin(), 
        choose_const_pmap(get_param(params, vertex_index), g, vertex_index), 
        pred_map[0])),
      choose_const_pmap(get_param(params, edge_weight), g, edge_weight));
 }
Example #2
0
    inline void
    dag_sp_dispatch1
      (const VertexListGraph& g,
       typename graph_traits<VertexListGraph>::vertex_descriptor s, 
       DistanceMap distance, WeightMap weight, ColorMap color, IndexMap id,
       DijkstraVisitor vis, const Params& params)
    {
      typedef typename property_traits<WeightMap>::value_type T;
      typename std::vector<T>::size_type n;
      n = is_default_param(distance) ? num_vertices(g) : 1;
      std::vector<T> distance_map(n);
      n = is_default_param(color) ? num_vertices(g) : 1;
      std::vector<default_color_type> color_map(n);

      dag_sp_dispatch2
        (g, s, 
         choose_param(distance, 
                      make_iterator_property_map(distance_map.begin(), id,
                                                 distance_map[0])),
         weight, 
         choose_param(color,
                      make_iterator_property_map(color_map.begin(), id, 
                                                 color_map[0])),
         id, vis, params);
    }
Example #3
0
      base_state(const GraphThis& graph_this, const GraphOther& graph_other,
                 IndexMapThis index_map_this, IndexMapOther index_map_other)
        : graph_this_(graph_this), graph_other_(graph_other), 
          index_map_this_(index_map_this), index_map_other_(index_map_other), 
          term_in_count_(0), term_out_count_(0), term_both_count_(0), core_count_(0) {

        core_vec_.resize(num_vertices(graph_this_), graph_traits<GraphOther>::null_vertex());
        core_ = make_iterator_property_map(core_vec_.begin(), index_map_this_);

        in_vec_.resize(num_vertices(graph_this_), 0);
        in_ = make_iterator_property_map(in_vec_.begin(), index_map_this_);

        out_vec_.resize(num_vertices(graph_this_), 0);
        out_ = make_iterator_property_map(out_vec_.begin(), index_map_this_);
      }
  inline void
  dijkstra_shortest_paths_no_init
    (const VertexListGraph& g,
     typename graph_traits<VertexListGraph>::vertex_descriptor s, 
     PredecessorMap predecessor, DistanceMap distance, WeightMap weight, 
     IndexMap index_map,
     Compare compare, Combine combine, DistInf inf, DistZero zero,
     DijkstraVisitor vis)
  {
    typedef indirect_cmp<DistanceMap, Compare> IndirectCmp;
    IndirectCmp icmp(distance, compare);

    typedef typename graph_traits<VertexListGraph>::vertex_descriptor Vertex;
    typedef mutable_queue<Vertex, std::vector<Vertex>, IndirectCmp, IndexMap>
      MutableQueue;

    MutableQueue Q(num_vertices(g), icmp, index_map);

    detail::dijkstra_bfs_visitor<DijkstraVisitor, MutableQueue, WeightMap,
      PredecessorMap, DistanceMap, Combine, Compare>
        bfs_vis(vis, Q, weight, predecessor, distance, combine, compare, zero);

    std::vector<default_color_type> color(num_vertices(g));
    default_color_type c = white_color;
    breadth_first_visit(g, s, Q, bfs_vis,
      make_iterator_property_map(&color[0], index_map, c));
  }
Example #5
0
static
bool pruneForwardUseless(NGHolder &h, const nfag_t &g, NFAVertex s,
                         vector<default_color_type> &vertexColor) {
    // Begin with all vertices set to white, as DFV only marks visited
    // vertices.
    fill(vertexColor.begin(), vertexColor.end(), boost::white_color);

    auto index_map = get(&NFAGraphVertexProps::index, g);

    depth_first_visit(g, s, make_dfs_visitor(boost::null_visitor()),
                      make_iterator_property_map(vertexColor.begin(),
                                                 index_map));

    vector<NFAVertex> dead;

    // All non-special vertices that are still white can be removed.
    for (auto v : vertices_range(g)) {
        u32 idx = g[v].index;
        if (!is_special(v, g) && vertexColor[idx] == boost::white_color) {
            DEBUG_PRINTF("vertex %u is unreachable from %u\n",
                         g[v].index, g[s].index);
            dead.push_back(v);
        }
    }

    if (dead.empty()) {
        return false;
    }

    DEBUG_PRINTF("removing %zu vertices\n", dead.size());
    remove_vertices(dead, h, false);
    return true;
}
 static typename edge_capacity_value<Graph, P, T, R>::type
 apply
 (Graph& g,
  typename graph_traits<Graph>::vertex_descriptor src,
  typename graph_traits<Graph>::vertex_descriptor sink,
  PredMap pred,
  const bgl_named_params<P, T, R>& params,
  detail::error_property_not_found)
 {
   typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
   typedef typename graph_traits<Graph>::vertices_size_type size_type;
   size_type n = is_default_param(get_param(params, vertex_color)) ?
     num_vertices(g) : 1;
   std::vector<default_color_type> color_vec(n);
   return edmunds_karp_max_flow
     (g, src, sink, 
      choose_const_pmap(get_param(params, edge_capacity), g, edge_capacity),
      choose_pmap(get_param(params, edge_residual_capacity), 
                  g, edge_residual_capacity),
      choose_const_pmap(get_param(params, edge_reverse), g, edge_reverse),
      make_iterator_property_map(color_vec.begin(), choose_const_pmap
                                 (get_param(params, vertex_index),
                                  g, vertex_index), color_vec[0]),
      pred);
 }
  inline void 
  kruskal_minimum_spanning_tree(const Graph& g,
                                OutputIterator spanning_tree_edges)
  {
    typedef typename graph_traits<Graph>::vertices_size_type size_type;
    typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
    if (num_vertices(g) == 0) return; // Nothing to do in this case
    typename graph_traits<Graph>::vertices_size_type
      n = num_vertices(g);
    std::vector<size_type> rank_map(n);
    std::vector<vertex_t> pred_map(n);

    detail::kruskal_mst_impl
      (g, spanning_tree_edges, 
       make_iterator_property_map(rank_map.begin(), get(vertex_index, g), rank_map[0]),
       make_iterator_property_map(pred_map.begin(), get(vertex_index, g), pred_map[0]),
       get(edge_weight, g));
  }
Example #8
0
void
betweenness_centrality_clustering(MutableGraph& g, Done done)
{
  typedef typename Done::centrality_type centrality_type;
  std::vector<centrality_type> edge_centrality(num_edges(g));
  betweenness_centrality_clustering(g, done, 
    make_iterator_property_map(edge_centrality.begin(), get(edge_index, g)),
    get(vertex_index, g));
}
  std::pair<std::size_t, OutputIterator>
  biconnected_components(const Graph& g, ComponentMap comp, OutputIterator out,
                         VertexIndexMap index_map)
  {
    typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
    typedef typename graph_traits<Graph>::vertices_size_type
      vertices_size_type;

    std::vector<vertices_size_type> discover_time(num_vertices(g));
    std::vector<vertices_size_type> lowpt(num_vertices(g));

    vertices_size_type vst(0);

    return biconnected_components
             (g, comp, out,
              make_iterator_property_map(discover_time.begin(), index_map, vst),
              make_iterator_property_map(lowpt.begin(), index_map, vst),
              index_map);
  }
Example #10
0
 typename property_traits<CoreMap>::value_type
 core_numbers(Graph& g, CoreMap c, CoreNumVisitor vis)
 {
     typedef typename graph_traits<Graph>::vertices_size_type size_type;
     detail::compute_in_degree_map(g,c,
         detail::constant_value_property_map<
             typename property_traits<CoreMap>::value_type>(1) );
     return detail::core_numbers_impl(g,c,
         make_iterator_property_map(
             std::vector<size_type>(num_vertices(g)).begin(),get(vertex_index, g)),
         vis
     );
 }
Example #11
0
 std::pair<std::size_t, OutputIterator>
 biconnected_components(const Graph & g, ComponentMap comp,
                        OutputIterator out, DiscoverTimeMap discover_time,
                        LowPointMap lowpt, VertexIndexMap index_map)
 {
   typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
   std::vector<vertex_t> pred(num_vertices(g));
   vertex_t vert = graph_traits<Graph>::null_vertex();
   return biconnected_components
            (g, comp, out, discover_time, lowpt,
             make_iterator_property_map(pred.begin(), index_map, vert),
             index_map);
 }
inline typename FloatTraits::value_type
minimum_cycle_mean(const Graph &g, VertexIndexMap vim,
                   EdgeWeightMap ewm, EdgeIndexMap eim,
                   std::vector<typename graph_traits<Graph>::edge_descriptor>* pcc = 0,
                   FloatTraits ft = FloatTraits())
{
    typedef typename remove_const<
        typename property_traits<EdgeWeightMap>::value_type
    >::type Weight;
    typename std::vector<Weight> ed_w2(boost::num_edges(g), 1);
    return minimum_cycle_ratio(g, vim, ewm,
                               make_iterator_property_map(ed_w2.begin(), eim),
                               pcc, ft);
}
Example #13
0
distributed_property_map<ProcessGroup, 
                         GlobalMap,
                         iterator_property_map<RandomAccessIterator, 
                                               StorageMap> >
make_iterator_property_map(RandomAccessIterator cc,
                           local_property_map<ProcessGroup, GlobalMap, 
                                              StorageMap> index_map)
{
  typedef distributed_property_map<
            ProcessGroup, GlobalMap,
            iterator_property_map<RandomAccessIterator, StorageMap> >
    result_type;
  return result_type(index_map.process_group(), index_map.global(),
                     make_iterator_property_map(cc, index_map.base()));
}
Example #14
0
    void transitive_closure_dispatch
      (const Graph & g, GraphTC & tc,
       G_to_TC_VertexMap g_to_tc_map, VertexIndexMap index_map)
    {
      typedef typename graph_traits < GraphTC >::vertex_descriptor tc_vertex;
      typename std::vector < tc_vertex >::size_type
        n = is_default_param(g_to_tc_map) ? num_vertices(g) : 1;
      std::vector < tc_vertex > to_tc_vec(n);

      transitive_closure
        (g, tc,
         choose_param(g_to_tc_map, make_iterator_property_map
                      (to_tc_vec.begin(), index_map, to_tc_vec[0])),
         index_map);
    }
Example #15
0
 static void
 apply(const Graph& g, DFSVisitor vis, Vertex start_vertex,
       const bgl_named_params<P, T, R>& params,
       EdgeColorMap edge_color,
       param_not_found)
 {
   std::vector<default_color_type> color_vec(num_vertices(g));
   default_color_type c = white_color; // avoid warning about un-init
   undirected_dfs
     (g, vis, make_iterator_property_map
      (color_vec.begin(),
       choose_const_pmap(get_param(params, vertex_index),
                         g, vertex_index), c),
      edge_color,
      start_vertex);
 }
 inline static typename property_traits<ComponentMap>::value_type
 apply(const Graph& g,
       ComponentMap comp,
       RootMap r_map,
       const bgl_named_params<P, T, R>& params,
       param_not_found)
 {
     typedef typename graph_traits<Graph>::vertices_size_type size_type;
     size_type       n = num_vertices(g) > 0 ? num_vertices(g) : 1;
     std::vector<size_type> time_vec(n);
     return strong_components_impl
            (g, comp, r_map,
             make_iterator_property_map(time_vec.begin(), choose_const_pmap
                                        (get_param(params, vertex_index),
                                         g, vertex_index), time_vec[0]),
             params);
 }
 inline static typename property_traits<ComponentMap>::value_type
 apply(const Graph& g,
       ComponentMap comp,
       const bgl_named_params<P, T, R>& params,
       param_not_found)
 {
     typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
     typename std::vector<Vertex>::size_type
     n = num_vertices(g) > 0 ? num_vertices(g) : 1;
     std::vector<Vertex> root_vec(n);
     return scc_helper2
            (g, comp,
             make_iterator_property_map(root_vec.begin(), choose_const_pmap
                                        (get_param(params, vertex_index),
                                         g, vertex_index), root_vec[0]),
             params,
             get_param(params, vertex_discover_time));
 }
    inline void
    dijkstra_dispatch1
      (const VertexListGraph& g,
       typename graph_traits<VertexListGraph>::vertex_descriptor s, 
       DistanceMap distance, WeightMap weight, IndexMap index_map,
       const Params& params)
    {
      // Default for distance map
      typedef typename property_traits<WeightMap>::value_type D;
      typename std::vector<D>::size_type 
        n = is_default_param(distance) ? num_vertices(g) : 1;
      std::vector<D> distance_map(n);

      detail::dijkstra_dispatch2
        (g, s, choose_param(distance, make_iterator_property_map
                            (distance_map.begin(), index_map, 
                             distance_map[0])),
         weight, index_map, params);
    }
Example #19
0
      static void 
      run(const DistributedGraph& g,
          typename graph_traits<DistributedGraph>::vertex_descriptor s,
          PredecessorMap predecessor, DistanceMap distance, 
          Lookahead lookahead, WeightMap weight, IndexMap index_map, 
          ::boost::param_not_found,
          Compare compare, Combine combine, DistInf inf, DistZero zero,
          DijkstraVisitor vis)
      {
        typedef typename graph_traits<DistributedGraph>::vertices_size_type
          vertices_size_type;

        vertices_size_type n = num_vertices(g);
        std::vector<default_color_type> colors(n, white_color);

        run_impl(g, s, predecessor, distance, lookahead, weight, index_map,
                 make_iterator_property_map(colors.begin(), index_map),
                 compare, combine, inf, zero, vis);
      }
Example #20
0
 static void apply
 (VertexListGraph& g,
  typename graph_traits<VertexListGraph>::vertex_descriptor s,
  const bgl_named_params<P, T, R>& params,
  detail::error_property_not_found)
 {
   std::vector<default_color_type> color_vec(num_vertices(g));
   default_color_type c = white_color;
   null_visitor null_vis;
   
   bfs_helper
     (g, s, 
      make_iterator_property_map
      (color_vec.begin(), 
       choose_const_pmap(get_param(params, vertex_index), 
                         g, vertex_index), c),
      choose_param(get_param(params, graph_visitor),
                   make_bfs_visitor(null_vis)),
      params);
 }
Example #21
0
static
depth findMinWidth(const NGHolder &h, const SpecialEdgeFilter &filter,
                   NFAVertex src) {
    if (isLeafNode(src, h)) {
        return depth::unreachable();
    }

    boost::filtered_graph<NFAGraph, SpecialEdgeFilter> g(h.g, filter);

    assert(hasCorrectlyNumberedVertices(h));
    const size_t num = num_vertices(h);
    vector<depth> distance(num, depth::unreachable());
    distance.at(g[src].index) = depth(0);

    auto index_map = get(&NFAGraphVertexProps::index, g);

    // Since we are interested in the single-source shortest paths on a graph
    // with the same weight on every edge, using BFS will be faster than
    // Dijkstra here.
    breadth_first_search(
        g, src,
        visitor(make_bfs_visitor(record_distances(
                    make_iterator_property_map(distance.begin(), index_map),
                    boost::on_tree_edge()))).vertex_index_map(index_map));

    DEBUG_PRINTF("d[accept]=%s, d[acceptEod]=%s\n",
                 distance.at(NODE_ACCEPT).str().c_str(),
                 distance.at(NODE_ACCEPT_EOD).str().c_str());

    depth d = min(distance.at(NODE_ACCEPT), distance.at(NODE_ACCEPT_EOD));

    if (d.is_unreachable()) {
        return d;
    }

    assert(d.is_finite());
    assert(d > depth(0));
    return d - depth(1);
}
  typename property_traits<ColorMap>::value_type
  sequential_vertex_coloring(const VertexListGraph& G, ColorMap color)
  {
    typedef typename graph_traits<VertexListGraph>::vertex_descriptor
      vertex_descriptor;
    typedef typename graph_traits<VertexListGraph>::vertex_iterator
      vertex_iterator;

    std::pair<vertex_iterator, vertex_iterator> v = vertices(G);
#ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS
    std::vector<vertex_descriptor> order(v.first, v.second);
#else
    std::vector<vertex_descriptor> order;
    order.reserve(std::distance(v.first, v.second));
    while (v.first != v.second) order.push_back(*v.first++);
#endif
    return sequential_vertex_coloring
             (G, 
              make_iterator_property_map
              (order.begin(), identity_property_map(), 
               graph_traits<VertexListGraph>::null_vertex()), 
              color);
  }
 static typename edge_capacity_value<Graph, P, T, R>::type
 apply
 (Graph& g,
  typename graph_traits<Graph>::vertex_descriptor src,
  typename graph_traits<Graph>::vertex_descriptor sink,
  const bgl_named_params<P, T, R>& params,
  detail::error_property_not_found)
 {
   typedef typename graph_traits<Graph>::edge_descriptor edge_descriptor;
   typedef typename graph_traits<Graph>::vertices_size_type size_type;
   size_type n = is_default_param(get_param(params, vertex_predecessor)) ?
     num_vertices(g) : 1;
   std::vector<edge_descriptor> pred_vec(n);
   
   typedef typename property_value< bgl_named_params<P,T,R>, vertex_color_t>::type C;
   return edmunds_karp_dispatch2<C>::apply
     (g, src, sink, 
      make_iterator_property_map(pred_vec.begin(), choose_const_pmap
                                 (get_param(params, vertex_index),
                                  g, vertex_index), pred_vec[0]),
      params, 
      get_param(params, vertex_color));
 }
Example #24
0
	void traverse( vertex_descriptor startingNode, DFSVisitor& visitor )
	{
//		try
//		{
			// Colors
			// @todo Could be optimize (don't reallocate this vector for each traverse call).
			std::vector< boost::default_color_type > colors( num_vertices(bglGraph()) );
			const boost::default_color_type c = boost::white_color;
			
			// Index Map
			typedef boost::property_map<detail::bglGraph, boost::vertex_index_t>::type IndexMap;
			IndexMap indexmap = boost::get(boost::vertex_index, bglGraph());

			// Initialize visitor
			visitor.initialize(	&getVertexNamePropertyMap(), &getEdgeNamePropertyMap() );
	
			// Depth first search
			vgd::visitor::internal::depth_first_search(
				bglGraph(),
				visitor,
	
				make_iterator_property_map(
					colors.begin(),
					indexmap,
					c ),
		
				startingNode
			 );
//		}
//		catch (vgd::visitor::HasCycle e)
//		{
//			throw e;
			// FIXME
			//return ( true );
//		}
	}
Example #25
0
static
depth findMaxWidth(const NGHolder &h, const SpecialEdgeFilter &filter,
                   NFAVertex src) {
    if (isLeafNode(src, h.g)) {
        return depth::unreachable();
    }

    if (hasReachableCycle(h, src)) {
        // There's a cycle reachable from this src, so we have inf width.
        return depth::infinity();
    }

    boost::filtered_graph<NFAGraph, SpecialEdgeFilter> g(h.g, filter);

    assert(hasCorrectlyNumberedVertices(h));
    const size_t num = num_vertices(h);
    vector<int> distance(num);
    vector<boost::default_color_type> colors(num);

    auto index_map = get(&NFAGraphVertexProps::index, g);

    // DAG shortest paths with negative edge weights.
    dag_shortest_paths(
        g, src,
        distance_map(make_iterator_property_map(distance.begin(), index_map))
            .weight_map(boost::make_constant_property<NFAEdge>(-1))
            .vertex_index_map(index_map)
            .color_map(make_iterator_property_map(colors.begin(), index_map)));

    depth acceptDepth, acceptEodDepth;
    if (colors.at(NODE_ACCEPT) == boost::white_color) {
        acceptDepth = depth::unreachable();
    } else {
        acceptDepth = -1 * distance.at(NODE_ACCEPT);
    }
    if (colors.at(NODE_ACCEPT_EOD) == boost::white_color) {
        acceptEodDepth = depth::unreachable();
    } else {
        acceptEodDepth = -1 * distance.at(NODE_ACCEPT_EOD);
    }

    depth d;
    if (acceptDepth.is_unreachable()) {
        d = acceptEodDepth;
    } else if (acceptEodDepth.is_unreachable()) {
        d = acceptDepth;
    } else {
        d = max(acceptDepth, acceptEodDepth);
    }

    if (d.is_unreachable()) {
        // If we're actually reachable, we'll have a min width, so we can
        // return infinity in this case.
        if (findMinWidth(h, filter, src).is_reachable()) {
            return depth::infinity();
        }
        return d;
    }

    // Invert sign and subtract one for start transition.
    assert(d.is_finite() && d > depth(0));
    return d - depth(1);
}
Example #26
0
 static type build(const Graph& g, const IndexMap& index, boost::scoped_array<Value>& array_holder) {
   array_holder.reset(new Value[num_vertices(g)]);
   std::fill(array_holder.get(), array_holder.get() + num_vertices(g), Value());
   return make_iterator_property_map(array_holder.get(), index);
 }
Example #27
0
 std::vector<typename graph_traits<VertexListGraph>::vertex_descriptor>
 smallest_last_vertex_ordering(const VertexListGraph& G) {
   std::vector<typename graph_traits<VertexListGraph>::vertex_descriptor> o(num_vertices(G));
   smallest_last_vertex_ordering(G, make_iterator_property_map(o.begin(), typed_identity_property_map<std::size_t>()));
   return o;
 }
 inline typename property_map<YASMIC_SIMPLE_CSR_GRAPH_TYPE, edge_weight_t>::const_type
 get(edge_weight_t, const YASMIC_SIMPLE_CSR_GRAPH_TYPE& g)
 {
     return make_iterator_property_map(g.a,get(edge_index,g));
 }