Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. template <typename EdgeWeightMap>
  2. struct non_null_weight_edge {
  3.  
  4. non_null_weight_edge() {}
  5. non_null_weight_edge(EdgeWeightMap const& map) : weight_map(map) {}
  6.  
  7. template <typename Edge>
  8. bool operator()(Edge const& e) const {
  9. return (boost::get(weight_map, e) != 0);
  10. }
  11.  
  12. private:
  13. EdgeWeightMap weight_map;
  14. };
  15.  
  16. // Just for clarity's sake while printing graph
  17. struct VertexProperty {
  18. std::string name;
  19. };
  20.  
  21. struct EdgeProperty {
  22. int weight; // Required
  23. // Add whatever you want...
  24. };
  25. using RawGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
  26. VertexProperty, EdgeProperty>;
  27.  
  28. RawGraph graph; // Populate it however you want...
  29. auto weight_map = boost::get(graph, &EdgeProperty::weight);
  30. auto predicate = non_null_weight_edge<decltype(weight_map)>(weight_map);
  31.  
  32. boost::filtered_graph<RawGraph, decltype(predicate)>(graph, predicate);
  33.  
  34. template <typename VertexDesc, typename VertexAllocator = std::allocator<Vertex>>
  35. struct VertexDetectorVisitor : boost::default_bfs_visitor {
  36.  
  37. VertexDetectorVisitor(std::vector<VertexDesc, VertexAllocator>& output_vec) :
  38. visited(output_vec) {}
  39.  
  40. template <typename Vertex, typename Graph>
  41. void discover_vertex(Vertex const& v, Graph const& g) {
  42. visited.push_back(v);
  43. }
  44. private:
  45. std::vector<VertexDesc, VertexAllocator>& visited;
  46. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement