Boost logo

Boost Users :

Subject: Re: [Boost-users] [Graph] initialize_vertex change vertex color (visitor)
From: Alex (alexhighviz_at_[hidden])
Date: 2014-01-20 08:22:26


>> "Examine" seems to work once on first encounter (is that correct??) so
might worth a try.
>> I did try the code below but I got errors on the part the works with the
color map. Any ideas?

>> class dijkstra_2step : public boost::default_dijkstra_visitor
>> {
>>public:
>>    dijkstra_2step(std::vector<Weight> dists, double threshold):
distances(dists), threshold(threshold) {}
>>
>>    void examine_vertex(boost::graph_traits <unGraph>::vertex_descriptor
u, const unGraph& g){
>>       boost::property_map< unGraph, boost::vertex_color_t >::type
colorMap = boost::get(boost::vertex_color, g);
>>        if( distances[u] > threshold ) colorMap[u] =
boost::color_traits::black();
>>    }
>>    std::vector<Weight> distances;
>>    double threshold;
>>};

If I understand correctly, your distances vector is another one than the one
that the dijkstra_shortest_path is working on? Otherwise, it seems that this
visitor makes little sense. Upon examination the distance for all vertices
is distance_inf, because that is how they are initialized.

You may want to make better use of property maps for your visitor. Remember,
visitors are passed by value internally, you don't want to copy your
distance vector all the time. You will need to create your own color map and
pass it both to dijkstra_shortest_path and your visitor.

Beware that you cannot use the named parameter variation of
dijkstra_shortest_paths if you want to specify your own color map:
http://comments.gmane.org/gmane.comp.lib.boost.devel/206220

template<typename DistanceMap, typename ColorMap>
struct dijkstra2step : public boost::default_dijkstra_visitor
{
  typedef typename boost::property_traits<ColorMap>::value_type color_type;
  typedef typename boost::color_traits<color_type> color_traits;

  dijkstra2step(DistanceMap d, ColorMap c, double threshold) :
m_distance(d), m_color(c), m_threshold(threshold)
  {}

  template< typename G>
  void examine_vertex(typename boost::graph_traits<G>::vertex_descriptor u,
const G& g)
  {
    if(get(m_distance, u) > threshold) put(m_color, u,
color_traits::black());
  }
  ColorMap m_color;
  DistanceMap m_Distance;
};

Best, Alex


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