Merging graphs using boost graph -


how add edge between 2 different graphs using boost graph library. have seen code merging/contracting 2 vertices, not want that. i want link end vertex of 1 graph starting vertex of graph , make 1 single graph. both graphs of same type.

please help...

first of all, have admit resulting graph single object. assume want of same type graph original 2 graphs g1 , g2. means have choice 1 of following: graph g = g1 + g2 or g1 += g2 (both choices in pseudo-code, of course).

in case, result contain copy of second graph, not "original" object of graph g2.

bgl provides function that, namely, function "copy_graph"

you can following

#include <boost/graph/adjacency_list.hpp> #include <boost/graph/copy.hpp>   typedef boost::adjacency_list<> graph; typedef graph::vertex_descriptor vertex_t;  void merging(graph & g1, vertex_t v_in_g1, const graph & g2, vertex_t u_in_g2) {     typedef boost::property_map<graph, boost::vertex_index_t>::type index_map_t;       //for simple adjacency_list<> type more efficient:     typedef boost::iterator_property_map<typename std::vector<vertex_t>::iterator,         index_map_t,vertex_t,vertex_t&> isomap;      //for more generic graphs, 1 can try  //typedef std::map<vertex_t, vertex_t> isomap;     isomap mapv;     boost::copy_graph( g2, g1, boost::orig_to_copy(mapv) ); //means g1 += g2      vertex_t u_in_g1 = mapv[u_in_g2];      boost::add_edge(v_in_g1, u_in_g1, g1); } 

see copy graph (adjacency_list) one


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -