Example Edge MapsThe following program shows how an #include <LEDA/graph/graph.h> #include <LEDA/graph/edge_map.h> using namespace leda; int main() { graph G; node v1=G.new_node(); node v2=G.new_node(); node v3=G.new_node(); edge e1=G.new_edge(v1,v2); edge e2=G.new_edge(v2,v3); edge e3=G.new_edge(v3,v1); edge_map<int> A(G,1); //define edge map A for G //and assign 1 to every edge std::cout << A[e1] << " " << A[e2] << " " << A[e3] << std::endl; //assign new values int i=0;edge e; forall_edges(e,G) { A[e]=i++; } std::cout << A[e1] << " " << A[e2] << " " << A[e3] << std::endl; //if new edges are generated for G, we need to make A //valid for the new edges edge e4=G.new_edge(v2,v1); A.init(G); std::cout << A[e1] << " " << A[e2] << " " << A[e3] << " " << A[e4] << std::endl; //outputs "1 1 1 1" return 0; } |
See also:Associate Information with Graphs Manual Entries: |