Algorithmic Solutions > LEDA > LEDA Guide > Graphs and Related Data Types > Sets of Edges > Example


Example Sets of Edges

The following example shows how a set of edges can be used.

First a random graph with 12 nodes and 15 edges is generated. Then an edge_set S is defined for G and all edges of G are inserted into S. The program iterates over all members of S and prints them. Finally, the member() function of S is illustrated. First S.member() is called for a random edge e of G. The result is true. Then S.member() is called for a new edge f of G. Here, the result is false. If f is inserted into S, then S.member(f) also returns true. If S.member() is called for an edge of another graph, the program terminates with an error message.

#include <LEDA/graph/graph.h>
#include <LEDA/graph/edge_set.h>

using namespace leda;

int main()
{
  graph G;
  random_graph(G,12,15);

  edge_set S(G);

  edge e;
  forall_edges(e,G) S.insert(e);

  forall(e,S) { G.print_edge(e); std::cout << std::endl; }
  std::cout << std::endl;

  e=G.choose_edge();
  G.print_edge(e);
  if (S.member(e)) std::cout << " is a member of S\n";
  else std::cout << " is no member of S\n";

  node v=G.choose_node();node w=G.choose_node();
  edge f=G.new_edge(v,w);
  G.print_edge(f);
  if (S.member(f)) cout << " is a member of S\n";
  else std::cout << " is no member of S\n";

  return 0;
}

See also:

Graph


Manual Entries:

Manual Page Sets of Edges

Iteration




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH