mirror of
https://github.com/boostorg/graph.git
synced 2026-01-31 08:12:14 +00:00
working on stlport debug port
[SVN r7815]
This commit is contained in:
@@ -86,30 +86,40 @@ int main(int argc, char* argv[])
|
||||
// color property needed in breadth-first search
|
||||
std::vector<default_color_type> color(num_vertices(G));
|
||||
|
||||
typedef boost::property_map<Graph, vertex_index>::type IndexMap;
|
||||
IndexMap vertex_id = get(vertex_index(), G);
|
||||
|
||||
// discover time property
|
||||
std::vector<size_type> dtime(num_vertices(G));
|
||||
|
||||
// finish time property
|
||||
std::vector<size_type> ftime(num_vertices(G));
|
||||
|
||||
typedef std::vector<size_type>::iterator RAIter;
|
||||
typedef random_access_iterator_property_map<RAIter, size_type,
|
||||
size_type&, IndexMap> IterMap;
|
||||
|
||||
IterMap discover(dtime.begin(), vertex_id);
|
||||
IterMap finish(ftime.begin(), vertex_id);
|
||||
|
||||
// Call the 4 argument version of BFS.
|
||||
// There is also a 3 argument version (assume color is in the graph)
|
||||
// and a 5 argument version (adds an argument for the queue).
|
||||
int time = 0;
|
||||
boost::breadth_first_search
|
||||
(G, vertex(s, G), make_bfs_visitor(
|
||||
std::make_pair(stamp_times(dtime.begin(), time, on_discover_vertex()),
|
||||
stamp_times(ftime.begin(), time, on_finish_vertex()))),
|
||||
color.begin());
|
||||
std::make_pair(stamp_times(discover, time, on_discover_vertex()),
|
||||
stamp_times(finish, time, on_finish_vertex()))),
|
||||
make_iterator_property_map(color.begin(), vertex_id, color[0]));
|
||||
|
||||
cout << "order of discovery: ";
|
||||
|
||||
// Perform some STL magic to order the vertices
|
||||
// according to their discover time
|
||||
vector<size_type> discover_order(N);
|
||||
std::vector<size_type> discover_order(N);
|
||||
iota(discover_order.begin(), discover_order.end(), 0);
|
||||
std::sort(discover_order.begin(), discover_order.end(),
|
||||
indirect_cmp<Iiter, std::less<size_type> >(dtime.begin()));
|
||||
indirect_cmp<IterMap, std::less<size_type> >(discover));
|
||||
|
||||
for (i = 0; i < N; ++i)
|
||||
cout << name[ discover_order[i] ] << " ";
|
||||
@@ -120,7 +130,7 @@ int main(int argc, char* argv[])
|
||||
vector<size_type> finish_order(N);
|
||||
iota(finish_order.begin(), finish_order.end(), 0);
|
||||
std::sort(finish_order.begin(), finish_order.end(),
|
||||
indirect_cmp<Iiter, std::less<size_type> >(ftime.begin()));
|
||||
indirect_cmp<IterMap, std::less<size_type> >(finish));
|
||||
|
||||
for (i = 0; i < N; ++i)
|
||||
cout << name[ finish_order[i] ] << " ";
|
||||
|
||||
@@ -117,7 +117,7 @@ struct edge_printer
|
||||
template <class T, class Graph>
|
||||
void operator()(T x, Graph& g) {
|
||||
m_os << "(" << get(m_pa, source(x, g)) << ","
|
||||
<< get(m_pa, target(x, g)) << ") ";
|
||||
<< get(m_pa, target(x, g)) << ") ";
|
||||
}
|
||||
PA m_pa;
|
||||
std::ostream& m_os;
|
||||
@@ -173,12 +173,14 @@ main(int argc, char* argv[])
|
||||
enum { a, b, c, d, e, f, g, N};
|
||||
|
||||
Graph G(N);
|
||||
boost::property_map<Graph, vertex_index>::type
|
||||
vertex_id = get(vertex_index(), G);
|
||||
|
||||
vector<weight_t> distance(N, numeric_limits<weight_t>::max());
|
||||
std::vector<weight_t> distance(N, numeric_limits<weight_t>::max());
|
||||
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
|
||||
vector<Vertex> parent(N);
|
||||
std::vector<Vertex> parent(N);
|
||||
|
||||
typedef pair<int,int> E;
|
||||
typedef std::pair<int,int> E;
|
||||
|
||||
E edges[] = { E(a,c), E(a,d),
|
||||
E(b,a), E(b,d),
|
||||
@@ -209,27 +211,32 @@ main(int argc, char* argv[])
|
||||
|
||||
boost::breadth_first_search
|
||||
(G, vertex(a, G), make_bfs_visitor(
|
||||
std::make_pair(write_property(name, cout_char, on_discover_vertex()),
|
||||
std::make_pair(write_property(distance.begin(), cout_int,
|
||||
on_discover_vertex()),
|
||||
std::make_pair(print_edge(name, std::cout, on_examine_edge()),
|
||||
std::make_pair(write_property(make_iterator_property_map(name, vertex_id, name[0]),
|
||||
cout_char, on_discover_vertex()),
|
||||
std::make_pair(write_property(make_iterator_property_map(distance.begin(), vertex_id, distance[0]),
|
||||
cout_int, on_discover_vertex()),
|
||||
std::make_pair(print_edge(make_iterator_property_map(name, vertex_id, name[0]),
|
||||
std::cout, on_examine_edge()),
|
||||
print_endl(std::cout, on_finish_vertex()
|
||||
))))));
|
||||
|
||||
dijkstra_shortest_paths(G, vertex(a, G), distance.begin(),
|
||||
dijkstra_shortest_paths(G, vertex(a, G),
|
||||
make_iterator_property_map(distance.begin(), vertex_id, distance[0]),
|
||||
make_ucs_visitor(std::make_pair(copy_graph(G_copy, on_examine_edge()),
|
||||
record_predecessors(parent.begin(),
|
||||
on_edge_relaxed()))));
|
||||
record_predecessors(make_iterator_property_map(parent.begin(), vertex_id, parent[0]),
|
||||
on_edge_relaxed()))));
|
||||
|
||||
cout << endl;
|
||||
cout << "Result:" << endl;
|
||||
breadth_first_search
|
||||
(G_copy, vertex(a, G_copy), make_bfs_visitor(
|
||||
std::make_pair(write_property(name, cout_char, on_discover_vertex()),
|
||||
std::make_pair(write_property(distance.begin(), cout_int,
|
||||
on_discover_vertex()),
|
||||
std::make_pair(print_edge(name, std::cout, on_examine_edge()),
|
||||
std::make_pair(write_property(make_iterator_property_map(name, vertex_id, name[0]),
|
||||
cout_char, on_discover_vertex()),
|
||||
std::make_pair(write_property(make_iterator_property_map(distance.begin(), vertex_id, distance[0]),
|
||||
cout_int, on_discover_vertex()),
|
||||
std::make_pair(print_edge(make_iterator_property_map(name, vertex_id, name[0]),
|
||||
std::cout, on_examine_edge()),
|
||||
print_endl(std::cout, on_finish_vertex()
|
||||
))))));
|
||||
))))));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -75,13 +75,16 @@ main(int argc, char* argv[])
|
||||
|
||||
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
|
||||
typedef boost::graph_traits<Graph>::vertices_size_type size_type;
|
||||
boost::property_map<Graph, vertex_index>::type
|
||||
vertex_id = get(vertex_index(), G);
|
||||
|
||||
std::vector<default_color_type> color(num_vertices(G));
|
||||
|
||||
std::cout << "DFS parenthesis:" << std::endl;
|
||||
depth_first_search(G, make_dfs_visitor(std::make_pair(open_paren(),
|
||||
close_paren())),
|
||||
color.begin());
|
||||
make_iterator_property_map(color.begin(),
|
||||
vertex_id, color[0]));
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,8 @@ main(int argc, char* argv[])
|
||||
|
||||
typedef boost::graph_traits<Graph>::vertex_descriptor Vertex;
|
||||
typedef boost::graph_traits<Graph>::vertices_size_type size_type;
|
||||
boost::property_map<Graph, vertex_index>::type
|
||||
vertex_id = get(vertex_index(), G);
|
||||
|
||||
std::vector<default_color_type> c(num_vertices(G));
|
||||
std::vector<size_type> d(num_vertices(G));
|
||||
@@ -107,14 +109,14 @@ main(int argc, char* argv[])
|
||||
std::make_pair(print_edge("back", on_back_edge()),
|
||||
print_edge("forward or cross", on_forward_or_cross_edge())
|
||||
))),
|
||||
c.begin());
|
||||
make_iterator_property_map(c.begin(), vertex_id, c[0]));
|
||||
|
||||
cout << endl << "BFS categorized directed graph" << endl;
|
||||
boost::breadth_first_search
|
||||
(G, vertex(0, G), make_bfs_visitor(
|
||||
std::make_pair(print_edge("tree", on_tree_edge()),
|
||||
print_edge("cycle", on_cycle_edge()))),
|
||||
c.begin());
|
||||
make_iterator_property_map(c.begin(), vertex_id, c[0]));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user