/* adjacency_matrix_test.cpp source file * * Copyright Cromwell D. Enage 2004 * * Permission to use, copy, modify, sell, and distribute this software * is hereby granted without fee provided that the above copyright notice * appears in all copies and that both that copyright notice and this * permission notice appear in supporting documentation, * * Cromwell D. Enage makes no representations about the suitability of this * software for any purpose. It is provided "as is" without express or * implied warranty. */ /* * Defines the std::ios class and std::cout, its global output instance. */ #include /* * Defines the boost::property_map class template and the boost::get and * boost::put function templates. */ #include /* * Defines the boost::graph_traits class template. */ #include /* * Defines the vertex and edge property tags. */ #include /* * Defines the boost::adjacency_list class template and its associated * non-member function templates. */ #include /* * Defines the boost::adjacency_matrix class template and its associated * non-member function templates. */ #include int main() { #if 1 typedef boost::adjacency_list Graph; #else typedef boost::adjacency_matrix Graph; #endif typedef boost::property_map::type IndexMap; Graph g(24); boost::add_edge(boost::vertex(0, g), boost::vertex(7, g), g); boost::add_edge(boost::vertex(1, g), boost::vertex(2, g), g); boost::add_edge(boost::vertex(2, g), boost::vertex(10, g), g); boost::add_edge(boost::vertex(2, g), boost::vertex(5, g), g); boost::add_edge(boost::vertex(3, g), boost::vertex(10, g), g); boost::add_edge(boost::vertex(3, g), boost::vertex(0, g), g); boost::add_edge(boost::vertex(4, g), boost::vertex(5, g), g); boost::add_edge(boost::vertex(4, g), boost::vertex(0, g), g); boost::add_edge(boost::vertex(5, g), boost::vertex(14, g), g); boost::add_edge(boost::vertex(6, g), boost::vertex(3, g), g); boost::add_edge(boost::vertex(7, g), boost::vertex(17, g), g); boost::add_edge(boost::vertex(7, g), boost::vertex(11, g), g); boost::add_edge(boost::vertex(8, g), boost::vertex(17, g), g); boost::add_edge(boost::vertex(8, g), boost::vertex(1, g), g); boost::add_edge(boost::vertex(9, g), boost::vertex(11, g), g); boost::add_edge(boost::vertex(9, g), boost::vertex(1, g), g); boost::add_edge(boost::vertex(10, g), boost::vertex(19, g), g); boost::add_edge(boost::vertex(10, g), boost::vertex(15, g), g); boost::add_edge(boost::vertex(10, g), boost::vertex(8, g), g); boost::add_edge(boost::vertex(11, g), boost::vertex(19, g), g); boost::add_edge(boost::vertex(11, g), boost::vertex(15, g), g); boost::add_edge(boost::vertex(11, g), boost::vertex(4, g), g); boost::add_edge(boost::vertex(12, g), boost::vertex(19, g), g); boost::add_edge(boost::vertex(12, g), boost::vertex(8, g), g); boost::add_edge(boost::vertex(12, g), boost::vertex(4, g), g); boost::add_edge(boost::vertex(13, g), boost::vertex(15, g), g); boost::add_edge(boost::vertex(13, g), boost::vertex(8, g), g); boost::add_edge(boost::vertex(13, g), boost::vertex(4, g), g); boost::add_edge(boost::vertex(14, g), boost::vertex(22, g), g); boost::add_edge(boost::vertex(14, g), boost::vertex(12, g), g); boost::add_edge(boost::vertex(15, g), boost::vertex(22, g), g); boost::add_edge(boost::vertex(15, g), boost::vertex(6, g), g); boost::add_edge(boost::vertex(16, g), boost::vertex(12, g), g); boost::add_edge(boost::vertex(16, g), boost::vertex(6, g), g); boost::add_edge(boost::vertex(17, g), boost::vertex(20, g), g); boost::add_edge(boost::vertex(18, g), boost::vertex(9, g), g); boost::add_edge(boost::vertex(19, g), boost::vertex(23, g), g); boost::add_edge(boost::vertex(19, g), boost::vertex(18, g), g); boost::add_edge(boost::vertex(20, g), boost::vertex(23, g), g); boost::add_edge(boost::vertex(20, g), boost::vertex(13, g), g); boost::add_edge(boost::vertex(21, g), boost::vertex(18, g), g); boost::add_edge(boost::vertex(21, g), boost::vertex(13, g), g); boost::add_edge(boost::vertex(22, g), boost::vertex(21, g), g); boost::add_edge(boost::vertex(23, g), boost::vertex(16, g), g); IndexMap index_map = boost::get(boost::vertex_index_t(), g); boost::graph_traits::vertex_iterator vi, vend; #if 0 boost::graph_traits::adjacency_iterator ai, aend; for (boost::tie(vi, vend) = boost::vertices(g); vi != vend; ++vi) { std::cout << " " << boost::get(index_map, *vi) << " ->"; for (boost::tie(ai, aend) = boost::adjacent_vertices(*vi, g); ai != aend; ++ai) { std::cout << " " << boost::get(index_map, *ai); } std::cout << std::endl; } #else boost::graph_traits::out_edge_iterator ei, eend; for (boost::tie(vi, vend) = boost::vertices(g); vi != vend; ++vi) { std::cout << " " << boost::get(index_map, *vi) << " ->"; for (boost::tie(ei, eend) = boost::out_edges(*vi, g); ei != eend; ++ei) { std::cout << " " << boost::get(index_map, boost::target(*ei, g)); } std::cout << std::endl; } #endif std::cout << std::endl; return 0; }