mirror of
https://github.com/boostorg/graph.git
synced 2025-05-11 13:24:01 +00:00
finished 1st draft
[SVN r8964]
This commit is contained in:
parent
f00f096e69
commit
accc191da3
61
test/dfs.cpp
61
test/dfs.cpp
@ -5,6 +5,7 @@
|
||||
|
||||
#include <boost/graph/depth_first_search.hpp>
|
||||
#include <boost/graph/adjacency_list.hpp>
|
||||
#include <boost/graph/graph_archetypes.hpp>
|
||||
#include "generate_random_graph.hpp"
|
||||
|
||||
template <typename ColorMap, typename ParentMap,
|
||||
@ -14,10 +15,10 @@ class dfs_test_visitor {
|
||||
typedef typename boost::color_traits<ColorValue> Color;
|
||||
public:
|
||||
dfs_test_visitor(ColorMap color, ParentMap p, DiscoverTimeMap d,
|
||||
FinishTimeMap f)
|
||||
FinishTimeMap f)
|
||||
: m_color(color), m_parent(p),
|
||||
m_discover_time(d), m_finish_time(f), m_time(0) { }
|
||||
|
||||
|
||||
template <class Vertex, class Graph>
|
||||
void initialize_vertex(Vertex u, Graph& g) {
|
||||
BOOST_TEST_VERIFY( get(m_color, u) == Color::white() );
|
||||
@ -70,8 +71,24 @@ private:
|
||||
|
||||
int test_main(int argc, char* argv[])
|
||||
{
|
||||
if (0) { // compile only
|
||||
// Check boost::depth_first_search() version 1 requirements with archetypes
|
||||
typedef boost::default_constructible_archetype<
|
||||
boost::sgi_assignable_archetype<
|
||||
boost::equality_comparable_archetype<> > > Vertex;
|
||||
typedef boost::vertex_list_graph_archetype<Vertex, boost::directed_tag,
|
||||
boost::allow_parallel_edge_tag > VLGraph;
|
||||
typedef boost::property_graph_archetype<VLGraph, boost::vertex_color_t,
|
||||
boost::color_value_archetype> PGraph;
|
||||
PGraph g_arch1;
|
||||
boost::depth_first_search(g_arch1, boost::dfs_visitor<>());
|
||||
|
||||
// remember to add concept archetype checks...
|
||||
// Check boost::depth_first_search() version 2 requirements with archetypes
|
||||
VLGraph g_arch2;
|
||||
typedef boost::read_write_property_map_archetype<Vertex,
|
||||
boost::color_value_archetype > color_map;
|
||||
boost::depth_first_search(g_arch2, boost::dfs_visitor<>(), color_map());
|
||||
}
|
||||
|
||||
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,
|
||||
boost::property<boost::vertex_color_t, boost::default_color_type> > Graph;
|
||||
@ -97,37 +114,37 @@ int test_main(int argc, char* argv[])
|
||||
ColorMap color = get(boost::vertex_color, g);
|
||||
std::vector<vertex_descriptor> parent(num_vertices(g));
|
||||
for (k = 0; k < num_vertices(g); ++k)
|
||||
parent[k] = k;
|
||||
parent[k] = k;
|
||||
std::vector<int> discover_time(num_vertices(g)),
|
||||
finish_time(num_vertices(g));
|
||||
finish_time(num_vertices(g));
|
||||
|
||||
dfs_test_visitor<ColorMap, vertex_descriptor*,
|
||||
int*, int*> visitor(color, &parent[0],
|
||||
&discover_time[0], &finish_time[0]);
|
||||
int*, int*> visitor(color, &parent[0],
|
||||
&discover_time[0], &finish_time[0]);
|
||||
|
||||
boost::depth_first_search(g, visitor);
|
||||
|
||||
// all vertices should be black
|
||||
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
|
||||
BOOST_TEST_VERIFY(get(color, *vi) == Color::black());
|
||||
BOOST_TEST_VERIFY(get(color, *vi) == Color::black());
|
||||
|
||||
// check parenthesis structure of discover/finish times
|
||||
// See CLR p.480
|
||||
for (boost::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui)
|
||||
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
|
||||
vertex_descriptor u = *ui, v = *vi;
|
||||
if (u != v) {
|
||||
BOOST_TEST_VERIFY( finish_time[u] < discover_time[v]
|
||||
|| finish_time[v] < discover_time[u]
|
||||
|| (discover_time[v] < discover_time[u]
|
||||
&& finish_time[u] < finish_time[v]
|
||||
&& boost::is_descendant(u, v, &parent[0]))
|
||||
|| (discover_time[u] < discover_time[v]
|
||||
&& finish_time[v] < finish_time[u]
|
||||
&& boost::is_descendant(v, u, &parent[0]))
|
||||
);
|
||||
}
|
||||
}
|
||||
for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
|
||||
vertex_descriptor u = *ui, v = *vi;
|
||||
if (u != v) {
|
||||
BOOST_TEST_VERIFY( finish_time[u] < discover_time[v]
|
||||
|| finish_time[v] < discover_time[u]
|
||||
|| (discover_time[v] < discover_time[u]
|
||||
&& finish_time[u] < finish_time[v]
|
||||
&& boost::is_descendant(u, v, &parent[0]))
|
||||
|| (discover_time[u] < discover_time[v]
|
||||
&& finish_time[v] < finish_time[u]
|
||||
&& boost::is_descendant(v, u, &parent[0]))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user