// (organize by Robinkin from Devonit)
#include
#include
#include
#include
#include
USING NAMESPACE BOOST;
Template
TypedEf TypeName Property_Traits
PUBLIC:
BFS_TIME_VISITOR (Timemap TMAP, T & T): M_TIMEMAP (TMAP), M_TIME (T) {}
Template
Void Discover_Vertex (Vertex U, Const Graph & G) Const
{
PUT (M_TIMEMAP, U, M_TIME ); // Access M_TIME plus 1 each time
}
TimeMap m_timemap;
T & M_TIME;
}
int
Main ()
{
USING NAMESPACE BOOST;
// Select the graph type we wish to us
Typedef adjacency_list
// set up the vertex ids and names
ENUM {R, S, T, U, V, W, X, Y, N};
Const char * name = "Rstuvwxy";
// Specify the Edges in the graph
Typedef std :: pair
E Edge_Array [] = {E (R, S), E (R, V), E (S, W), E (W, R), E (W, T),
E (w, x), e (x, t), e (t, u), e (x, y), e (u, y)
}
// Create the graph Object
Const int n_edges = sizeof (edge_array) / sizeof (e);
#if Defined (boost_msvc) && boost_msvc <= 1300
// VC HAS Trouble with the Edge Iterator Constructor
GRAPH_T G (N);
For (std :: size_t j = 0; j Add_edge (Edge_Array [J] .first, Edge_Array [J] .Second, G); #ELSE Typedef graph_traits GRAPH_T G (Edge_Array, Edge_Array n_edges, v_size_t (n)); // Constructive #ENDIF // typedefs Typedef graph_traits Typedef size * iiter; // a Vector to Hold The Discover Time Property for Each Vertex Std :: Vector Size Time = 0; BFS_TIME_VISITOR Breadth_First_Search (G, Vertex (S, G), Visitor (VIS)); // use std :: sort to order the vertices by their discover time Std :: Vector Integer_Range Std :: Copy (Range.begin (), Range.end (), Discover_Order.begin ()); Std :: Sort (discover_order.begin (), discover_order.end (), Indirect_cmp Std :: Cout << "Order of Discovery:"; For (int i = 0; i Std :: cout << name [discover_order [i]] << " Std :: cout << std :: endl; Return EXIT_SUCCESS; } // Output: Order of Discovery: S R w v T x u y