5.4. dimacs_graph_io.hpp¶
Full path: graph_canon/dimacs_graph_io.hpp
-
template<typename
Graph
>
voidwrite_dimacs_graph
(std::ostream &s, const Graph &g)¶ Write the given graph in DIMACS format (see
read_dimacs_format()
).The vertices must have indices, i.e., the expression
get(boost::verex_index_t(), g)
must be valid. Currently the expressionget(boost::vertex_name_t(), g)
must also be valid and return a property map with integer values If any vertex have non-zero vertex name, then the graph is considered vertex labelled and the vertex names are written.
-
template<typename
Graph
, typenameParallelHandler
, typenameLoopHandler
>
boolread_dimacs_graph
(std::istream &s, Graph &graph, std::ostream &err, ParallelHandler parHandler, LoopHandler loopHandler)¶ Parse a graph in DIMACS format from
s
and store it ingraph
. Reading errors are written toerr
.The unary predicate
loopHandler
is called with vertex indices where a loop edge has been parsed. The edge is added to the graph only if the handler returnstrue
. The binary predicateparHandler
must similarly evaluated parallel edges, if present.The format is line-based. Empty lines and lines starting with
c
are ignored. The first non-ignored line must be on the formp edge <n> <m>
where<n>
is the number of vertices in edge graph and<m>
is the number of edges. Afterwards there must be exactly<m>
lines on the forme <src> <tar>
where<src>
and<tar>
are vertex IDs in the range 1 to \(n\), representing and edge.In addition there may be any number of lines on the form
n <id> <label>
where<id>
is a vertex ID in the range 1 to \(n\), and<label>
is a non-negative number that will be assigned as the label of the vertex.