As mentioned above a new edge is created using
G.new_edge(n1, n2);for some graph G containing nodes n1 and n2, where neither the two nodes need to be distinct nor is it required that this edge is the only one connecting these nodes. Clearly by definition every edge is directed, though the graph can be made undirected, which means that it forgets about the direction. This shows that even for undirected graphs the notions source and target of an edge make sense. Given some edge e these can easily be obtained via e.source() and e.target() respectively.
Suppose one wants to count all the edges having the same source and target as some edge e in a given graph G:
... int num = 1; node::out_edges_iterator it = e.source().out_edges_begin(); node::out_edges_iterator end = e.source().out_edges_end(); while(it != end) { if((*it).target == e.target()) { // // *it and e have the same source and target. // ++num; } ++it; } ...
Sometimes it is convenient to use n.opposite(e) for some node n which must be either the source or the target of e. n.opposite(e) is then the ``other end'' of e, with respect to n.