lemon/dimacs.h
changeset 395 0c5dd7ceda03
parent 387 24a2c6ee6cb0
child 440 88ed40ad0d4f
equal deleted inserted replaced
2:e424429ffc11 3:69deebfc2863
    29 /// \file
    29 /// \file
    30 /// \brief DIMACS file format reader.
    30 /// \brief DIMACS file format reader.
    31 
    31 
    32 namespace lemon {
    32 namespace lemon {
    33 
    33 
    34   ///@defgroup dimacs_group DIMACS format
       
    35   ///\brief Read and write files in DIMACS format
       
    36   ///
       
    37   ///Tools to read a digraph from or write it to a file in DIMACS format
       
    38   ///data
       
    39   ///\ingroup io_group
       
    40 
       
    41   /// \addtogroup dimacs_group
    34   /// \addtogroup dimacs_group
    42   /// @{
    35   /// @{
    43 
       
    44 
    36 
    45   /// DIMACS file type descriptor.
    37   /// DIMACS file type descriptor.
    46   struct DimacsDescriptor
    38   struct DimacsDescriptor
    47   {
    39   {
    48     ///File type enum
    40     ///File type enum
    50       {
    42       {
    51         NONE, MIN, MAX, SP, MAT
    43         NONE, MIN, MAX, SP, MAT
    52       };
    44       };
    53     ///The file type
    45     ///The file type
    54     Type type;
    46     Type type;
    55     ///The number of nodes on the graph
    47     ///The number of nodes in the graph
    56     int nodeNum;
    48     int nodeNum;
    57     ///The number of edges on the graph
    49     ///The number of edges in the graph
    58     int edgeNum;
    50     int edgeNum;
    59     int lineShift;
    51     int lineShift;
    60     /// Constructor. Sets the type to NONE.
    52     /// Constructor. Sets the type to NONE.
    61     DimacsDescriptor() : type(NONE) {}
    53     DimacsDescriptor() : type(NONE) {}
    62   };
    54   };
    63 
    55 
    64   ///Discover the type of a DIMACS file
    56   ///Discover the type of a DIMACS file
    65 
    57 
    66   ///It starts seeking the begining of the file for the problem type
    58   ///It starts seeking the begining of the file for the problem type
    67   ///and size info. The found date is returned in a special struct
    59   ///and size info. The found data is returned in a special struct
    68   ///that can be evaluated and passed to the appropriate reader
    60   ///that can be evaluated and passed to the appropriate reader
    69   ///function.
    61   ///function.
    70   DimacsDescriptor dimacsType(std::istream& is)
    62   DimacsDescriptor dimacsType(std::istream& is)
    71   {
    63   {
    72     DimacsDescriptor r;
    64     DimacsDescriptor r;
   103     throw FormatError("Missing problem type declaration.");
    95     throw FormatError("Missing problem type declaration.");
   104   }
    96   }
   105 
    97 
   106 
    98 
   107 
    99 
   108   /// DIMACS min cost flow reader function.
   100   /// DIMACS minimum cost flow reader function.
   109   ///
   101   ///
   110   /// This function reads a min cost flow instance from DIMACS format,
   102   /// This function reads a minimum cost flow instance from DIMACS format,
   111   /// i.e. from DIMACS files having a line starting with
   103   /// i.e. from a DIMACS file having a line starting with
   112   /// \code
   104   /// \code
   113   ///   p min
   105   ///   p min
   114   /// \endcode
   106   /// \endcode
   115   /// At the beginning, \c g is cleared by \c g.clear(). The supply
   107   /// At the beginning, \c g is cleared by \c g.clear(). The supply
   116   /// amount of the nodes are written to \c supply (signed). The
   108   /// amount of the nodes are written to \c supply (signed). The
   228         break;
   220         break;
   229       }
   221       }
   230     }
   222     }
   231   }
   223   }
   232 
   224 
   233   /// DIMACS max flow reader function.
   225   /// DIMACS maximum flow reader function.
   234   ///
   226   ///
   235   /// This function reads a max flow instance from DIMACS format,
   227   /// This function reads a maximum flow instance from DIMACS format,
   236   /// i.e. from DIMACS files having a line starting with
   228   /// i.e. from a DIMACS file having a line starting with
   237   /// \code
   229   /// \code
   238   ///   p max
   230   ///   p max
   239   /// \endcode
   231   /// \endcode
   240   /// At the beginning, \c g is cleared by \c g.clear(). The arc
   232   /// At the beginning, \c g is cleared by \c g.clear(). The arc
   241   /// capacities are written to \c capacity and \c s and \c t are
   233   /// capacities are written to \c capacity and \c s and \c t are
   257   }
   249   }
   258 
   250 
   259   /// DIMACS shortest path reader function.
   251   /// DIMACS shortest path reader function.
   260   ///
   252   ///
   261   /// This function reads a shortest path instance from DIMACS format,
   253   /// This function reads a shortest path instance from DIMACS format,
   262   /// i.e. from DIMACS files having a line starting with
   254   /// i.e. from a DIMACS file having a line starting with
   263   /// \code
   255   /// \code
   264   ///   p sp
   256   ///   p sp
   265   /// \endcode
   257   /// \endcode
   266   /// At the beginning, \c g is cleared by \c g.clear(). The arc
   258   /// At the beginning, \c g is cleared by \c g.clear(). The arc
   267   /// lengths are written to \c lenght and \c s is set to the
   259   /// lengths are written to \c length and \c s is set to the
   268   /// source node.
   260   /// source node.
   269   ///
   261   ///
   270   /// If the file type was previously evaluated by dimacsType(), then
   262   /// If the file type was previously evaluated by dimacsType(), then
   271   /// the descriptor struct should be given by the \c dest parameter.
   263   /// the descriptor struct should be given by the \c dest parameter.
   272   template<typename Digraph, typename LengthMap>
   264   template<typename Digraph, typename LengthMap>