diff -r e9c203fb003d -r 994c7df296c9 lemon/lgf_writer.h --- a/lemon/lgf_writer.h Fri Nov 13 12:33:33 2009 +0100 +++ b/lemon/lgf_writer.h Thu Dec 10 17:05:35 2009 +0100 @@ -2,7 +2,7 @@ * * This file is a part of LEMON, a generic C++ optimization library. * - * Copyright (C) 2003-2008 + * Copyright (C) 2003-2009 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * @@ -347,19 +347,17 @@ } - template + template class DigraphWriter; - template - DigraphWriter digraphWriter(const Digraph& digraph, - std::ostream& os = std::cout); - template - DigraphWriter digraphWriter(const Digraph& digraph, - const std::string& fn); + template + DigraphWriter digraphWriter(const TDGR& digraph, + std::ostream& os = std::cout); + template + DigraphWriter digraphWriter(const TDGR& digraph, const std::string& fn); - template - DigraphWriter digraphWriter(const Digraph& digraph, - const char* fn); + template + DigraphWriter digraphWriter(const TDGR& digraph, const char* fn); /// \ingroup lemon_io @@ -381,7 +379,7 @@ /// arc() functions are used to add attribute writing rules. /// ///\code - /// DigraphWriter(digraph, std::cout). + /// DigraphWriter(digraph, std::cout). /// nodeMap("coordinates", coord_map). /// nodeMap("size", size). /// nodeMap("title", title). @@ -406,12 +404,12 @@ /// section to the stream. The output stream can be retrieved with /// the \c ostream() function, hence the second pass can append its /// output to the output of the first pass. - template + template class DigraphWriter { public: - typedef _Digraph Digraph; - TEMPLATE_DIGRAPH_TYPEDEFS(Digraph); + typedef DGR Digraph; + TEMPLATE_DIGRAPH_TYPEDEFS(DGR); private: @@ -419,7 +417,7 @@ std::ostream* _os; bool local_os; - const Digraph& _digraph; + const DGR& _digraph; std::string _nodes_caption; std::string _arcs_caption; @@ -451,7 +449,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - DigraphWriter(const Digraph& digraph, std::ostream& os = std::cout) + DigraphWriter(const DGR& digraph, std::ostream& os = std::cout) : _os(&os), local_os(false), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) {} @@ -459,7 +457,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const Digraph& digraph, const std::string& fn) + DigraphWriter(const DGR& digraph, const std::string& fn) : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) { if (!(*_os)) { @@ -472,7 +470,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - DigraphWriter(const Digraph& digraph, const char* fn) + DigraphWriter(const DGR& digraph, const char* fn) : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), _skip_nodes(false), _skip_arcs(false) { if (!(*_os)) { @@ -505,15 +503,15 @@ private: - template - friend DigraphWriter digraphWriter(const DGR& digraph, - std::ostream& os); - template - friend DigraphWriter digraphWriter(const DGR& digraph, - const std::string& fn); - template - friend DigraphWriter digraphWriter(const DGR& digraph, - const char *fn); + template + friend DigraphWriter digraphWriter(const TDGR& digraph, + std::ostream& os); + template + friend DigraphWriter digraphWriter(const TDGR& digraph, + const std::string& fn); + template + friend DigraphWriter digraphWriter(const TDGR& digraph, + const char *fn); DigraphWriter(DigraphWriter& other) : _os(other._os), local_os(other.local_os), _digraph(other._digraph), @@ -538,7 +536,7 @@ public: - /// \name Writing rules + /// \name Writing Rules /// @{ /// \brief Node map writing rule @@ -641,7 +639,7 @@ return *this; } - /// \name Section captions + /// \name Section Captions /// @{ /// \brief Add an additional caption to the \c \@nodes section @@ -668,7 +666,7 @@ return *this; } - /// \name Skipping section + /// \name Skipping Section /// @{ /// \brief Skip writing the node set @@ -724,8 +722,8 @@ } if (label == 0) { - IdMap id_map(_digraph); - _writer_bits::MapLess > id_less(id_map); + IdMap id_map(_digraph); + _writer_bits::MapLess > id_less(id_map); std::sort(nodes.begin(), nodes.end(), id_less); } else { label->sort(nodes); @@ -809,8 +807,8 @@ } if (label == 0) { - IdMap id_map(_digraph); - _writer_bits::MapLess > id_less(id_map); + IdMap id_map(_digraph); + _writer_bits::MapLess > id_less(id_map); std::sort(arcs.begin(), arcs.end(), id_less); } else { label->sort(arcs); @@ -885,7 +883,7 @@ public: - /// \name Execution of the writer + /// \name Execution of the Writer /// @{ /// \brief Start the batch processing @@ -915,14 +913,41 @@ /// @} }; + /// \ingroup lemon_io + /// /// \brief Return a \ref DigraphWriter class /// - /// This function just returns a \ref DigraphWriter class. + /// This function just returns a \ref DigraphWriter class. + /// + /// With this function a digraph can be write to a file or output + /// stream in \ref lgf-format "LGF" format with several maps and + /// attributes. For example, with the following code a network flow + /// problem can be written to the standard output, i.e. a digraph + /// with a \e capacity map on the arcs and \e source and \e target + /// nodes: + /// + ///\code + ///ListDigraph digraph; + ///ListDigraph::ArcMap cap(digraph); + ///ListDigraph::Node src, trg; + /// // Setting the capacity map and source and target nodes + ///digraphWriter(digraph, std::cout). + /// arcMap("capacity", cap). + /// node("source", src). + /// node("target", trg). + /// run(); + ///\endcode + /// + /// For a complete documentation, please see the \ref DigraphWriter + /// class documentation. + /// \warning Don't forget to put the \ref DigraphWriter::run() "run()" + /// to the end of the parameter list. /// \relates DigraphWriter - template - DigraphWriter digraphWriter(const Digraph& digraph, - std::ostream& os) { - DigraphWriter tmp(digraph, os); + /// \sa digraphWriter(const TDGR& digraph, const std::string& fn) + /// \sa digraphWriter(const TDGR& digraph, const char* fn) + template + DigraphWriter digraphWriter(const TDGR& digraph, std::ostream& os) { + DigraphWriter tmp(digraph, os); return tmp; } @@ -930,10 +955,11 @@ /// /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter - template - DigraphWriter digraphWriter(const Digraph& digraph, - const std::string& fn) { - DigraphWriter tmp(digraph, fn); + /// \sa digraphWriter(const TDGR& digraph, std::ostream& os) + template + DigraphWriter digraphWriter(const TDGR& digraph, + const std::string& fn) { + DigraphWriter tmp(digraph, fn); return tmp; } @@ -941,23 +967,22 @@ /// /// This function just returns a \ref DigraphWriter class. /// \relates DigraphWriter - template - DigraphWriter digraphWriter(const Digraph& digraph, - const char* fn) { - DigraphWriter tmp(digraph, fn); + /// \sa digraphWriter(const TDGR& digraph, std::ostream& os) + template + DigraphWriter digraphWriter(const TDGR& digraph, const char* fn) { + DigraphWriter tmp(digraph, fn); return tmp; } - template + template class GraphWriter; - template - GraphWriter graphWriter(const Graph& graph, - std::ostream& os = std::cout); - template - GraphWriter graphWriter(const Graph& graph, const std::string& fn); - template - GraphWriter graphWriter(const Graph& graph, const char* fn); + template + GraphWriter graphWriter(const TGR& graph, std::ostream& os = std::cout); + template + GraphWriter graphWriter(const TGR& graph, const std::string& fn); + template + GraphWriter graphWriter(const TGR& graph, const char* fn); /// \ingroup lemon_io /// @@ -974,12 +999,12 @@ /// '+' and \c '-'. The arcs are written into the \c \@attributes /// section as a \c '+' or a \c '-' prefix (depends on the direction /// of the arc) and the label of corresponding edge. - template + template class GraphWriter { public: - typedef _Graph Graph; - TEMPLATE_GRAPH_TYPEDEFS(Graph); + typedef GR Graph; + TEMPLATE_GRAPH_TYPEDEFS(GR); private: @@ -987,7 +1012,7 @@ std::ostream* _os; bool local_os; - const Graph& _graph; + const GR& _graph; std::string _nodes_caption; std::string _edges_caption; @@ -1019,7 +1044,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output stream. - GraphWriter(const Graph& graph, std::ostream& os = std::cout) + GraphWriter(const GR& graph, std::ostream& os = std::cout) : _os(&os), local_os(false), _graph(graph), _skip_nodes(false), _skip_edges(false) {} @@ -1027,7 +1052,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const Graph& graph, const std::string& fn) + GraphWriter(const GR& graph, const std::string& fn) : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), _skip_nodes(false), _skip_edges(false) { if (!(*_os)) { @@ -1040,7 +1065,7 @@ /// /// Construct a directed graph writer, which writes to the given /// output file. - GraphWriter(const Graph& graph, const char* fn) + GraphWriter(const GR& graph, const char* fn) : _os(new std::ofstream(fn)), local_os(true), _graph(graph), _skip_nodes(false), _skip_edges(false) { if (!(*_os)) { @@ -1073,15 +1098,13 @@ private: - template - friend GraphWriter graphWriter(const GR& graph, - std::ostream& os); - template - friend GraphWriter graphWriter(const GR& graph, - const std::string& fn); - template - friend GraphWriter graphWriter(const GR& graph, - const char *fn); + template + friend GraphWriter graphWriter(const TGR& graph, std::ostream& os); + template + friend GraphWriter graphWriter(const TGR& graph, + const std::string& fn); + template + friend GraphWriter graphWriter(const TGR& graph, const char *fn); GraphWriter(GraphWriter& other) : _os(other._os), local_os(other.local_os), _graph(other._graph), @@ -1106,7 +1129,7 @@ public: - /// \name Writing rules + /// \name Writing Rules /// @{ /// \brief Node map writing rule @@ -1168,10 +1191,10 @@ GraphWriter& arcMap(const std::string& caption, const Map& map) { checkConcept, Map>(); _writer_bits::MapStorageBase* forward_storage = - new _writer_bits::GraphArcMapStorage(_graph, map); + new _writer_bits::GraphArcMapStorage(_graph, map); _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); _writer_bits::MapStorageBase* backward_storage = - new _writer_bits::GraphArcMapStorage(_graph, map); + new _writer_bits::GraphArcMapStorage(_graph, map); _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); return *this; } @@ -1185,11 +1208,11 @@ const Converter& converter = Converter()) { checkConcept, Map>(); _writer_bits::MapStorageBase* forward_storage = - new _writer_bits::GraphArcMapStorage + new _writer_bits::GraphArcMapStorage (_graph, map, converter); _edge_maps.push_back(std::make_pair('+' + caption, forward_storage)); _writer_bits::MapStorageBase* backward_storage = - new _writer_bits::GraphArcMapStorage + new _writer_bits::GraphArcMapStorage (_graph, map, converter); _edge_maps.push_back(std::make_pair('-' + caption, backward_storage)); return *this; @@ -1247,7 +1270,7 @@ /// /// Add an arc writing rule to writer. GraphWriter& arc(const std::string& caption, const Arc& arc) { - typedef _writer_bits::GraphArcLookUpConverter Converter; + typedef _writer_bits::GraphArcLookUpConverter Converter; Converter converter(_graph, _edge_index); _writer_bits::ValueStorageBase* storage = new _writer_bits::ValueStorage(arc, converter); @@ -1255,7 +1278,7 @@ return *this; } - /// \name Section captions + /// \name Section Captions /// @{ /// \brief Add an additional caption to the \c \@nodes section @@ -1282,7 +1305,7 @@ return *this; } - /// \name Skipping section + /// \name Skipping Section /// @{ /// \brief Skip writing the node set @@ -1338,8 +1361,8 @@ } if (label == 0) { - IdMap id_map(_graph); - _writer_bits::MapLess > id_less(id_map); + IdMap id_map(_graph); + _writer_bits::MapLess > id_less(id_map); std::sort(nodes.begin(), nodes.end(), id_less); } else { label->sort(nodes); @@ -1423,8 +1446,8 @@ } if (label == 0) { - IdMap id_map(_graph); - _writer_bits::MapLess > id_less(id_map); + IdMap id_map(_graph); + _writer_bits::MapLess > id_less(id_map); std::sort(edges.begin(), edges.end(), id_less); } else { label->sort(edges); @@ -1499,7 +1522,7 @@ public: - /// \name Execution of the writer + /// \name Execution of the Writer /// @{ /// \brief Start the batch processing @@ -1529,14 +1552,37 @@ /// @} }; + /// \ingroup lemon_io + /// /// \brief Return a \ref GraphWriter class /// - /// This function just returns a \ref GraphWriter class. + /// This function just returns a \ref GraphWriter class. + /// + /// With this function a graph can be write to a file or output + /// stream in \ref lgf-format "LGF" format with several maps and + /// attributes. For example, with the following code a weighted + /// matching problem can be written to the standard output, i.e. a + /// graph with a \e weight map on the edges: + /// + ///\code + ///ListGraph graph; + ///ListGraph::EdgeMap weight(graph); + /// // Setting the weight map + ///graphWriter(graph, std::cout). + /// edgeMap("weight", weight). + /// run(); + ///\endcode + /// + /// For a complete documentation, please see the \ref GraphWriter + /// class documentation. + /// \warning Don't forget to put the \ref GraphWriter::run() "run()" + /// to the end of the parameter list. /// \relates GraphWriter - template - GraphWriter graphWriter(const Graph& graph, - std::ostream& os) { - GraphWriter tmp(graph, os); + /// \sa graphWriter(const TGR& graph, const std::string& fn) + /// \sa graphWriter(const TGR& graph, const char* fn) + template + GraphWriter graphWriter(const TGR& graph, std::ostream& os) { + GraphWriter tmp(graph, os); return tmp; } @@ -1544,9 +1590,10 @@ /// /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter - template - GraphWriter graphWriter(const Graph& graph, const std::string& fn) { - GraphWriter tmp(graph, fn); + /// \sa graphWriter(const TGR& graph, std::ostream& os) + template + GraphWriter graphWriter(const TGR& graph, const std::string& fn) { + GraphWriter tmp(graph, fn); return tmp; } @@ -1554,9 +1601,10 @@ /// /// This function just returns a \ref GraphWriter class. /// \relates GraphWriter - template - GraphWriter graphWriter(const Graph& graph, const char* fn) { - GraphWriter tmp(graph, fn); + /// \sa graphWriter(const TGR& graph, std::ostream& os) + template + GraphWriter graphWriter(const TGR& graph, const char* fn) { + GraphWriter tmp(graph, fn); return tmp; } @@ -1651,7 +1699,7 @@ public: - /// \name Section writers + /// \name Section Writers /// @{ /// \brief Add a section writer with line oriented writing @@ -1718,7 +1766,7 @@ public: - /// \name Execution of the writer + /// \name Execution of the Writer /// @{ /// \brief Start the batch processing @@ -1746,10 +1794,18 @@ }; + /// \ingroup lemon_io + /// /// \brief Return a \ref SectionWriter class /// /// This function just returns a \ref SectionWriter class. + /// + /// Please see SectionWriter documentation about the custom section + /// output. + /// /// \relates SectionWriter + /// \sa sectionWriter(const std::string& fn) + /// \sa sectionWriter(const char *fn) inline SectionWriter sectionWriter(std::ostream& os) { SectionWriter tmp(os); return tmp; @@ -1759,6 +1815,7 @@ /// /// This function just returns a \ref SectionWriter class. /// \relates SectionWriter + /// \sa sectionWriter(std::ostream& os) inline SectionWriter sectionWriter(const std::string& fn) { SectionWriter tmp(fn); return tmp; @@ -1768,6 +1825,7 @@ /// /// This function just returns a \ref SectionWriter class. /// \relates SectionWriter + /// \sa sectionWriter(std::ostream& os) inline SectionWriter sectionWriter(const char* fn) { SectionWriter tmp(fn); return tmp;