]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/graphviz.cpp
1 // Copyright 2005 Trustees of Indiana University
3 // Use, modification and distribution is subject to the Boost Software
4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 // Author: Douglas Gregor
8 #include <boost/graph/graphviz.hpp>
9 #include <boost/graph/adjacency_list.hpp>
10 #include <boost/test/minimal.hpp>
13 #include <boost/graph/iteration_macros.hpp>
15 using namespace boost
;
17 typedef boost::adjacency_list
< vecS
, vecS
, directedS
,
18 property
< vertex_name_t
, std::string
>, property
< edge_weight_t
, double > >
21 typedef boost::adjacency_list
< vecS
, vecS
, undirectedS
,
22 property
< vertex_name_t
, std::string
>, property
< edge_weight_t
, double > >
25 void test_graph_read_write(const std::string
& filename
)
27 std::ifstream
in(filename
.c_str());
31 dynamic_properties dp
;
32 dp
.property("id", get(vertex_name
, g
));
33 dp
.property("weight", get(edge_weight
, g
));
34 BOOST_CHECK(read_graphviz(in
, g
, dp
, "id"));
36 BOOST_CHECK(num_vertices(g
) == 4);
37 BOOST_CHECK(num_edges(g
) == 4);
39 typedef graph_traits
< Graph
>::vertex_descriptor Vertex
;
41 std::map
< std::string
, Vertex
> name_to_vertex
;
42 BGL_FORALL_VERTICES(v
, g
, Graph
)
43 name_to_vertex
[get(vertex_name
, g
, v
)] = v
;
46 BOOST_CHECK(name_to_vertex
.find("0") != name_to_vertex
.end());
47 BOOST_CHECK(name_to_vertex
.find("1") != name_to_vertex
.end());
48 BOOST_CHECK(name_to_vertex
.find("foo") != name_to_vertex
.end());
49 BOOST_CHECK(name_to_vertex
.find("bar") != name_to_vertex
.end());
52 BOOST_CHECK(edge(name_to_vertex
["0"], name_to_vertex
["1"], g
).second
);
53 BOOST_CHECK(edge(name_to_vertex
["1"], name_to_vertex
["foo"], g
).second
);
54 BOOST_CHECK(edge(name_to_vertex
["foo"], name_to_vertex
["bar"], g
).second
);
55 BOOST_CHECK(edge(name_to_vertex
["1"], name_to_vertex
["bar"], g
).second
);
57 BOOST_CHECK(get(edge_weight
, g
,
58 edge(name_to_vertex
["0"], name_to_vertex
["1"], g
).first
)
60 BOOST_CHECK(get(edge_weight
, g
,
61 edge(name_to_vertex
["1"], name_to_vertex
["foo"], g
).first
)
63 BOOST_CHECK(get(edge_weight
, g
,
64 edge(name_to_vertex
["foo"], name_to_vertex
["bar"], g
).first
)
66 BOOST_CHECK(get(edge_weight
, g
,
67 edge(name_to_vertex
["1"], name_to_vertex
["bar"], g
).first
)
70 // Write out the graph
71 write_graphviz_dp(std::cout
, g
, dp
, std::string("id"));
74 int test_main(int argc
, char* argv
[])
76 test_graph_read_write(argc
>= 2 ? argv
[1] : "graphviz_example.dot");