COIN-OR::LEMON - Graph Library

Changeset 598:a3402913cffe in lemon-main for lemon/lgf_reader.h


Ignore:
Timestamp:
04/18/09 21:54:30 (15 years ago)
Author:
Balazs Dezso <deba@…>
Branch:
default
Phase:
public
Message:

Add more docs to LGF function interface (#109)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lgf_reader.h

    r559 r598  
    102102    };
    103103
    104     template <typename _Graph, bool _dir, typename _Map,
     104    template <typename _GR, bool _dir, typename _Map,
    105105              typename _Converter = DefaultConverter<typename _Map::Value> >
    106     class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
     106    class GraphArcMapStorage : public MapStorageBase<typename _GR::Edge> {
    107107    public:
    108108      typedef _Map Map;
    109109      typedef _Converter Converter;
    110       typedef _Graph Graph;
    111       typedef typename Graph::Edge Item;
     110      typedef _GR GR;
     111      typedef typename GR::Edge Item;
    112112      static const bool dir = _dir;
    113113
    114114    private:
    115       const Graph& _graph;
     115      const GR& _graph;
    116116      Map& _map;
    117117      Converter _converter;
    118118
    119119    public:
    120       GraphArcMapStorage(const Graph& graph, Map& map,
     120      GraphArcMapStorage(const GR& graph, Map& map,
    121121                         const Converter& converter = Converter())
    122122        : _graph(graph), _map(map), _converter(converter) {}
     
    174174    };
    175175
    176     template <typename Graph>
     176    template <typename GR>
    177177    struct GraphArcLookUpConverter {
    178       const Graph& _graph;
    179       const std::map<std::string, typename Graph::Edge>& _map;
    180 
    181       GraphArcLookUpConverter(const Graph& graph,
     178      const GR& _graph;
     179      const std::map<std::string, typename GR::Edge>& _map;
     180
     181      GraphArcLookUpConverter(const GR& graph,
    182182                              const std::map<std::string,
    183                                              typename Graph::Edge>& map)
     183                                             typename GR::Edge>& map)
    184184        : _graph(graph), _map(map) {}
    185185
    186       typename Graph::Arc operator()(const std::string& str) {
     186      typename GR::Arc operator()(const std::string& str) {
    187187        if (str.empty() || (str[0] != '+' && str[0] != '-')) {
    188188          throw FormatError("Item must start with '+' or '-'");
    189189        }
    190         typename std::map<std::string, typename Graph::Edge>
     190        typename std::map<std::string, typename GR::Edge>
    191191          ::const_iterator it = _map.find(str.substr(1));
    192192        if (it == _map.end()) {
     
    388388  }
    389389
    390   template <typename Digraph>
     390  template <typename DGR>
    391391  class DigraphReader;
    392392
    393   template <typename Digraph>
    394   DigraphReader<Digraph> digraphReader(Digraph& digraph,
    395                                        std::istream& is = std::cin);
    396   template <typename Digraph>
    397   DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn);
    398   template <typename Digraph>
    399   DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn);
     393  template <typename TDGR>
     394  DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is = std::cin);
     395  template <typename TDGR>
     396  DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn);
     397  template <typename TDGR>
     398  DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn);
    400399
    401400  /// \ingroup lemon_io
     
    420419  ///
    421420  ///\code
    422   /// DigraphReader<Digraph>(digraph, std::cin).
     421  /// DigraphReader<DGR>(digraph, std::cin).
    423422  ///   nodeMap("coordinates", coord_map).
    424423  ///   arcMap("capacity", cap_map).
     
    449448  /// a single pass, because the arcs are not constructed when the node
    450449  /// maps are read.
    451   template <typename GR>
     450  template <typename DGR>
    452451  class DigraphReader {
    453452  public:
    454453
    455     typedef GR Digraph;
     454    typedef DGR Digraph;
    456455
    457456  private:
    458457
    459     TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
     458    TEMPLATE_DIGRAPH_TYPEDEFS(DGR);
    460459
    461460    std::istream* _is;
     
    463462    std::string _filename;
    464463
    465     Digraph& _digraph;
     464    DGR& _digraph;
    466465
    467466    std::string _nodes_caption;
     
    501500    /// Construct a directed graph reader, which reads from the given
    502501    /// input stream.
    503     DigraphReader(Digraph& digraph, std::istream& is = std::cin)
     502    DigraphReader(DGR& digraph, std::istream& is = std::cin)
    504503      : _is(&is), local_is(false), _digraph(digraph),
    505504        _use_nodes(false), _use_arcs(false),
     
    510509    /// Construct a directed graph reader, which reads from the given
    511510    /// file.
    512     DigraphReader(Digraph& digraph, const std::string& fn)
     511    DigraphReader(DGR& digraph, const std::string& fn)
    513512      : _is(new std::ifstream(fn.c_str())), local_is(true),
    514513        _filename(fn), _digraph(digraph),
     
    525524    /// Construct a directed graph reader, which reads from the given
    526525    /// file.
    527     DigraphReader(Digraph& digraph, const char* fn)
     526    DigraphReader(DGR& digraph, const char* fn)
    528527      : _is(new std::ifstream(fn)), local_is(true),
    529528        _filename(fn), _digraph(digraph),
     
    561560  private:
    562561
    563     template <typename DGR>
    564     friend DigraphReader<DGR> digraphReader(DGR& digraph, std::istream& is);
    565     template <typename DGR>
    566     friend DigraphReader<DGR> digraphReader(DGR& digraph,
    567                                             const std::string& fn);
    568     template <typename DGR>
    569     friend DigraphReader<DGR> digraphReader(DGR& digraph, const char *fn);
     562    template <typename TDGR>
     563    friend DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is);
     564    template <typename TDGR>
     565    friend DigraphReader<TDGR> digraphReader(TDGR& digraph,
     566                                             const std::string& fn);
     567    template <typename TDGR>
     568    friend DigraphReader<TDGR> digraphReader(TDGR& digraph, const char *fn);
    570569
    571570    DigraphReader(DigraphReader& other)
     
    11891188
    11901189  };
     1190 
     1191  /// \ingroup lemon_io
     1192  ///
     1193  /// \brief Return a \ref DigraphReader class
     1194  ///
     1195  /// This function just returns a \ref DigraphReader class.
     1196  ///
     1197  /// With this function a digraph can be read from an
     1198  /// \ref lgf-format "LGF" file or input stream with several maps and
     1199  /// attributes. For example, there is network flow problem on a
     1200  /// digraph, i.e. a digraph with a \e capacity map on the arcs and
     1201  /// \e source and \e target nodes. This digraph can be read with the
     1202  /// following code:
     1203  ///
     1204  ///\code
     1205  ///ListDigraph digraph;
     1206  ///ListDigraph::ArcMap<int> cm(digraph);
     1207  ///ListDigraph::Node src, trg;
     1208  ///digraphReader(digraph, std::cin).
     1209  ///  arcMap("capacity", cap).
     1210  ///  node("source", src).
     1211  ///  node("target", trg).
     1212  ///  run();
     1213  ///\endcode
     1214  ///
     1215  /// For a complete documentation, please see the \ref DigraphReader
     1216  /// class documentation.
     1217  /// \warning Don't forget to put the \ref DigraphReader::run() "run()"
     1218  /// to the end of the parameter list.
     1219  /// \relates DigraphReader
     1220  /// \sa digraphReader(TDGR& digraph, const std::string& fn)
     1221  /// \sa digraphReader(TDGR& digraph, const char* fn)
     1222  template <typename TDGR>
     1223  DigraphReader<TDGR> digraphReader(TDGR& digraph, std::istream& is) {
     1224    DigraphReader<TDGR> tmp(digraph, is);
     1225    return tmp;
     1226  }
    11911227
    11921228  /// \brief Return a \ref DigraphReader class
     
    11941230  /// This function just returns a \ref DigraphReader class.
    11951231  /// \relates DigraphReader
    1196   template <typename Digraph>
    1197   DigraphReader<Digraph> digraphReader(Digraph& digraph, std::istream& is) {
    1198     DigraphReader<Digraph> tmp(digraph, is);
     1232  /// \sa digraphReader(TDGR& digraph, std::istream& is)
     1233  template <typename TDGR>
     1234  DigraphReader<TDGR> digraphReader(TDGR& digraph, const std::string& fn) {
     1235    DigraphReader<TDGR> tmp(digraph, fn);
    11991236    return tmp;
    12001237  }
     
    12041241  /// This function just returns a \ref DigraphReader class.
    12051242  /// \relates DigraphReader
    1206   template <typename Digraph>
    1207   DigraphReader<Digraph> digraphReader(Digraph& digraph,
    1208                                        const std::string& fn) {
    1209     DigraphReader<Digraph> tmp(digraph, fn);
     1243  /// \sa digraphReader(TDGR& digraph, std::istream& is)
     1244  template <typename TDGR>
     1245  DigraphReader<TDGR> digraphReader(TDGR& digraph, const char* fn) {
     1246    DigraphReader<TDGR> tmp(digraph, fn);
    12101247    return tmp;
    12111248  }
    12121249
    1213   /// \brief Return a \ref DigraphReader class
    1214   ///
    1215   /// This function just returns a \ref DigraphReader class.
    1216   /// \relates DigraphReader
    1217   template <typename Digraph>
    1218   DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) {
    1219     DigraphReader<Digraph> tmp(digraph, fn);
    1220     return tmp;
    1221   }
    1222 
    1223   template <typename Graph>
     1250  template <typename GR>
    12241251  class GraphReader;
    12251252 
    1226   template <typename Graph>
    1227   GraphReader<Graph> graphReader(Graph& graph,
    1228                                  std::istream& is = std::cin);
    1229   template <typename Graph>
    1230   GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
    1231   template <typename Graph>
    1232   GraphReader<Graph> graphReader(Graph& graph, const char *fn);
     1253  template <typename TGR>
     1254  GraphReader<TGR> graphReader(TGR& graph, std::istream& is = std::cin);
     1255  template <typename TGR>
     1256  GraphReader<TGR> graphReader(TGR& graph, const std::string& fn);
     1257  template <typename TGR>
     1258  GraphReader<TGR> graphReader(TGR& graph, const char *fn);
    12331259
    12341260  /// \ingroup lemon_io
     
    12551281  private:
    12561282
    1257     TEMPLATE_GRAPH_TYPEDEFS(Graph);
     1283    TEMPLATE_GRAPH_TYPEDEFS(GR);
    12581284
    12591285    std::istream* _is;
     
    12611287    std::string _filename;
    12621288
    1263     Graph& _graph;
     1289    GR& _graph;
    12641290
    12651291    std::string _nodes_caption;
     
    12991325    /// Construct an undirected graph reader, which reads from the given
    13001326    /// input stream.
    1301     GraphReader(Graph& graph, std::istream& is = std::cin)
     1327    GraphReader(GR& graph, std::istream& is = std::cin)
    13021328      : _is(&is), local_is(false), _graph(graph),
    13031329        _use_nodes(false), _use_edges(false),
     
    13081334    /// Construct an undirected graph reader, which reads from the given
    13091335    /// file.
    1310     GraphReader(Graph& graph, const std::string& fn)
     1336    GraphReader(GR& graph, const std::string& fn)
    13111337      : _is(new std::ifstream(fn.c_str())), local_is(true),
    13121338        _filename(fn), _graph(graph),
     
    13231349    /// Construct an undirected graph reader, which reads from the given
    13241350    /// file.
    1325     GraphReader(Graph& graph, const char* fn)
     1351    GraphReader(GR& graph, const char* fn)
    13261352      : _is(new std::ifstream(fn)), local_is(true),
    13271353        _filename(fn), _graph(graph),
     
    13581384
    13591385  private:
    1360     template <typename Graph>
    1361     friend GraphReader<Graph> graphReader(Graph& graph, std::istream& is);
    1362     template <typename Graph>
    1363     friend GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
    1364     template <typename Graph>
    1365     friend GraphReader<Graph> graphReader(Graph& graph, const char *fn);
     1386    template <typename TGR>
     1387    friend GraphReader<TGR> graphReader(TGR& graph, std::istream& is);
     1388    template <typename TGR>
     1389    friend GraphReader<TGR> graphReader(TGR& graph, const std::string& fn);
     1390    template <typename TGR>
     1391    friend GraphReader<TGR> graphReader(TGR& graph, const char *fn);
    13661392
    13671393    GraphReader(GraphReader& other)
     
    14551481      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    14561482      _reader_bits::MapStorageBase<Edge>* backward_storage =
    1457         new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
     1483        new _reader_bits::GraphArcMapStorage<GR, false, Map>(_graph, map);
    14581484      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    14591485      return *this;
     
    14691495      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    14701496      _reader_bits::MapStorageBase<Edge>* forward_storage =
    1471         new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter>
     1497        new _reader_bits::GraphArcMapStorage<GR, true, Map, Converter>
    14721498        (_graph, map, converter);
    14731499      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    14741500      _reader_bits::MapStorageBase<Edge>* backward_storage =
    1475         new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter>
     1501        new _reader_bits::GraphArcMapStorage<GR, false, Map, Converter>
    14761502        (_graph, map, converter);
    14771503      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
     
    15311557    /// Add an arc reading rule to reader.
    15321558    GraphReader& arc(const std::string& caption, Arc& arc) {
    1533       typedef _reader_bits::GraphArcLookUpConverter<Graph> Converter;
     1559      typedef _reader_bits::GraphArcLookUpConverter<GR> Converter;
    15341560      Converter converter(_graph, _edge_index);
    15351561      _reader_bits::ValueStorageBase* storage =
     
    20342060  };
    20352061
     2062  /// \ingroup lemon_io
     2063  ///
     2064  /// \brief Return a \ref GraphReader class
     2065  ///
     2066  /// This function just returns a \ref GraphReader class.
     2067  ///
     2068  /// With this function a graph can be read from an
     2069  /// \ref lgf-format "LGF" file or input stream with several maps and
     2070  /// attributes. For example, there is weighted matching problem on a
     2071  /// graph, i.e. a graph with a \e weight map on the edges. This
     2072  /// graph can be read with the following code:
     2073  ///
     2074  ///\code
     2075  ///ListGraph graph;
     2076  ///ListGraph::EdgeMap<int> weight(graph);
     2077  ///graphReader(graph, std::cin).
     2078  ///  edgeMap("weight", weight).
     2079  ///  run();
     2080  ///\endcode
     2081  ///
     2082  /// For a complete documentation, please see the \ref GraphReader
     2083  /// class documentation.
     2084  /// \warning Don't forget to put the \ref GraphReader::run() "run()"
     2085  /// to the end of the parameter list.
     2086  /// \relates GraphReader
     2087  /// \sa graphReader(TGR& graph, const std::string& fn)
     2088  /// \sa graphReader(TGR& graph, const char* fn)
     2089  template <typename TGR>
     2090  GraphReader<TGR> graphReader(TGR& graph, std::istream& is) {
     2091    GraphReader<TGR> tmp(graph, is);
     2092    return tmp;
     2093  }
     2094
    20362095  /// \brief Return a \ref GraphReader class
    20372096  ///
    20382097  /// This function just returns a \ref GraphReader class.
    20392098  /// \relates GraphReader
    2040   template <typename Graph>
    2041   GraphReader<Graph> graphReader(Graph& graph, std::istream& is) {
    2042     GraphReader<Graph> tmp(graph, is);
     2099  /// \sa graphReader(TGR& graph, std::istream& is)
     2100  template <typename TGR>
     2101  GraphReader<TGR> graphReader(TGR& graph, const std::string& fn) {
     2102    GraphReader<TGR> tmp(graph, fn);
    20432103    return tmp;
    20442104  }
     
    20482108  /// This function just returns a \ref GraphReader class.
    20492109  /// \relates GraphReader
    2050   template <typename Graph>
    2051   GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) {
    2052     GraphReader<Graph> tmp(graph, fn);
    2053     return tmp;
    2054   }
    2055 
    2056   /// \brief Return a \ref GraphReader class
    2057   ///
    2058   /// This function just returns a \ref GraphReader class.
    2059   /// \relates GraphReader
    2060   template <typename Graph>
    2061   GraphReader<Graph> graphReader(Graph& graph, const char* fn) {
    2062     GraphReader<Graph> tmp(graph, fn);
     2110  /// \sa graphReader(TGR& graph, std::istream& is)
     2111  template <typename TGR>
     2112  GraphReader<TGR> graphReader(TGR& graph, const char* fn) {
     2113    GraphReader<TGR> tmp(graph, fn);
    20632114    return tmp;
    20642115  }
     
    23172368  };
    23182369
     2370  /// \ingroup lemon_io
     2371  ///
    23192372  /// \brief Return a \ref SectionReader class
    23202373  ///
    23212374  /// This function just returns a \ref SectionReader class.
     2375  ///
     2376  /// Please see SectionReader documentation about the custom section
     2377  /// input.
     2378  ///
    23222379  /// \relates SectionReader
     2380  /// \sa sectionReader(const std::string& fn)
     2381  /// \sa sectionReader(const char *fn)
    23232382  inline SectionReader sectionReader(std::istream& is) {
    23242383    SectionReader tmp(is);
     
    23302389  /// This function just returns a \ref SectionReader class.
    23312390  /// \relates SectionReader
     2391  /// \sa sectionReader(std::istream& is)
    23322392  inline SectionReader sectionReader(const std::string& fn) {
    23332393    SectionReader tmp(fn);
     
    23392399  /// This function just returns a \ref SectionReader class.
    23402400  /// \relates SectionReader
     2401  /// \sa sectionReader(std::istream& is)
    23412402  inline SectionReader sectionReader(const char* fn) {
    23422403    SectionReader tmp(fn);
Note: See TracChangeset for help on using the changeset viewer.