From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/graph/example/graphviz.cpp | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/boost/libs/graph/example/graphviz.cpp (limited to 'src/boost/libs/graph/example/graphviz.cpp') diff --git a/src/boost/libs/graph/example/graphviz.cpp b/src/boost/libs/graph/example/graphviz.cpp new file mode 100644 index 00000000..4e357aeb --- /dev/null +++ b/src/boost/libs/graph/example/graphviz.cpp @@ -0,0 +1,79 @@ +// Copyright 2005 Trustees of Indiana University + +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Author: Douglas Gregor +#include +#include +#include +#include +#include +#include + +using namespace boost; + +typedef boost::adjacency_list, + property > Digraph; + +typedef boost::adjacency_list, + property > Graph; + +void test_graph_read_write(const std::string& filename) +{ + std::ifstream in(filename.c_str()); + BOOST_REQUIRE(in); + + Graph g; + dynamic_properties dp; + dp.property("id", get(vertex_name, g)); + dp.property("weight", get(edge_weight, g)); + BOOST_CHECK(read_graphviz(in, g, dp, "id")); + + BOOST_CHECK(num_vertices(g) == 4); + BOOST_CHECK(num_edges(g) == 4); + + typedef graph_traits::vertex_descriptor Vertex; + + std::map name_to_vertex; + BGL_FORALL_VERTICES(v, g, Graph) + name_to_vertex[get(vertex_name, g, v)] = v; + + // Check vertices + BOOST_CHECK(name_to_vertex.find("0") != name_to_vertex.end()); + BOOST_CHECK(name_to_vertex.find("1") != name_to_vertex.end()); + BOOST_CHECK(name_to_vertex.find("foo") != name_to_vertex.end()); + BOOST_CHECK(name_to_vertex.find("bar") != name_to_vertex.end()); + + // Check edges + BOOST_CHECK(edge(name_to_vertex["0"], name_to_vertex["1"], g).second); + BOOST_CHECK(edge(name_to_vertex["1"], name_to_vertex["foo"], g).second); + BOOST_CHECK(edge(name_to_vertex["foo"], name_to_vertex["bar"], g).second); + BOOST_CHECK(edge(name_to_vertex["1"], name_to_vertex["bar"], g).second); + + BOOST_CHECK(get(edge_weight, g, + edge(name_to_vertex["0"], name_to_vertex["1"], g).first) + == 3.14159); + BOOST_CHECK(get(edge_weight, g, + edge(name_to_vertex["1"], name_to_vertex["foo"], g).first) + == 2.71828); + BOOST_CHECK(get(edge_weight, g, + edge(name_to_vertex["foo"], name_to_vertex["bar"], g).first) + == 10.0); + BOOST_CHECK(get(edge_weight, g, + edge(name_to_vertex["1"], name_to_vertex["bar"], g).first) + == 10.0); + + // Write out the graph + write_graphviz_dp(std::cout, g, dp, std::string("id")); +} + +int test_main(int argc, char* argv[]) +{ + test_graph_read_write(argc >= 2 ? argv[1] : "graphviz_example.dot"); + + return 0; +} -- cgit v1.2.3