|
Boost Users : |
From: Douglas Gregor (dgregor_at_[hidden])
Date: 2005-01-28 02:11:02
On Monday 17 January 2005 10:31 pm, Tony Juricic wrote:
> Has anybody created custom dijkstra_shortest_paths algorithm visitor for
> discover_vertex event?
We've used them quite often. Do you have a particular task in mind?
> Reshuffling the code (but at this point I hardly know what am I really
> doing) I got the following to compile:
>
> // define visitor for discover_vertex event
>
> template <class Vertex, class Tag>
> struct target_visitor
>
> : public default_dijkstra_visitor
>
> {
> target_visitor(Vertex u) : v(u) { }
>
> template <class Vertex, class Graph>
> void discover_vertex(Vertex u, Graph& g)
> {
> if ( u==v )
> assert(0);
> }
>
> private:
> Vertex v;
> };
>
> template <class Vertex, class Tag>
> target_visitor<Vertex, Tag>
> target_visit(Vertex u, Tag) {
> return target_visitor<Vertex, Tag>(u);
> }
>
>
> ...
> // call dijkstra_shortest_paths with custom visitor
> // parameters below are defined as in dijkstra-example.cpp
>
> dijkstra_shortest_paths(g, s,
> predecessor_map(&p[0]).distance_map(&d[0]).visitor(target_visit(D,
> on_discover_vertex())));
Looks good. You can actually omit the "Tag" template parameter (and all of the
places it's passed along), because it won't be used. Just writing the
discover_vertex function into the visitor is enough.
Doug
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