Esempio n. 1
0
void dumpG(graph_t * g, char *fname, int expMode)
{
    FILE *fp;

    fp = fopen(fname, "w");
    if (!fp) {
	fprintf(stderr, "Couldn not open %s \n", fname);
	exit(1);
    }
    outputGraph(g, fp, expMode);
    fclose(fp);
}
Esempio n. 2
0
void convert_pbbs2gr(const std::string& infilename, const std::string& outfilename) {
  typedef Galois::Graph::FirstGraph<uint32_t,EdgeTy,true> Graph;
  typedef typename Graph::GraphNode GNode;
  Graph graph;

  std::ifstream infile(infilename.c_str());
  std::string header;
  uint32_t nnodes;
  size_t nedges;

  infile >> header >> nnodes >> nedges;
  if (header != "AdjacencyGraph") {
    std::cerr << "Unknown file format\n";
    abort();
  }

  size_t* offsets = new size_t[nnodes];
  for (size_t i = 0; i < nnodes; ++i) {
    infile >> offsets[i];
  }

  size_t* edges = new size_t[nedges];
  for (size_t i = 0; i < nedges; ++i) {
    infile >> edges[i];
  }

  std::vector<GNode> nodes;
  nodes.resize(nnodes);
  for (uint32_t i = 0; i < nnodes; ++i) {
    GNode n = graph.createNode(i);
    graph.addNode(n);
    nodes[i] = n;
    graph.addNode(n, Galois::NONE);
  }

  for (uint32_t i = 0; i < nnodes; ++i) {
    size_t begin = offsets[i];
    size_t end = (i == nnodes - 1) ? nedges : offsets[i+1];
    GNode& src = nodes[i];
    for (size_t j = begin; j < end; ++j) {
      GNode& dst = nodes[edges[j]];
      graph.addEdge(src, dst);
    }
  }

  std::cout << "Finished reading graph. "
    << "Nodes: " << nnodes
    << " Edges read: " << nedges 
    << "\n";

  outputGraph(outfilename.c_str(), graph);
}
void dsmcGeneralBoundary::writeTimeData
(
    const fileName& pathName,
    const word& nameFile,
    const scalarField& xData,
    const scalarField& yData
)
{
    fileName writeFile(pathName/nameFile);

    graph outputGraph("title", "x", "y", xData, yData);

    outputGraph.write(writeFile, "raw");
}
Esempio n. 4
0
void convert_rmat2gr(const std::string& infilename, const std::string& outfilename) {
  typedef Galois::Graph::FirstGraph<uint32_t,int32_t,true> Graph;
  typedef Graph::GraphNode GNode;
  Graph graph;

  std::ifstream infile(infilename.c_str());

  // Skip to first non-comment line
  while (!infile.eof()) {
    if (infile.peek() != '%') {
      break;
    }
    infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  }

  uint32_t nnodes;
  size_t nedges;
  infile >> nnodes >> nedges;
  infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

  std::vector<GNode> nodes;
  nodes.resize(nnodes);
  for (uint32_t i = 0; i < nnodes; ++i) {
    GNode n = graph.createNode(i);
    graph.addNode(n);
    nodes[i] = n;
    graph.addNode(n, Galois::NONE);
  }

  for (size_t edge_num = 0; edge_num < nnodes; ++edge_num) {
    uint32_t cur_id;
    size_t cur_edges;
    infile >> cur_id >> cur_edges;
    if (cur_id >= nnodes) {
      std::cerr << "node id out of range: " << cur_id << "\n";
      abort();
    }
    // if (cur_edges < 0) {
    //   std::cerr << "num edges out of range: " << cur_edges << "\n";
    //   abort();
    // }
    
    for (size_t j = 0; j < cur_edges; ++j) {
      uint32_t neighbor_id;
      int32_t weight;
      infile >> neighbor_id >> weight;
      if (neighbor_id >= nnodes) {
        std::cerr << "neighbor id out of range: " << neighbor_id << "\n";
        abort();
      }
      GNode& src = nodes[cur_id];
      GNode& dst = nodes[neighbor_id];
      // replaces existing edge if it exists
      graph.getEdgeData(graph.addEdge(src, dst)) = weight;
    }

    infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  }

  infile.peek();
  if (!infile.eof()) {
    std::cerr << "additional lines in file\n";
    abort();
  }

  size_t edges_added = 0;
  for (Graph::iterator ii = graph.begin(), ei = graph.end(); ii != ei; ++ii) {
    edges_added += std::distance(graph.edge_begin(*ii), graph.edge_end(*ii));
  }

  std::cout << "Finished reading graph. "
    << "Nodes: " << nnodes
    << " Edges read: " << nedges 
    << " Edges added: " << edges_added
    << "\n";

  outputGraph(outfilename.c_str(), graph);
}
Esempio n. 5
0
void convert_dimacs2gr(const std::string& infilename, const std::string& outfilename) {
  typedef Galois::Graph::FirstGraph<uint32_t,int32_t,true> Graph;
  typedef Graph::GraphNode GNode;
  Graph graph;

  std::ifstream infile(infilename.c_str());

  while (!infile.eof()) {
    if (infile.peek() != 'c') {
      break;
    }
    infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  }

  if (infile.peek() != 'p') {
    std::cerr << "Missing problem specification line\n";
    abort();
  }

  std::string tmp;
  uint32_t nnodes;
  size_t nedges;
  infile >> tmp >> tmp >> nnodes >> nedges;
  infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

  std::vector<GNode> nodes;
  nodes.resize(nnodes);
  for (uint32_t i = 0; i < nnodes; ++i) {
    GNode n = graph.createNode(i);
    graph.addNode(n);
    nodes[i] = n;
    graph.addNode(n, Galois::NONE);
  }

  for (size_t edge_num = 0; edge_num < nedges; ++edge_num) {
    uint32_t cur_id, neighbor_id;
    int32_t weight;
    infile >> tmp;

    if (tmp.compare("a") != 0) {
      --edge_num;
      infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
      continue;
    }

    infile >> cur_id >> neighbor_id >> weight;
    if (cur_id == 0 || cur_id > nnodes) {
      std::cerr << "node id out of range: " << cur_id << "\n";
      abort();
    }
    if (neighbor_id == 0 || neighbor_id > nnodes) {
      std::cerr << "neighbor id out of range: " << neighbor_id << "\n";
      abort();
    }
    
    GNode& src = nodes[cur_id - 1]; // 1 indexed
    GNode& dst = nodes[neighbor_id - 1];
    // replaces existing edge if it exists
    graph.getEdgeData(graph.addEdge(src, dst)) = weight;

    infile.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
  }

  infile.peek();
  if (!infile.eof()) {
    std::cerr << "additional lines in file\n";
    abort();
  }

  size_t edges_added = 0;
  for (Graph::iterator ii = graph.begin(), ei = graph.end(); ii != ei; ++ii) {
    edges_added += std::distance(graph.edge_begin(*ii), graph.edge_end(*ii));
  }

  std::cout << "Finished reading graph. "
    << "Nodes: " << nnodes
    << " Edges read: " << nedges 
    << " Edges added: " << edges_added
    << "\n";

  outputGraph(outfilename.c_str(), graph);
}