Next Up Previous Contents

2 Nodes

Nodes

Now that we are able to create nodes and edges the question arises what to do with them. As seen above two nodes n1 and n2 are needed to create a new edge e. It is important to keep in mind that there aren't any restrictions, except that the two nodes are valid (i.e. not node()) and that both are members of the same graph G, of course. This means that selfloops like

   G.new_edge(n, n);
as well as multi-edges, e.g.
   G.new_edge(n1, n2);
   G.new_edge(n1, n2);
are supported.

The most common thing to do with some node in applications using graphs is to traverse its neighbors or perhaps the edges incident to it. Since GTL ist based on the STL, it uses the STL iterator concept. In detail the following bidirectional iterators are provided:

Please note that the notion of adjacency depends on wether the graph is directed or not, i.e. in a directed graph the adjacent edges are the outgoing edges whereas in an undirected graph both the outgoing and the incmoing edges are considered.

Suppose having some graph G with some node n the following loop can be used to perform a certain action on all adjacent nodes of n:

    ...

   node::adj_nodes_iterator it = n.adj_nodes_begin();
   node::adj_nodes_iterator end = n.adj_nodes_end();

   while(it != end) {
      //
      // some action on *it, which is the actual node in iteration
      //

     ++it;
   }

   ...
The other iterators are used similarly.

Another concept commonly found in graph theory is the degree of a node. Thus given a node n calling n.indeg() or n.outdeg() returns the number of incoming or outgoing edges resp. In addition n.degree() returns the sum of these two.


Next Up Previous Contents