Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Anyone with Boost::Graph experience?

Anyone with Boost::Graph experience?

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmindata-structureshelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nathan Addy
    wrote on last edited by
    #1

    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?

    J 1 Reply Last reply
    0
    • N Nathan Addy

      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?

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups