Example Parameterized Planar MapsThe following program shows how to use parameterized planar maps. First
a bidirected parameterized planar #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(); 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:How to Associate Information with graphs Manual Entries: Page Parameterized Planar Maps |