Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] Searching for a convenient way to combine predicates for filtered_graph (SOLVED)
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2010-12-01 11:18:53


Hi,

in case someone might ask "Is it possible to create some sort of "nested"
combined predicates"? Or incrementally construct a predicate?

Actually, it is!

Let's say, we have got the positive_edge_weight predicate(functor) from the
filtered_graph example again and also the negative_edge_weight
predicate(functor).
Then we can do something like this:

  // HERE we define the type for our combined predicate
  typedef boost::function< bool( Edge ) > CombinedPred;
  // First predicate
  CombinedPred combined_pred = (boost::bind(pos_filter, _1) );
  // Second predicate
  combined_pred = boost::bind(combined_pred, _1) || boost::bind(neg_filter,
_1);

This would then _hide_ all the edges having an edge weight of zero of course.

This solution allows the arbitrary combination of predicates and also an
incremental construction of even more complex predicates. One scenario I could
think of is a vector (or any other container) of integers representing
edge_weights of interest.
Then the definion of a single predicate(functor) having a single integer as
argument, would be enough, using this approach, to create a predicate covering
_all_ the edge_weights of interest. Of course, one could also define a
predicate directly that takes this vector as an argument. But this would not
be very flexible IMHO.
However, I don't know which solution would perform better when being applied
to a filtered_graph. Maybe the overhead of all that binding would cost,
although I could imagine that going over the vector for each edge might also
cost something when compared to simply checking a combination of logical
operations.

Best,

Cedric


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