Skip to content
Snippets Groups Projects
Commit b9ddda3a authored by Lukas Garbas's avatar Lukas Garbas
Browse files

Changed code style

parent 51ebb0db
No related merge requests found
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
#include <gp-bnb/bnb.hpp> #include <gp-bnb/bnb.hpp>
#include <gp-bnb/graph.hpp> #include <gp-bnb/graph.hpp>
#include <gp-bnb/partition.hpp> #include <gp-bnb/partition.hpp>
#include <gp-bnb/MetisReader.hpp> #include <gp-bnb/metis_reader.hpp>
int main() { int main() {
// MetisReader example // MetisReader example
std::string graphFile = "../test/inputs/delaunay_n10.graph"; std::string graphFile = "../test/inputs/delaunay_n10.graph";
auto g = MetisReader().read(graphFile); auto g = metis_reader().read(graphFile);
std::cout << "Number of nodes: " << g.num_vertices() << std::endl; std::cout << "Number of nodes: " << g.num_vertices() << std::endl;
} }
......
#include <gp-bnb/metis_reader.hpp>
#include <stdexcept>
std::vector<unsigned int> parse_line(std::string& line) {
std::vector<unsigned int> adjacencies;
std::stringstream iss( line );
int node;
while ( iss >> node ) {
adjacencies.push_back( node );
}
return adjacencies;
}
graph metis_reader::read(std::string& path) {
std::ifstream graph_file(path);
std::pair<int, int> header;
std::vector<std::vector<unsigned int>> adjacencies;
int edge_counter = 0;
std::string line = "";
if (std::getline(graph_file, line)) {
// ignore comment lines
while (line[0] == '%')
std::getline(graph_file, line);
// read the header line
std::vector<unsigned int> first_line = parse_line(line);
header = std::make_pair(first_line[0], first_line[1]);
adjacencies.reserve(header.first);
std::cout << "Reading graph in Metis format ";
std::cout << "(n = " << header.first << ", m = " << header.second << ")" << std::endl;
while (getline(graph_file, line)) {
// ignore comment lines after the header
if (line[0] != '%') {
adjacencies.push_back(parse_line(line));
edge_counter += adjacencies.back().size();
}
}
}
if ( edge_counter / 2 != header.second )
puts("Reader Error: incorrect number of edges");
if ( adjacencies.size() != (unsigned int) header.first )
puts("Reader Error: incorrect number of nodes");
graph g = graph(adjacencies);
return g;
}
\ No newline at end of file
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <gp-bnb/graph.hpp>
#ifndef METISREADER_H_
#define METISREADER_H_
/** Reader for the METIS file format **/
class metis_reader {
public:
metis_reader() = default;
graph read(std::string& path);
};
#endif
\ No newline at end of file
...@@ -11,6 +11,8 @@ executable('gp-bnb', ...@@ -11,6 +11,8 @@ executable('gp-bnb',
'bnb/main.cpp', 'bnb/main.cpp',
'bnb/graph.cpp', 'bnb/graph.cpp',
'bnb/partition.cpp', 'bnb/partition.cpp',
'bnb/metis_reader.cpp',
'bnb/bnb.cpp',
include_directories: inc) include_directories: inc)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment