Algorithmic Solutions > LEDA > LEDA Guide > Graphs and Related Data Types > Associate Information with Graphs > Face Arrays > Example

Example Face Arrays

The following program shows how an face_array can be used. First a graph G with three nodes and six edges is defined. A face_array can only be used for a planar map. Therefore, we set the reversal edge information for every edge of G by calling G.make_map() and compute a planar embedding with G.compute_faces(). Afterwards, we can define a face_array A of type int. The default value for A is 1. We output the values of A for the two faces of G. Finally, we assign new values to the faces and output the result.

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

using namespace leda;

int main()
{
  graph G;
  node v1=G.new_node();
  node v2=G.new_node();
  node v3=G.new_node();
  G.new_edge(v1,v2);G.new_edge(v2,v1);
  G.new_edge(v2,v3);G.new_edge(v3,v2);
  G.new_edge(v3,v1);G.new_edge(v1,v3);

  G.make_map(); //sets reversal information for every edge
  G.compute_faces();  //computes faces of G
  
  face_array<int> A(G,1);  //define edge array A for G
                           //and assign 1 to every edge
  face f;
  forall_faces(f,G) std::cout << A[f] << " ";
  std::cout << std::endl;

  //assign new values
  int i=2;
  forall_faces(f,G) A[f]=i++; 

  forall_faces(f,G) cout << A[f] << " ";
  std::cout << std::endl;

  return 0;
}    

See also:

Face Arrays

Graphs and Related Data Types

Associate Information with Graphs


Manual Entries:

Manual Page Face Arrays

User Defined Parameter Types




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