Exemple #1
0
static void makeGraph(GraphType &graph, double** input, int matrix_size) {
     
    std::vector<SGNode> nodes;
    nodes.resize(matrix_size); 
    for(int i = 0; i<matrix_size; i++){
		Node n; 
		n.id = i;
		SGNode node = graph.createNode(n);
		graph.addNode(node); 
		nodes[i] = node; 
	} 
	
	
	int numEdges = 0; 
	for(int i = 0; i<matrix_size; i++){
		SGNode src = nodes[i];
		for(int j = i; j<matrix_size; j++){
			if(input[i][j] != 0){
				typename GraphType::edge_iterator it = graph.addEdge(src, nodes[j], Galois::MethodFlag::NONE);
				graph.getEdgeData(it) = input[i][j];
				numEdges++;
			}
			
		}
	}
   
   //#if BORUVKA_DEBUG
   std::cout << "Final num edges " << numEdges << std::endl;
   //#endif
}
Exemple #2
0
Totals
sage_time_add_edge()
{
    // Insert vertices
    GraphType *g = new GraphType;
    start_deadman(2);
    while (!had_alarm && g->numberOfGraphNodes()<MAX_VERTICES)
        g->addNode(new SgGraphNode);

    // Build a list of vertices that we can index in constant time.
    std::vector<SgGraphNode*> vertices = sage_vertex_vector(g);

    // The actual test
    start_deadman(2);
    Sawyer::Stopwatch t;
    while (!had_alarm && g->numberOfGraphEdges()<MAX_EDGES) {
        SgGraphNode *v1 = sage_random_vertex(g, vertices);
        SgGraphNode *v2 = sage_random_vertex(g, vertices);
        g->addEdge(v1, v2);
    }
    t.stop();
    return report("add edge", sage_size(g), g->numberOfGraphEdges(), t, "edges/s");
}
Exemple #3
0
static void makeGraph(GraphType &graph, const char* input) {
   std::vector<SGNode> nodes;
   //Create local computation graph.
   typedef Galois::Graph::LC_CSR_Graph<Node, edgedata> InGraph;
   typedef InGraph::GraphNode InGNode;
   InGraph in_graph;
   //Read graph from file.
   Galois::Graph::readGraph(in_graph, input);
   std::cout << "Read " << in_graph.size() << " nodes\n";
   //A node and a int is an element.
   typedef std::pair<InGNode, edgedata> Element;
   //A vector of element is 'Elements'
   typedef std::vector<Element> Elements;
   //A vector of 'Elements' is a 'Map'
   typedef std::vector<Elements> Map;
   //'in_edges' is a vector of vector of pairs of nodes and int.
   Map edges(in_graph.size());
   //
   int numEdges = 0;
   // Extract edges from input graph
   for (InGraph::iterator src = in_graph.begin(), esrc = in_graph.end();
        src != esrc; ++src) {
      for (InGraph::edge_iterator
             dst = in_graph.edge_begin(*src, Galois::MethodFlag::NONE),
             edst = in_graph.edge_end(*src, Galois::MethodFlag::NONE);
           dst != edst; ++dst) {
         edgedata w = in_graph.getEdgeData(dst);
         Element e(*src, w);
         edges[in_graph.getEdgeDst(dst)].push_back(e);
         numEdges++;
      }
   }
   //#if BORUVKA_DEBUG
   std::cout<<"Number of edges "<<numEdges<<std::endl;
   //#endif
   // Create nodes in output graph
   nodes.resize(in_graph.size());
   int nodeID = 0;
   for (Map::iterator i = edges.begin(), ei = edges.end(); i != ei; ++i) {
      Node n;
      n.id = nodeID;
      assert(!n.seen);
      SGNode node = graph.createNode(n);
      graph.addNode(node);
      nodes[nodeID] = node;
      nodeID++;
   }

   int id = 0;
   numEdges = 0;
   for (Map::iterator i = edges.begin(), ei = edges.end(); i != ei; ++i) {
      SGNode src = nodes[id];
      for (Elements::iterator j = i->begin(), ej = i->end(); j != ej; ++j) {
         typename GraphType::edge_iterator
           it = graph.findEdge(src, nodes[j->first], Galois::MethodFlag::NONE);
         if ( it != graph.edge_end(src, Galois::MethodFlag::NONE) ) {
           assert(graph.getEdgeData(it) == j->second);
           continue;
         }
         it = graph.addEdge(src, nodes[j->first], Galois::MethodFlag::NONE);
         graph.getEdgeData(it) = j->second;
         numEdges++;
      }
      id++;
   }
   
   //#if BORUVKA_DEBUG
   std::cout << "Final num edges " << numEdges << std::endl;
   //#endif
}