Boost logo

Boost Users :

Subject: Re: [Boost-users] Graph: Trying to filter on custom properties
From: Amit Prakash Ambasta (amit.prakash.ambasta_at_[hidden])
Date: 2016-07-29 03:34:38


Hi Daniel,

Thanks for your response..

I modified the code wrt your example and it seems to work now!
http://dpaste.com/2H6QP2S

On Thu, Jul 28, 2016 at 11:00 PM Daniel Hofmann <daniel_at_[hidden]> wrote:

> Your get_filtered_graph function has to take a graph type and return a
> filtered graph type for your graph. Those two are not the same type.
>
> Here's an example signature for: graph in, filtered graph out.
>
> template <typename G, typename EdgePred>
> bgl::filtered_graph<G, EdgePred> filterd(G& g, EdgePred pred);
>
> And here is a small self contained example for filtered graphs:
>
> https://gist.github.com/daniel-j-h/ceb53abffa4b3cb3ab37
>
> Cheers,
> Daniel J H
>
> On 07/28/2016 04:55 PM, Amit Prakash Ambasta wrote:
> > How should I be writing the get_filtered_graph in a generic way?
> >
> > #include <map>
> > #include <string>
> > #include <vector>
> > #include <iostream>
> >
> > #include <boost/graph/adjacency_list.hpp>
> > #include <boost/property_map/property_map.hpp>
> > #include <boost/graph/filtered_graph.hpp>
> > #include <boost/graph/graph_utility.hpp>
> >
> > template <typename F> struct EdgeProperty {
> > F features;
> >
> > EdgeProperty() = default;
> >
> > EdgeProperty(const F& f) : features(f) {}
> > };
> >
> > template <typename EM, typename F>
> > struct filtered_edge {
> > F filters;
> > EM emap;
> >
> > filtered_edge() = default;
> > filtered_edge(EM emap_, F filters_) : emap(emap_), filters(filters_)
> {}
> >
> > template <typename E> bool operator()(const E& e) {
> > auto e_prop = get(emap, e);
> > auto e_feat = e_prop.features;
> >
> > for (auto it: e_feat) {
> > if (get(e_feat, it.first) != it.second) {
> > return false;
> > }
> > }
> > return true;
> > }
> > };
> >
> > template<typename G, typename F> G get_filtered_graph(G& g, F& filters) {
> > typedef filtered_edge<boost::property_map<G, EdgeProperty<F> >, F>
> > filter_fn;
> > filter_fn filter{get(&EdgeProperty<F>::features, g), filters};
> > boost::filtered_graph<G, filter_fn> fg(g, filter);
> > return fg;
> > }
> >
> > typedef std::map<std::string, int> dict;
> >
> > typedef boost::adjacency_list<
> > boost::vecS,
> > boost::vecS,
> > boost::directedS,
> > boost::no_property,
> > EdgeProperty<dict>
> >> Graph;
> >
> > Graph create_empty_graph() noexcept {
> > return {};
> > }
> >
> > int main() {
> > const char* name = "ABCDE";
> > auto g = create_empty_graph();
> > auto v0 = boost::add_vertex(g);
> > auto v1 = boost::add_vertex(g);
> > auto v2 = boost::add_vertex(g);
> >
> > dict d01;
> > d01["a"] = 1;
> >
> > dict d12;
> > d12["b"] = 1;
> >
> > dict fil;
> > fil["a"] = 1;
> >
> > auto ep01 = EdgeProperty<dict>{
> > dict{}
> > };
> > boost::add_edge(v0, v1, d01, g);
> > boost::add_edge(v1, v2, d12, g);
> >
> > std::cout << "Before filter" << std::endl;
> > boost::print_graph(g, name);
> > auto fg = get_filtered_graph(g, fil);
> >
> > std::cout << "After filter" << std::endl;
> > boost::print_graph(fg, name);
> >
> > Graph ga;
> > }
> >
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net