8 #ifndef BOOST_GRAPH_READ_DIMACS_GRAPH_HPP
9 #define BOOST_GRAPH_READ_DIMACS_GRAPH_HPP
18 #include <boost/graph/graph_traits.hpp>
26 Instance* read_dimacs_graph(std::istream& in,
const unsigned num_paths,
const unsigned num_cycles,
const unsigned num_objects){
27 const uint P_FIELDS = 2;
28 const uint E_FIELDS = 2;
29 unsigned no_lines = 0;
30 unsigned no_elines = 0;
31 unsigned num_vertices, num_edges;
33 Instance* I =
new Instance(num_paths, num_cycles, num_objects);
35 std::vector<ScafVertex> verts;
38 while(std::getline(in, in_line)) {
46 if(std::sscanf(in_line.c_str(),
"%*c %*s %u %u", &num_vertices, &num_edges) != P_FIELDS)
48 verts.reserve(num_vertices);
49 for(
unsigned vi = 0; vi < num_vertices; ++vi) verts.push_back(I->add_vertex(std::to_string(vi), vi));
53 if(no_elines >= num_edges)
throw except::bad_syntax(no_lines,
"too many edges specified or no p line found");
54 if(std::sscanf(in_line.c_str(),
"%*c %u %u", &u, &v) != E_FIELDS)
58 if((u < num_vertices) && (v < num_vertices)){
61 boost::tie(e, success) = I->add_edge(verts[u], verts[v]);
72 if ( no_elines < num_edges )
throw except::bad_syntax(no_lines,
"did not read enough edges");
74 std::cout <<
"Syntax error in line "<<ex.
line_no<<
": "<<ex.what()<<std::endl;
78 std::cout <<
"Error reading after "<<ex.
line_no<<
" lines: "<<ex.what()<<std::endl;
82 #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
const unsigned line_no
store the line number on which the exception ocurred
Definition: exceptions.hpp:47