# HG changeset patch # User athos # Date 1120493493 0 # Node ID b86aad11f84237c7f28caf91b90fac9a57956bd2 # Parent 43c7b30852124948aafe840b481272627a6a218f Doc. diff -r 43c7b3085212 -r b86aad11f842 demo/reader_writer_demo.cc --- a/demo/reader_writer_demo.cc Mon Jul 04 16:11:00 2005 +0000 +++ b/demo/reader_writer_demo.cc Mon Jul 04 16:11:33 2005 +0000 @@ -24,8 +24,6 @@ GraphWriter writer(std::cout, graph); writer.writeEdgeMap("multiplicity", cap); -// writer.writeNode("source", s); -// writer.writeNode("target", t); writer.run(); } catch (DataFormatError& error) { diff -r 43c7b3085212 -r b86aad11f842 doc/quicktour.dox --- a/doc/quicktour.dox Mon Jul 04 16:11:00 2005 +0000 +++ b/doc/quicktour.dox Mon Jul 04 16:11:33 2005 +0000 @@ -38,7 +38,7 @@ read a graph (and perhaps maps on it) from a stream (e.g. a file). Of course we also have routines that write a graph (and perhaps maps) to a stream (file): this will also be shown. LEMON supports the DIMACS file formats to -store network optimization problems, but more importantly we also have our own +read network optimization problems, but more importantly we also have our own file format that gives a more flexible way to store data related to network optimization. @@ -86,9 +86,8 @@ One can also store network (graph+capacity on the edges) instances and other things (minimum cost flow instances etc.) in DIMACS format and -use these in LEMON: to see the details read the documentation of the -\ref dimacs.h "Dimacs file format reader". There you will also find -the details about the output routines into files of the DIMACS format. +read these in LEMON: to see the details read the documentation of the +\ref dimacs.h "Dimacs file format reader".
  • If you want to solve some transportation problems in a network then diff -r 43c7b3085212 -r b86aad11f842 lemon/graph_reader.h --- a/lemon/graph_reader.h Mon Jul 04 16:11:00 2005 +0000 +++ b/lemon/graph_reader.h Mon Jul 04 16:11:33 2005 +0000 @@ -33,6 +33,13 @@ /// \brief The graph reader class. /// + /// The \c GraphReader class provides the graph input. + /// Before you read this documentation it might be useful to read the general + /// description of \ref graph-io-page "Graph Input-Output". + /// If you don't need very sophisticated + /// behaviour then you can use the versions of the public function + /// \ref readGraph() to read a graph (or a max flow instance etc). + /// /// The given file format may contain several maps and labeled nodes or /// edges. /// @@ -332,9 +339,78 @@ AttributeReader attribute_reader; }; - /// \brief Read a graph from the input. + + ///\anchor readGraph() /// - /// Read a graph from the input. + /// \brief Read a graph from an input stream. + /// + /// Read a graph from an input stream. + /// \param is The input stream. + /// \param g The graph. + template + void readGraph(std::istream& is, Graph &g) { + GraphReader reader(is, g); + reader.run(); + } + + /// \brief Read a capacitated graph instance from an input stream. + /// + /// Read a capacitated graph (graph+capacity on the + /// edges) from an input stream. + /// \param is The input stream. + /// \param g The graph. + /// \param capacity The capacity map. + template + void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) { + GraphReader reader(is, g); + reader.readEdgeMap("capacity", capacity); + reader.run(); + } + + /// \brief Read a shortest path instance from an input stream. + /// + /// Read a shortest path instance (graph+capacity on the + /// edges+designated source) from an input stream. + /// \param is The input stream. + /// \param g The graph. + /// \param capacity The capacity map. + /// \param s The source node. + template + void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, + typename Graph::Node &s) { + GraphReader reader(is, g); + reader.readEdgeMap("capacity", capacity); + reader.readNode("source", s); + reader.run(); + } + + + + /// \brief Read a max flow instance from an input stream. + /// + /// Read a max flow instance (graph+capacity on the + /// edges+designated source and target) from an input stream. + /// + /// \param is The input stream. + /// \param g The graph. + /// \param capacity The capacity map. + /// \param s The source node. + /// \param t The target node. + template + void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, + typename Graph::Node &s, typename Graph::Node &t) { + GraphReader reader(is, g); + reader.readEdgeMap("capacity", capacity); + reader.readNode("source", s); + reader.readNode("target", t); + reader.run(); + } + + /// \brief Read a min cost flow instance from an input stream. + /// + /// Read a min cost flow instance (graph+capacity on the edges+cost + /// function on the edges+designated source and target) from an input stream. + /// /// \param is The input stream. /// \param g The graph. /// \param capacity The capacity map. @@ -353,63 +429,6 @@ reader.run(); } - /// \brief Read a graph from the input. - /// - /// Read a graph from the input. - /// \param is The input stream. - /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - /// \param t The target node. - template - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, - typename Graph::Node &s, typename Graph::Node &t) { - GraphReader reader(is, g); - reader.readEdgeMap("capacity", capacity); - reader.readNode("source", s); - reader.readNode("target", t); - reader.run(); - } - - /// \brief Read a graph from the input. - /// - /// Read a graph from the input. - /// \param is The input stream. - /// \param g The graph. - /// \param capacity The capacity map. - /// \param s The source node. - template - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, - typename Graph::Node &s) { - GraphReader reader(is, g); - reader.readEdgeMap("capacity", capacity); - reader.readNode("source", s); - reader.run(); - } - - /// \brief Read a graph from the input. - /// - /// Read a graph from the input. - /// \param is The input stream. - /// \param g The graph. - /// \param capacity The capacity map. - template - void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) { - GraphReader reader(is, g); - reader.readEdgeMap("capacity", capacity); - reader.run(); - } - - /// \brief Read a graph from the input. - /// - /// Read a graph from the input. - /// \param is The input stream. - /// \param g The graph. - template - void readGraph(std::istream& is, Graph &g) { - GraphReader reader(is, g); - reader.run(); - } /// \brief The undir graph reader class. /// @@ -779,9 +798,22 @@ AttributeReader attribute_reader; }; - /// \brief Read an undir graph from the input. + /// \brief Read an undirected graph from an input stream. /// - /// Read an undir graph from the input. + /// Read an undirected graph from an input stream. + /// \param is The input stream. + /// \param g The graph. + template + void readUndirGraph(std::istream& is, Graph &g) { + UndirGraphReader reader(is, g); + reader.run(); + } + + /// \brief Read an undirected multigraph (undirected graph + capacity + /// map on the edges) from an input stream. + /// + /// Read an undirected multigraph (undirected graph + capacity + /// map on the edges) from an input stream. /// \param is The input stream. /// \param g The graph. /// \param capacity The capacity map. @@ -792,16 +824,6 @@ reader.run(); } - /// \brief Read an undir graph from the input. - /// - /// Read an undir graph from the input. - /// \param is The input stream. - /// \param g The graph. - template - void readUndirGraph(std::istream& is, Graph &g) { - UndirGraphReader reader(is, g); - reader.run(); - } /// @} } diff -r 43c7b3085212 -r b86aad11f842 lemon/graph_writer.h --- a/lemon/graph_writer.h Mon Jul 04 16:11:00 2005 +0000 +++ b/lemon/graph_writer.h Mon Jul 04 16:11:33 2005 +0000 @@ -17,6 +17,7 @@ ///\ingroup io_group ///\file ///\brief Lemon Graph Format writer. +/// #ifndef LEMON_GRAPH_WRITER_H #define LEMON_GRAPH_WRITER_H @@ -36,6 +37,10 @@ /// The \c GraphWriter class provides the graph output. /// Before you read this documentation it might be useful to read the general /// description of \ref graph-io-page "Graph Input-Output". + /// If you don't need very sophisticated + /// behaviour then you can use the versions of the public function + /// \ref writeGraph() to output a graph (or a max flow instance etc). + /// /// To write a graph /// you should first give writing commands to the writer. You can declare /// write commands as \c NodeMap or \c EdgeMap writing and labeled Node and @@ -276,34 +281,69 @@ }; + ///\anchor writeGraph() + /// /// \brief Write a graph to the output. /// /// Write a graph to the output. /// \param os The output stream. /// \param g The graph. + template + void writeGraph(std::ostream& os, const Graph &g) { + GraphWriter writer(os, g); + IdMap nodeIdMap(g); + writer.writeNodeMap("id", nodeIdMap); + IdMap edgeIdMap(g); + writer.writeEdgeMap("id", edgeIdMap); + writer.run(); + } + + /// \brief Write a capacitated graph instance to the output. + /// + /// Write a capacitated graph (graph+capacity on the + /// edges) to the output. + /// \param os The output stream. + /// \param g The graph. /// \param capacity The capacity map. - /// \param s The source node. - /// \param t The target node. - /// \param cost The cost map. - template + template void writeGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity, const typename Graph::Node &s, - const typename Graph::Node &t, const CostMap& cost) { + const CapacityMap& capacity) { GraphWriter writer(os, g); IdMap nodeIdMap(g); writer.writeNodeMap("id", nodeIdMap); IdMap edgeIdMap(g); writer.writeEdgeMap("id", edgeIdMap); writer.writeEdgeMap("capacity", capacity); - writer.writeEdgeMap("cost", cost); - writer.writeNode("source", s); - writer.writeNode("target", t); writer.run(); } - /// \brief Write a graph to the output. + /// \brief Write a shortest path instance to the output. + /// + /// Write a shortest path instance (graph+capacity on the + /// edges+designated source) to the output. + /// \param os The output stream. + /// \param g The graph. + /// \param capacity The capacity map. + /// \param s The source node. + template + void writeGraph(std::ostream& os, const Graph &g, + const CapacityMap& capacity, const typename Graph::Node &s) { + GraphWriter writer(os, g); + IdMap nodeIdMap(g); + writer.writeNodeMap("id", nodeIdMap); + IdMap edgeIdMap(g); + writer.writeEdgeMap("id", edgeIdMap); + writer.writeEdgeMap("capacity", capacity); + writer.writeNode("source", s); + writer.run(); + } + + + /// \brief Write a max flow instance to the output. /// - /// Write a graph to the output. + /// Write a max flow instance (graph+capacity on the + /// edges+designated source and target) to the output. + /// /// \param os The output stream. /// \param g The graph. /// \param capacity The capacity map. @@ -324,56 +364,30 @@ writer.run(); } - /// \brief Write a graph to the output. + /// \brief Write a min cost flow instance to the output. /// - /// Write a graph to the output. + /// Write a min cost flow instance (graph+capacity on the edges+cost + /// function on the edges+designated source and target) to the output. + /// /// \param os The output stream. /// \param g The graph. /// \param capacity The capacity map. /// \param s The source node. - template + /// \param t The target node. + /// \param cost The cost map. + template void writeGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity, const typename Graph::Node &s) { + const CapacityMap& capacity, const typename Graph::Node &s, + const typename Graph::Node &t, const CostMap& cost) { GraphWriter writer(os, g); IdMap nodeIdMap(g); writer.writeNodeMap("id", nodeIdMap); IdMap edgeIdMap(g); writer.writeEdgeMap("id", edgeIdMap); writer.writeEdgeMap("capacity", capacity); + writer.writeEdgeMap("cost", cost); writer.writeNode("source", s); - writer.run(); - } - - /// \brief Write a graph to the output. - /// - /// Write a graph to the output. - /// \param os The output stream. - /// \param g The graph. - /// \param capacity The capacity map. - template - void writeGraph(std::ostream& os, const Graph &g, - const CapacityMap& capacity) { - GraphWriter writer(os, g); - IdMap nodeIdMap(g); - writer.writeNodeMap("id", nodeIdMap); - IdMap edgeIdMap(g); - writer.writeEdgeMap("id", edgeIdMap); - writer.writeEdgeMap("capacity", capacity); - writer.run(); - } - - /// \brief Write a graph to the output. - /// - /// Write a graph to the output. - /// \param os The output stream. - /// \param g The graph. - template - void writeGraph(std::ostream& os, const Graph &g) { - GraphWriter writer(os, g); - IdMap nodeIdMap(g); - writer.writeNodeMap("id", nodeIdMap); - IdMap edgeIdMap(g); - writer.writeEdgeMap("id", edgeIdMap); + writer.writeNode("target", t); writer.run(); } @@ -665,6 +679,16 @@ AttributeWriter attribute_writer; }; + /// \brief Write an undirected graph to the output. + /// + /// Write an undirected graph to the output. + /// \param os The output stream. + /// \param g The graph. + template + void writeUndirGraph(std::ostream& os, const Graph &g) { + UndirGraphWriter writer(os, g); + writer.run(); + } /// \brief Write an undirected multigraph (undirected graph + capacity /// map on the edges) to the output. @@ -682,16 +706,6 @@ writer.run(); } - /// \brief Write an undirected graph to the output. - /// - /// Write an undirected graph to the output. - /// \param os The output stream. - /// \param g The graph. - template - void writeUndirGraph(std::ostream& os, const Graph &g) { - UndirGraphWriter writer(os, g); - writer.run(); - } /// @}