Anyone with Boost::Graph experience?
-
Hey everyone, I need a map class to represent the data in a sort of network class I'm making and I've been looking at Boost graph library for this. The one feature I really need is the ability to join two graphs together, by specifying a vetex from each that should be joined with an edge. Although Boost::mutable_graph looks close to what I want, I don't see how I can implement my join/union/addition operation in an efficient manner with the boost graph operations. Does anyone have experience with this problem and know of any potential solutions for it? Any suggestions for libraries that might work? I am going to check out the Graph Template Library and see if that might support this better. I could always make a graph structure that is optimized for my operation, but that would probably take more time than just finding something preexisting that just works. Any suggestions?
-
Hey everyone, I need a map class to represent the data in a sort of network class I'm making and I've been looking at Boost graph library for this. The one feature I really need is the ability to join two graphs together, by specifying a vetex from each that should be joined with an edge. Although Boost::mutable_graph looks close to what I want, I don't see how I can implement my join/union/addition operation in an efficient manner with the boost graph operations. Does anyone have experience with this problem and know of any potential solutions for it? Any suggestions for libraries that might work? I am going to check out the Graph Template Library and see if that might support this better. I could always make a graph structure that is optimized for my operation, but that would probably take more time than just finding something preexisting that just works. Any suggestions?
A rough guess: map1[0,1] = ? map1[0,2] = ? ... map2[0,1] = ? map2[0,2] = ? ... join(map1,map2); new_map1[0,1] = ? new_map1[0,2] = ? ... Possible Solution:
void shift_keys(map_type& map, map_type::size_type amt)
{
// create new map with adjusted keys
map_type new_map(map);
map_type::iterator mi = map.begin();
for( ; mi != map.end(); ++mi )
new_map[std:make_pair((mi->first).first+amt,(mi->first).second+amt)]
= mi->second;
map.swap(new_map);
}
vod join(map_type& map1,map_type& map2)
{
map_type new_map(map2)
shift_keys(map2,map1.size());
// join new_map to map1
map_type::iterator mi = new_map.begin();
for( ; mi != new_map.end(); ++mi )
map1[mi->first] = mi->second;
}This is an incomplete solution (off the top of my head). It should successfully join the two maps. Example: join(map1,map2); map1[0,1] = ? map1[0,2] = ? .. map1[2,3] = ? map1[2,4] = ? ... I hope that helps you figure out the problem. Maps allow only one entry per-key; therefore, you have to change any key values in map2 that may be the same as a key values in map1 before you attempt to join them. It may be more complicated than that, but I have essentially used simular code to join two maps. INTP "The more help VB provides VB programmers, the more miserable your life as a C++ programmer becomes." Andrew W. Troelsen