0

I have gone through BGL documentation and I'm trying to construct a directed graph with the properties below. Even though the documentation mentions bits and pieces, I can't seem to understand how to achieve these properties collectively through BGL. The properties I'm looking for are:

  1. O(1) access to vertices with some integer/string as key
  2. O(I) access to incoming or outgoing edges where I is the number of incident edges, i.e. through an adjacency list (O(1) access to edges would be cool, as well, through some key)
  3. Able to change multiple edge properties, i.e. weight, id, attached Custom data struct
  4. Able to change multiple vertex properties, i.e. id, attached Custom data structures
  5. Add/Remove Vertices and Edges

Is there a way to construct a graph through BGL, with all of these properties? A code sample would be appreciated.

dev_nut
  • 2,476
  • 4
  • 29
  • 49
  • You don't want your cake and eat it, you want to eat it while it bakes it self anew, contuously. And sings the national anthem. You'll have to figure out your required trade-offs; there is no silver bullet. Even if you come up with a datastructure and adapt it to model the required Graph concept(s), it would just shift the inefficiencies to other operations (like insertion or update). – sehe Mar 31 '17 at 22:47
  • But why? I'm asking for O(1) access. Anything else can be O(V+E) or similar. – dev_nut Apr 01 '17 at 01:51
  • Of course. Complexity of graph algorithms didn't even come into your question at all. "I didn't ask for the pavement to be gold-plated, just the furniture!". You know, you could probably just create your own hashtable indexes that map ids to descriptors. This will tell you exactly the complexity overhead implied in maintaining the index. No BGL model does this (except _maybe_ `labeled_graph` for vertices). If you must, consider creating your own datastructure and make [it implement the graph concept.](http://www.boost.org/doc/libs/master/libs/graph/doc/graph_concepts.html) – sehe Apr 01 '17 at 09:43
  • I will try to extend BGL with some hashmaps (1 for vertex, 1 for edges, maybe more if needed), and try to add/remove entries from the hasmaps when vertices and edges are added/removed. I think that should do this, with the use of bundled properties. – dev_nut Apr 01 '17 at 18:41
  • I think so too. Part of this has "somewhat" been achieved in BGL, though undocumented: [`labeled_graph`](http://www.boost.org/doc/libs/1_63_0/boost/graph/labeled_graph.hpp). I happen to have posted a very simple answer that uses it earlier today: http://stackoverflow.com/questions/43114533/check-if-vertex-already-exists-before-an-add-edge-using-boost-graph-bgl/43155407#43155407 – sehe Apr 01 '17 at 18:47
  • Maybe this is another question, but I thought I was good with C++, until I came across BGL. Maybe it's because I don't use templates much. A lot of the make_iterator_property_map, property_traits, iterator_traits, etc. made me scratch my head. Is there something I can read to get better at boost, and C++. Any recommendations from you? I see that you answer most of the BGL questions. – dev_nut Apr 01 '17 at 18:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/139660/discussion-between-sehe-and-dev-nut). – sehe Apr 01 '17 at 18:57

0 Answers0