Algorithmic Solutions > LEDA > LEDA Guide > Graphs and Related Data Types > Planar Maps > Example


Example Planar Maps

The following program shows how to use planar maps. First a bidirected planar graph G with four nodes and eight edges is generated. Then a planar_map M is generated from G. The program then iterates through all faces of M and prints the face and all edges bounding the face. Finally, two special operations on the planar map are performed.

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

using namespace leda;

int main()
{
  graph G;
 
  //create new nodes of G
  node v0=G.new_node();   
  node v1=G.new_node();
  node v2=G.new_node();
  node v3=G.new_node();

  //create new edges
  G.new_edge(v0,v1);G.new_edge(v1,v0);
  G.new_edge(v1,v2);G.new_edge(v2,v1);
  G.new_edge(v2,v3);G.new_edge(v3,v2);
  G.new_edge(v3,v0);G.new_edge(v0,v3);

  planar_map M(G);      //create planar_map from G
  
  face f;
  forall_faces(f,M) {   //iterate through all faces of M
    M.print_face(f); cout << endl;

    edge e;
    forall_face_edges(e,f) {
      M.print_edge(e); 
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }
  
  //split f into triangles by inserting new node u 
  //and connecting it to all nodes of f. 
  f=M.first_face();
  node u=M.new_node(f);  
  M.print();

  //delete e1 and its reversal from M. The two faces 
  //adjacent to e1 are united to one new face
  edge e1=M.first_edge(); 
  M.del_edge(e1);         
  M.print();

  return 0;
}

See also:

Manual Entries:

Manual Page Planar Maps

Iteration




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