8 #ifndef BOOST_GRAPH_READ_ADJ_LIST_HPP
9 #define BOOST_GRAPH_READ_ADJ_LIST_HPP
25 Instance* read_adj_list(std::istream& in,
const unsigned num_paths,
const unsigned num_cycles,
const unsigned num_objects){
26 unsigned num_vertices = 0;
27 unsigned no_lines = 0;
29 Instance* I =
new Instance(num_paths, num_cycles, num_objects);
31 std::vector<ScafVertex> verts;
34 while(std::getline(in, in_line)) {
37 if(num_vertices == 0){
39 if(std::sscanf(in_line.c_str(),
"%u", &num_vertices) != 1)
throw except::bad_syntax(no_lines,
"failed to read #vertices");
40 verts.reserve(num_vertices);
41 for(
unsigned vi = 0; vi < num_vertices; ++vi) verts.push_back(I->add_vertex(std::to_string(vi), vi));
43 for(
unsigned vi = 0; vi < num_vertices; vi+=2)
44 I->add_matching_edge(verts[vi], verts[vi+1]);
55 while(!in_line.empty()) {
59 if(in_line.empty())
break;
65 if(in_line[0] ==
','){
73 I->add_edge(verts[u], verts[v], ScafEdgeProperty(weight, 0, 1,
""));
75 }
catch(std::invalid_argument ex){
85 std::cout <<
"Syntax error in line "<<ex.
line_no<<
": "<<ex.what()<<std::endl;
89 std::cout <<
"Error reading after "<<ex.
line_no<<
" lines: "<<ex.what()<<std::endl;
93 #warning TODO: support insert size and other information in DIMACS format
an exception for the case that a given file does not conform to expected syntax
Definition: exceptions.hpp:56
an exception for the case that a given file could not be read on a low level
Definition: exceptions.hpp:46
Definition: read_adj_list.hpp:22
Definition: read_phytree.hpp:10
long read_single_number(std::string &s)
consume an integer from the beginning of s and return it
Definition: string_utils.hpp:31
void skip_to(std::string &s, const std::string &skip_to)
remove all characters not in 'skip_to' from the beginning of s
Definition: string_utils.hpp:17
const unsigned line_no
store the line number on which the exception ocurred
Definition: exceptions.hpp:47