1

Why is edge_iterator not an integer_iterator like vertex_iterator? I am using undirected adjacency list with vectors to store both vertices and edges.

Curious
  • 152
  • 9

1 Answers1

2

Adjacency lists store a list of adjacencies.

That is, per vertex, it stores a list of adjacent vertices.

That means that vertices can be stored in a single container, but each vertex contains its own (separate) container of adjacencies ("other vertex references").

This should explain: there is no such thing as "the edge container", making it impossible to directly address the edges by index or as a single adjacent container.

Note there are other graph models (e.g. EdgeList concept, as modeled by edge_list)

sehe
  • 374,641
  • 47
  • 450
  • 633
  • Thanks a lot @sehe for the explanation. What put me off was something like this `boost::adjacency_list` where a vector is used as the container for edges. The BGL doc [here](http://www.boost.org/doc/libs/1_61_0/libs/graph/doc/using_adjacency_list.html) give more clarification - **The containers used for edge lists must either satisfy the requirements for Sequence or for AssociativeContainer** while **The container must model Sequence or RandomAccessContainer** for _VertexList_. – Curious Sep 21 '16 at 19:14
  • Thing is, the Edge container selector is used once per vertex :) Note this is /not/ required when modeling EdgeList, but it is the way adjacency_list<> is designed. – sehe Sep 21 '16 at 19:15
  • Apologize as this must be a newbie question, so for adjacency_list representation the edges are stored in a vector of vectors for something like this `boost::adjacency_list`? – Curious Sep 21 '16 at 19:22
  • Yes. In fact, it has two edge lists in that case (one for the normal edge and one for the reverse edge). In general it's cheaper to have undirected graphs than bidirectional ones if applicable. (If you like, implementation details here http://stackoverflow.com/a/25110137/85371) – sehe Sep 21 '16 at 19:29