COIN-OR::LEMON - Graph Library

Ticket #35: digraph_reader_doc.patch

File digraph_reader_doc.patch, 12.8 KB (added by Balazs Dezso, 17 years ago)
  • lemon/lgf_reader.h

    # HG changeset patch
    # User Balazs Dezso <deba@inf.elte.hu>
    # Date 1210511869 -7200
    # Node ID f6b69e8d7fa38c99540c7affa9ecf6572d473d16
    # Parent  5c3604513ed0256e35e5fd50c54cd0e37362397e
    Documentation for DigraphReader
    
    diff -r 5c3604513ed0 -r f6b69e8d7fa3 lemon/lgf_reader.h
    a b  
    295295    }
    296296   
    297297  }
    298  
    299   /// \e
     298
     299  /// \ingroup lemon_io
     300  /// 
     301  /// \brief LGF reader for directed graphs
     302  ///
     303  /// The \e LGF (LEMON graph file) format is the default file format
     304  /// of the LEMON library. It is a text based, section oriented
     305  /// format, which defines some standard sections for storing graphs
     306  /// in text files. Each line with \c '#' first non-whitespace
     307  /// character are denoted as comment line. Each section starts with
     308  /// a header line, these lines starts with \c '@' character and the
     309  /// name of section type.  The standard sections are \c \@nodes, \c
     310  /// \@arcs or \c \@edges (these two names are completely equivalent)
     311  /// and \@attributes. Each header lines could contain an optional
     312  /// name, which can be use to distinguish the sections of the same
     313  /// type.
     314  ///
     315  /// The \@nodes section stores node maps for a node set. The first
     316  /// line comprises from the names of the maps, these map names are
     317  /// sequences of non-whitespace characters. One of the maps should
     318  /// be called \c "label", which plays specific role in the file.
     319  /// Each following non-empty line, until a line starting with \c '@'
     320  /// character, describes a node in the graph. These lines contain
     321  /// the values of the node maps associated to the current node. The
     322  /// values are plain or quoted tokens, a plain token is a sequence
     323  /// of a non-whitespace characters. A quoted token is a character
     324  /// sequence surrounded by double quotes, and the sequence could
     325  /// contain several escape sequences.
     326  ///
     327  /// The \c \@arcs or \c \@edges section is very similar to the \c
     328  /// \@nodes section, it starts with a line consists from the names of
     329  /// the arc maps, the \c "label" map is also necessary. The
     330  /// following lines contain the description of the arcs, but before
     331  /// the map values the line comprises the source and target of the
     332  /// arc, these tokens should be occured in the \c \@nodes section as
     333  /// a node label.
     334  ///
     335  /// The \c \@attrbiutes section contains key-value pairs, each line
     336  /// starts with an attribute name, and then an attribute value. The
     337  /// name is a sequence of non-whitespace characters, while the value
     338  /// is plain or quoted string literal. The value could be a node or
     339  /// arc label.
     340  ///
     341  ///\code
     342  /// @nodes
     343  /// label   coordinates size    title
     344  /// 1       (10,20)     10      "First node"
     345  /// 2       (80,80)     8       "Second node"
     346  /// 3       (40,10)     10      "Third node"
     347  /// @arcs
     348  ///         capacity
     349  /// 1   2   16
     350  /// 1   3   12
     351  /// 2   3   18
     352  /// @attributes
     353  /// source 1
     354  /// target 3
     355  /// caption "LEMON test digraph"
     356  ///\endcode
     357  ///
     358  /// The reading method is organized as batch processing. The user
     359  /// creates a reader object, then several reading rules can be added
     360  /// to the reader, and finally executes the reading with the \c
     361  /// run() member function. A map reading rule can be added to the
     362  /// reader with the \c nodeMap() or \c arcMap() members. The
     363  /// optional converter parameter can be a standard functor, which
     364  /// converts an std::string to the value type of the map, if it is
     365  /// set, it determines how the read string literal is converted to
     366  /// the map's value type. If the functor is not set, then the
     367  /// default method will perform this task. One map could be read in
     368  /// multiple map objects, if more reading rule is used with the same
     369  /// map name. The \c attribute(), \c node() and \c arc() functions
     370  /// can be used to add attribute reading rules.
     371  ///
     372  ///\code
     373  ///     DigraphReader<Digraph>(std::cin, digraph).
     374  ///       nodeMap("coordinates", coord_map).
     375  ///       arcMap("capacity", cap_map).
     376  ///       node("source", src).
     377  ///       node("target", trg).
     378  ///       attribute("caption", caption).
     379  ///       run();
     380  ///\endcode
     381  ///
     382  /// In the default behaviour the reader uses the first section in
     383  /// the file of the proper type. If a section has an optional name,
     384  /// then it can be select to read with the \c nodes(), \c arcs() or
     385  /// \c attributes() functions.
     386  ///
     387  /// The \c useNodes() and \c useArcs() functions can be used to
     388  /// specify that the nodes or arcs should not be constructed during
     389  /// the reading, the argument of these functions is a node map or
     390  /// arc map, which determines the label map for the items. One
     391  /// application of these member is the multipass reading, which is a
     392  /// very important approach in the LEMON IO, because several tasks
     393  /// are solveable just with this technic. If two \e \@arcs should be
     394  /// read from the file (for example transport matrix), then it could
     395  /// be made with two phases. The first phase reads the node set and
     396  /// one of the arc set, and it should read the label column to a
     397  /// map. The second phase could read the second arc set into an \e
     398  /// ArcSet class (\c SmartArcSet or \c ListArcSet), the previously
     399  /// read label node map should be given to the \c useNodes()
     400  /// functions. An other multipass application is reading path into
     401  /// node map or arc map. It is impossible in singlepass, because the
     402  /// arcs are not constructed yet, when the node maps are read.
    300403  template <typename _Digraph>
    301404  class DigraphReader {
    302405  public:
     
    341444
    342445  public:
    343446
    344     /// \e
     447    /// \brief Constructor
     448    ///
     449    /// Construct a directed graph reader, which reads from the given
     450    /// input stream.
    345451    DigraphReader(std::istream& is, Digraph& digraph)
    346452      : _is(&is), local_is(false), _digraph(digraph),
    347453        _use_nodes(false), _use_arcs(false) {}
    348454
    349     /// \e
     455    /// \brief Constructor
     456    ///
     457    /// Construct a directed graph reader, which reads from the given
     458    /// file.
    350459    DigraphReader(const std::string& fn, Digraph& digraph)
    351460      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
    352461        _use_nodes(false), _use_arcs(false) {}
    353 
    354 
    355     /// \e
     462   
     463    /// \brief Constructor
     464    ///
     465    /// Construct a directed graph reader, which reads from the given
     466    /// file.
    356467    DigraphReader(const char* fn, Digraph& digraph)
    357468      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
    358469        _use_nodes(false), _use_arcs(false) {}
    359470
    360     /// \e
     471    /// \brief Copy constructor
     472    ///
     473    /// The copy constructor transfers all data from the other reader,
     474    /// therefore the copied reader will not be useable more.
    361475    DigraphReader(DigraphReader& other)
    362476      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
    363477        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
     
    377491      _attributes_caption = other._attributes_caption;
    378492    }
    379493
    380     /// \e
     494    /// \brief Destructor
    381495    ~DigraphReader() {
    382496      for (typename NodeMaps::iterator it = _node_maps.begin();
    383497           it != _node_maps.end(); ++it) {
     
    406520
    407521  public:
    408522
    409     /// \e
     523    /// \name Reading rules
     524    /// @{
     525   
     526    /// \brief Node map reading rule
     527    ///
     528    /// Add a node map reading rule to the reader.
    410529    template <typename Map>
    411530    DigraphReader& nodeMap(const std::string& caption, Map& map) {
    412531      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
     
    416535      return *this;
    417536    }
    418537
    419     /// \e
     538    /// \brief Node map reading rule
     539    ///
     540    /// Add a node map reading rule with specialized converter to the
     541    /// reader.
    420542    template <typename Map, typename Converter>
    421543    DigraphReader& nodeMap(const std::string& caption, Map& map,
    422544                           const Converter& converter = Converter()) {
     
    427549      return *this;
    428550    }
    429551
    430     /// \e
     552    /// \brief Arc map reading rule
     553    ///
     554    /// Add an arc map reading rule to the reader.
    431555    template <typename Map>
    432556    DigraphReader& arcMap(const std::string& caption, Map& map) {
    433557      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
     
    437561      return *this;
    438562    }
    439563
    440     /// \e
     564    /// \brief Arc map reading rule
     565    ///
     566    /// Add an arc map reading rule with specialized converter to the
     567    /// reader.
    441568    template <typename Map, typename Converter>
    442569    DigraphReader& arcMap(const std::string& caption, Map& map,
    443570                          const Converter& converter = Converter()) {
     
    448575      return *this;
    449576    }
    450577
    451     /// \e
     578    /// \brief Attribute reading rule
     579    ///
     580    /// Add an attribute reading rule to the reader.
    452581    template <typename Value>
    453582    DigraphReader& attribute(const std::string& caption, Value& value) {
    454583      _reader_bits::ValueStorageBase* storage =
     
    457586      return *this;
    458587    }
    459588
    460     /// \e
     589    /// \brief Attribute reading rule
     590    ///
     591    /// Add an attribute reading rule with specialized converter to the
     592    /// reader.
    461593    template <typename Value, typename Converter>
    462594    DigraphReader& attribute(const std::string& caption, Value& value,
    463595                             const Converter& converter = Converter()) {
     
    467599      return *this;
    468600    }
    469601
    470     /// \e
     602    /// \brief Node reading rule
     603    ///
     604    /// Add a node reading rule with specialized converter to the
     605    /// reader.
    471606    DigraphReader& node(const std::string& caption, Node& node) {
    472607      typedef _reader_bits::MapLookUpConverter<Node> Converter;
    473608      Converter converter(_node_index);
     
    477612      return *this;
    478613    }
    479614
    480     /// \e
     615    /// \brief Arc reading rule
     616    ///
     617    /// Add an arc reading rule with specialized converter to the
     618    /// reader.
    481619    DigraphReader& arc(const std::string& caption, Arc& arc) {
    482620      typedef _reader_bits::MapLookUpConverter<Arc> Converter;
    483621      Converter converter(_arc_index);
     
    487625      return *this;
    488626    }
    489627
    490     /// \e
     628    /// @}
     629
     630    /// \name Select section by name
     631    /// @{
     632
     633    /// \brief Set \c \@nodes section to be read
     634    ///
     635    /// Set \c \@nodes section to be read
    491636    DigraphReader& nodes(const std::string& caption) {
    492637      _nodes_caption = caption;
    493638      return *this;
    494639    }
    495640
    496     /// \e
     641    /// \brief Set \c \@arcs section to be read
     642    ///
     643    /// Set \c \@arcs section to be read
    497644    DigraphReader& arcs(const std::string& caption) {
    498645      _arcs_caption = caption;
    499646      return *this;
    500647    }
    501648
    502     /// \e
     649    /// \brief Set \c \@attributes section to be read
     650    ///
     651    /// Set \c \@attributes section to be read
    503652    DigraphReader& attributes(const std::string& caption) {
    504653      _attributes_caption = caption;
    505654      return *this;
    506655    }
    507656
    508     /// \e
     657    /// @}
     658
     659    /// \name Using previously constructed node or arc set
     660    /// @{
     661
     662    /// \brief Use previously constructed node set
     663    ///
     664    /// Use previously constructed node set, and specify the node
     665    /// label map.
    509666    template <typename Map>
    510667    DigraphReader& useNodes(const Map& map) {
    511668      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
     
    518675      return *this;
    519676    }
    520677
    521     /// \e
     678    /// \brief Use previously constructed node set
     679    ///
     680    /// Use previously constructed node set, and specify the node
     681    /// label map and a functor which converts the label map values to
     682    /// std::string.
    522683    template <typename Map, typename Converter>
    523684    DigraphReader& useNodes(const Map& map,
    524685                            const Converter& converter = Converter()) {
     
    531692      return *this;
    532693    }
    533694
    534     /// \e
     695    /// \brief Use previously constructed arc set
     696    ///
     697    /// Use previously constructed arc set, and specify the arc
     698    /// label map.
    535699    template <typename Map>
    536700    DigraphReader& useArcs(const Map& map) {
    537701      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
     
    544708      return *this;
    545709    }
    546710
    547     /// \e
     711    /// \brief Use previously constructed arc set
     712    ///
     713    /// Use previously constructed arc set, and specify the arc
     714    /// label map and a functor which converts the label map values to
     715    /// std::string.
    548716    template <typename Map, typename Converter>
    549717    DigraphReader& useArcs(const Map& map,
    550718                            const Converter& converter = Converter()) {
     
    556724      }
    557725      return *this;
    558726    }
     727
     728    /// @}
    559729
    560730  private:
    561731
     
    827997    }
    828998
    829999  public:
    830    
    831     /// \e
     1000
     1001    /// \name Execution of the reader   
     1002    /// @{
     1003
     1004    /// \brief Start the batch processing
     1005    ///
     1006    /// This function starts the batch processing
    8321007    void run() {
    8331008     
    8341009      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
     
    8911066      }
    8921067
    8931068    }
     1069
     1070    /// @}
    8941071   
    8951072  };
    8961073