/*This program generates graphs that match the basic properties observed for the computational task graphs of stream processing systems. In these graphs, the vertices represent the kernels and the edges represent a continous data-stream movement from one kernel to another.*/ #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define SEED 135792468 class edge{ private: unsigned int src; unsigned int tgt; public: edge(unsigned int _source, unsigned int _target): src(_source),tgt(_target) {} unsigned int source() { return src;} unsigned int target() {return tgt;} void set_source(unsigned int _source) {src=_source;} }; class edgeWithWeight{ private: unsigned int src; unsigned int tgt; unsigned int src_label; double wgt; public: edgeWithWeight(unsigned int _source, unsigned int _target, unsigned int _source_label): src(_source),tgt(_target),src_label(_source_label) {} edgeWithWeight(unsigned int _source, unsigned int _target, double _wgt): src(_source),tgt(_target),wgt(_wgt) {} edgeWithWeight() {src=0;tgt=0;src_label=0;wgt=0;} double weight() {return wgt;} unsigned int source() { return src;} unsigned int target() {return tgt;} unsigned int source_label() {return src_label;} void set_weight(double _wgt) {wgt=_wgt;} void set_source_label(unsigned int _src_label) {src_label=_src_label;} }; bool edgeWithWeightLabel(edgeWithWeight e1, edgeWithWeight e2) { if(e1.source_label()e2.source_label()) return false; if(e1.source()e2.source()) return false; if(e1.target()e2.source()) return false; if(e1.target()e2.target()) return false; if(e1.source()e2.source()) return false; if(e1.target() &graph, vector& indegree, vector& outdegree) { outdegree.clear(); indegree.clear(); sort(graph.begin(),graph.end(),edgeSource); vector::iterator iter_ver = graph.begin(); for(int i =0;i & edge_vector_unique, vector & indegree,vector & longest_path) { //Recompute indegree sort(edge_vector_unique.begin(),edge_vector_unique.end(),edgeTarget); vector::iterator iter=edge_vector_unique.begin(); for(int i =0;i > neighb; iter=edge_vector_unique.begin(); for(int i=0;i i_neighb; while((iter!=edge_vector_unique.end())&&((*iter).source()==i)) { i_neighb.push_back((*iter).target()); ++iter; } neighb.push_back(i_neighb); } //cout<<"Neighbors pushed back"< sources; for(int i=0;i::iterator iter1 = neighb[v].begin();iter1!=neighb[v].end();++iter1) { int w = *iter1; if(longest_path[w].dgr, as undirected graph in .gr"< edge_vector; timeval tt; gettimeofday(&tt, NULL); // srandom(tt.tv_usec + tt.tv_sec*1000000); // changed to allow for reproducibility srandom(SEED); //First generate the core of the graph with O(n^{1/3}) vertices and O(n^{2/3}) edges //The vertices in this graph will later be divided into splits and joins. The filters will be added even later. int k=1; unsigned int n_nodes = ceil(2*k*pow(n,0.3333)); unsigned int m_edges = ceil(pow(n,0.6666)); //Part 1 of generating core //Generate series-parallel directed acyclic multi-graph unsigned int curr_n_nodes=2; unsigned int curr_edges = random()%(n_nodes/2-1)+1; for(int i=0;i indegree; vector outdegree; vector longest_path; compute_longest_paths(n_nodes,edge_vector,indegree,longest_path); //Add a random sequence of edges to the series-parallel core for(int i=0;i::iterator iter=edge_vector.begin(); vector add_edges; int n_nodes_fix=n_nodes; for(int i =0;i1)&&(outdegree[i]>1)) { while((iter!=edge_vector.end())&&((*iter).source()::iterator add_iter = add_edges.begin();add_iter!=add_edges.end();++add_iter) edge_vector.push_back(*add_iter); //cout<<"After adding the in to out edges"<::iterator iter1 = edge_vector.begin();iter1!=edge_vector.end();++iter1) { sum_edge_diff+=longest_path[(*iter1).target()]-longest_path[(*iter1).source()]; } sort(edge_vector.begin(),edge_vector.end(),edgeSource); // cout<<"sum_edge_diff = "<((*wgraph_iter).target(),e)); } if((indegree[curr_vertex]<=1)&&(outdegree[curr_vertex]>1)) { double w=1; //cout<<"w = "<20.0) make_int=20.0; for(wgraph_iter=graph.begin();wgraph_iter!=graph.end();++wgraph_iter) { double new_wgt = pow(2,make_int)*((*wgraph_iter).weight()); (*wgraph_iter).set_source_label(floor(new_wgt+0.5)); if((*wgraph_iter).source_label()==0) (*wgraph_iter).set_source_label(1); // cout<<(*wgraph_iter).weight()<<" "<<(*wgraph_iter).source_label()< "<<(*wgraph_iter).target(); dot_dir_graph_file< undGraph; wgraph_iter=graph.begin(); for(;wgraph_iter!=graph.end();++wgraph_iter) { undGraph.push_back(edgeWithWeight((*wgraph_iter).source(),(*wgraph_iter).target(),(*wgraph_iter).source_label())); undGraph.push_back(edgeWithWeight((*wgraph_iter).target(),(*wgraph_iter).source(),(*wgraph_iter).source_label())); ++m; } sort(graph.begin(),graph.end(),edgeWithWeightSource); //Output as Directed graph string dir_file_name = file_base+".dir.gr"; ofstream dir_graph_file; dir_graph_file.open(dir_file_name.c_str()); dir_graph_file<