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


Example Parameterized Planar Maps

The following program shows how to use parameterized planar maps. First a bidirected parameterized planar GRAPH<string,int> G with four nodes and eight edges is generated. The nodes have a name of type string and the edges have a length of type int. Then a PLANAR_MAP<string,int,bool> M is generated from G. The program then iterates through all faces of M, assigns a value to the faces, and prints the face and all edges on 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<string,int> G;
 
  //create nodes of G
  node v0=G.new_node("Hamburg");   
  node v1=G.new_node("Rostock");
  node v2=G.new_node("Cottbus");
  node v3=G.new_node("Dresden");

  //create edges with length
  G.new_edge(v0,v1,5);G.new_edge(v1,v0,5);
  G.new_edge(v1,v2,7);G.new_edge(v2,v1,7);
  G.new_edge(v2,v3,10);G.new_edge(v3,v2,10);
  G.new_edge(v3,v0,14);G.new_edge(v0,v3,14);

  PLANAR_MAP<string,int,bool> M(G);      //create PLANAR_MAP from G
  
  face f;
  forall_faces(f,M) {   //iterate through all faces of M
    if (M.size(f)>3) M[f]=true;  //assign true if f bounded by >3 edges
    else M[f]=false;             //false otherwise

    M.print_face(f); 
    std::cout << std::endl;

    edge e;
    forall_face_edges(e,f) {
      M.print_edge(e); 
      std::cout << std::endl;
      
      std::cout << "The distance from " 
                << M[M.source(e)] << " to "
                << M[M.target(e)] << " is " 
                << M[e] << " km\n";
    }

    std::cout << std::endl;
  }
  
  //splits 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,"saarbrücken"); 
  M.print();

  //deletes 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:

Parameterized Graphs

How to Associate Information with graphs


Manual Entries:

Manual Page Parameterized Planar Maps

Iteration




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