How to Use the Special Graph Constructor G ( int n, int e)The following program shows how to use the special constructor. In The data slots for the nodes and the edges are used as follows. Simply
define a The The lists of nodes and edges of G are randomly permuted in
#include <LEDA/graph/graph.h>
#include <LEDA/graph/graph_gen.h>
using namespace leda;
float node_array_time(const list<node>& LN, node_array<int>& na)
{
float t=used_time();
node v; forall(v,LN) na[v]=na[v]+4711;
t=used_time(t);
return t;
}
float edge_array_time(const list<edge>& LE, edge_array<int>& ea)
{
float t=used_time();
edge e; forall(e,LE) ea[e]=ea[e]+4711;
t=used_time(t);
return t;
}
int main()
{
int n_slots=2;
int e_slots=1;
graph G(n_slots,e_slots);
random_graph(G,50000,1000000);
list<node> LN=G.all_nodes();
LN.permute();
list<edge> LE=G.all_edges();
LE.permute();
node_array<int> n1;
n1.use_node_data(G,1); //node data slot
std::cout << "tn1=" << node_array_time(LN,n1) << std::endl;
node_array<int> n2;
n2.use_node_data(G,2); //node data slot
std::cout << "tn2=" << node_array_time(LN,n2) << std::endl;
node_array<int> n3;
n3.use_node_data(G,3); //standard node_array
std::cout << "tn3=" << node_array_time(LN,n3) << std::endl;
edge_array<int> e1;
e1.use_edge_data(G,1); //edge data slot
std::cout << "te1=" << edge_array_time(LE,e1) << std::endl;
edge_array<int> e2;
e2.use_edge_data(G,2); //standard edge_array
std::cout << "te2=" << edge_array_time(LE,e2) << std::endl;
return 0;
}
|
See also:Special Graph Constructor G(int n, int e) Associate Information with Graphs Manual Entries: |