Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename EdgeWeightMap>
- struct non_null_weight_edge {
- non_null_weight_edge() {}
- non_null_weight_edge(EdgeWeightMap const& map) : weight_map(map) {}
- template <typename Edge>
- bool operator()(Edge const& e) const {
- return (boost::get(weight_map, e) != 0);
- }
- private:
- EdgeWeightMap weight_map;
- };
- // Just for clarity's sake while printing graph
- struct VertexProperty {
- std::string name;
- };
- struct EdgeProperty {
- int weight; // Required
- // Add whatever you want...
- };
- using RawGraph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS,
- VertexProperty, EdgeProperty>;
- RawGraph graph; // Populate it however you want...
- auto weight_map = boost::get(graph, &EdgeProperty::weight);
- auto predicate = non_null_weight_edge<decltype(weight_map)>(weight_map);
- boost::filtered_graph<RawGraph, decltype(predicate)>(graph, predicate);
- template <typename VertexDesc, typename VertexAllocator = std::allocator<Vertex>>
- struct VertexDetectorVisitor : boost::default_bfs_visitor {
- VertexDetectorVisitor(std::vector<VertexDesc, VertexAllocator>& output_vec) :
- visited(output_vec) {}
- template <typename Vertex, typename Graph>
- void discover_vertex(Vertex const& v, Graph const& g) {
- visited.push_back(v);
- }
- private:
- std::vector<VertexDesc, VertexAllocator>& visited;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement