Ticket #3416: quick_tour.cpp.patch
File quick_tour.cpp.patch, 2.5 KB (added by , 13 years ago) |
---|
-
libs/graph/example/quick_tour.cpp
18 18 using namespace boost; 19 19 20 20 template <class Graph> struct exercise_vertex { 21 exercise_vertex(Graph& g_ ) : g(g_) { }21 exercise_vertex(Graph& g_, const char name_[]) : g(g_),name(name_) { } 22 22 typedef typename graph_traits<Graph>::vertex_descriptor Vertex; 23 23 void operator()(const Vertex& v) const 24 24 { 25 25 using namespace boost; 26 26 typename property_map<Graph, vertex_index_t>::type 27 27 vertex_id = get(vertex_index, g); 28 std::cout << "vertex: " << get(vertex_id, v)<< std::endl;28 std::cout << "vertex: " << name[get(vertex_id, v)] << std::endl; 29 29 30 30 // Write out the outgoing edges 31 31 std::cout << "\tout-edges: "; … … 36 36 { 37 37 e = *out_i; 38 38 Vertex src = source(e, g), targ = target(e, g); 39 std::cout << "(" << get(vertex_id, src)40 << "," << get(vertex_id, targ)<< ") ";39 std::cout << "(" << name[get(vertex_id, src)] 40 << "," << name[get(vertex_id, targ)] << ") "; 41 41 } 42 42 std::cout << std::endl; 43 43 … … 48 48 { 49 49 e = *in_i; 50 50 Vertex src = source(e, g), targ = target(e, g); 51 std::cout << "(" << get(vertex_id, src)52 << "," << get(vertex_id, targ)<< ") ";51 std::cout << "(" << name[get(vertex_id, src)] 52 << "," << name[get(vertex_id, targ)] << ") "; 53 53 } 54 54 std::cout << std::endl; 55 55 … … 57 57 std::cout << "\tadjacent vertices: "; 58 58 typename graph_traits<Graph>::adjacency_iterator ai, ai_end; 59 59 for (tie(ai,ai_end) = adjacent_vertices(v, g); ai != ai_end; ++ai) 60 std::cout << get(vertex_id, *ai)<< " ";60 std::cout << name[get(vertex_id, *ai)] << " "; 61 61 std::cout << std::endl; 62 62 } 63 63 Graph& g; 64 const char *name; 64 65 }; 65 66 66 67 … … 73 74 // Make convenient labels for the vertices 74 75 enum { A, B, C, D, E, N }; 75 76 const int num_vertices = N; 76 const char * name= "ABCDE";77 const char name[] = "ABCDE"; 77 78 78 79 // writing out the edges in the graph 79 80 typedef std::pair<int,int> Edge; … … 120 121 std::cout << std::endl; 121 122 122 123 std::for_each(vertices(g).first, vertices(g).second, 123 exercise_vertex<Graph>(g ));124 exercise_vertex<Graph>(g, name)); 124 125 125 126 std::map<std::string,std::string> graph_attr, vertex_attr, edge_attr; 126 127 graph_attr["size"] = "3,3";