//======================================================================= // Graph Connectives: Union // g1 and g2 are two graphs which are supposed to unite. // G is the union graph of (g1,g2) //======================================================================= #include #include #include #include #include #include "graph_union.hpp" using namespace boost; typedef adjacency_matrix <> adj_matrix; typedef adjacency_list <> adj_list; int main() { adj_matrix g1(5); // Graph 1. Size = 5 adj_list g2(5); // Graph 2. Size = 5 int union_size = num_vertices(g1) + num_vertices(g2); // Size of union graph adj_list G(union_size); // Union Graph. Size = 10 add_edge(0, 1, g1); add_edge(0, 2, g1); add_edge(0, 3, g2); add_edge(2, 3, g2); graph_union(g1, g2, G) ; // Print Graph G std::cout << "Graph Union : " << std::endl; graph_traits < adj_list >::vertex_iterator i, end; graph_traits < adj_list >::adjacency_iterator ai, a_end; property_map < adj_list, vertex_index_t >::type index_map = get(vertex_index, G); for (tie(i, end) = vertices(G); i != end; ++i) { tie(ai, a_end) = adjacent_vertices(*i, G); for (; ai != a_end; ++ai){ int source = get(index_map, *i) ; int target = get(index_map, *ai); std::cout << source << " " << target << std:: endl; } } return EXIT_SUCCESS; }