converters/metis.cpp
// This function will most likely be purged from future versions of Vite
This function will most likely be purged from future versions of Vite
This function will most likely be purged from future versions of Vite
void loadMetisFile(Graph *&g, const std::string &fileName, Weight_t wtype)
{
  std::ifstream ifs;
  ifs.open(fileName.c_str());
  if (!ifs) {
    std::cerr << "Error opening Metis format file: " << fileName << std::endl;
    exit(EXIT_FAILURE);
  }
  std::string line;
  char comment;
  do {
    std::getline(ifs, line);
    comment = line[0];
  } while (comment == '%');
  GraphElem numVertices, numEdges, value = 0L;
  {
    std::istringstream iss(line);
    iss >> numVertices >> numEdges;
    if (!iss.eof())
      iss >> value;
  }
  numEdges *= 2; 
  std::cout << "Loading Metis file: " << fileName << ", numvertices: " << numVertices <<
    ", numEdges: " << numEdges << std::endl;
  g = new Graph(numVertices, numEdges);
  GraphElem edgePos = 0;
  g->setEdgeStartForVertex(0, 0);
  switch (value) {
  case 10:
    std::cout << "Metis format vertex weights ignored" << std::endl;
  case 0: 
    for (GraphElem i = 0; i < numVertices; i++) {
      GraphElem j = 0L, neighbor, oldNeighbor=-1;
      std::getline(ifs, line);
      std::istringstream iss(line);
      while (!iss.eof()) {
        iss >> neighbor;
      	if (!iss || iss.eof())
	        break;
        GraphWeight weight;
        oldNeighbor = neighbor;
      	j++;
      	Edge &edge = g->getEdge(edgePos);
        edge.tail = neighbor - 1;
        if (wtype == ONE_WEIGHT)
            weight = 1.0;
        if (wtype == RND_WEIGHT)
            weight = genRandom(RANDOM_MIN_WEIGHT, RANDOM_MAX_WEIGHT);
        edge.weight = weight;
	edgePos++;
      }
      g->setEdgeStartForVertex(i + 1L, edgePos);
    }
    break;
  case 11:
    std::cout << "Metis format vertex weights ignored" << std::endl;
  case 1:
    for (GraphElem i = 0; i < numVertices; i++) {
      GraphElem j = 0, neighbor;
      GraphWeight weight;
      std::getline(ifs, line);
      std::istringstream iss(line);
      while (!iss.eof()) {
	iss >> neighbor >> weight;
	if (!iss || iss.eof())
	  break;
        if (wtype == ONE_WEIGHT)
            weight = 1.0;
        if (wtype == RND_WEIGHT)
            weight = genRandom(RANDOM_MIN_WEIGHT, RANDOM_MAX_WEIGHT);
        if (wtype == ABS_WEIGHT)
            weight = std::fabs(weight);
	j++;
	Edge &edge = g->getEdge(edgePos);
	edge.tail = neighbor - 1;
	edge.weight = weight;
	edgePos++;
      }
      g->setEdgeStartForVertex(i + 1, edgePos);
    }
    break;
  default:
    std::cerr << "Inconsistent value for weight flag in Metis format: " << value << std::endl;
    exit(EXIT_FAILURE);
  }
  ifs.close();
}
void loadMetisFile ( Graph * & g , const std :: string & fileName , Weight_t wtype ) { std :: ifstream ifs ; ifs . open ( fileName . c_str ( ) ) ; if ( ! ifs ) { std :: cerr << " " << fileName << std :: endl ; exit ( EXIT_FAILURE ) ; } std :: string line ; char comment ; do { std :: getline ( ifs , line ) ; comment = line [ 0 ] ; } while ( comment == ' ' ) ; GraphElem numVertices , numEdges , value = 0L ; { std :: istringstream iss ( line ) ; iss >> numVertices >> numEdges ; if ( ! iss . eof ( ) ) iss >> value ; } numEdges *= 2 ; std :: cout << " " << fileName << " " << numVertices << " " << numEdges << std :: endl ; g = new Graph ( numVertices , numEdges ) ; GraphElem edgePos = 0 ; g -> setEdgeStartForVertex ( 0 , 0 ) ; switch ( value ) { case 10 : std :: cout << " " << std :: endl ; case 0 : for ( GraphElem i = 0 ; i < numVertices ; i ++ ) { GraphElem j = 0L , neighbor , oldNeighbor = -1 ; std :: getline ( ifs , line ) ; std :: istringstream iss ( line ) ; while ( ! iss . eof ( ) ) { iss >> neighbor ; if ( ! iss || iss . eof ( ) ) break ; GraphWeight weight ; oldNeighbor = neighbor ; j ++ ; Edge & edge = g -> getEdge ( edgePos ) ; edge . tail = neighbor - 1 ; if ( wtype == ONE_WEIGHT ) weight = 1.0 ; if ( wtype == RND_WEIGHT ) weight = genRandom ( RANDOM_MIN_WEIGHT , RANDOM_MAX_WEIGHT ) ; edge . weight = weight ; edgePos ++ ; } g -> setEdgeStartForVertex ( i + 1L , edgePos ) ; } break ; case 11 : std :: cout << " " << std :: endl ; case 1 : for ( GraphElem i = 0 ; i < numVertices ; i ++ ) { GraphElem j = 0 , neighbor ; GraphWeight weight ; std :: getline ( ifs , line ) ; std :: istringstream iss ( line ) ; while ( ! iss . eof ( ) ) { iss >> neighbor >> weight ; if ( ! iss || iss . eof ( ) ) break ; if ( wtype == ONE_WEIGHT ) weight = 1.0 ; if ( wtype == RND_WEIGHT ) weight = genRandom ( RANDOM_MIN_WEIGHT , RANDOM_MAX_WEIGHT ) ; if ( wtype == ABS_WEIGHT ) weight = std :: fabs ( weight ) ; j ++ ; Edge & edge = g -> getEdge ( edgePos ) ; edge . tail = neighbor - 1 ; edge . weight = weight ; edgePos ++ ; } g -> setEdgeStartForVertex ( i + 1 , edgePos ) ; } break ; default : std :: cerr << " " << value << std :: endl ; exit ( EXIT_FAILURE ) ; } ifs . close ( ) ; }
This function will most likely be purged from future versions of Vite
This function will most likely be purged from future versions of Vite
// Metis' edges are not directional // No weights in Metis file //          if((oldNeighbor == neighbor))