lemon/dimacs.h
changeset 1172 d7e25df22e88
parent 1092 dceba191c00d
parent 1157 332627dd249e
equal deleted inserted replaced
9:7c5a5480b551 12:5dba9eab020e
    23 #include <string>
    23 #include <string>
    24 #include <vector>
    24 #include <vector>
    25 #include <limits>
    25 #include <limits>
    26 #include <lemon/maps.h>
    26 #include <lemon/maps.h>
    27 #include <lemon/error.h>
    27 #include <lemon/error.h>
       
    28 
    28 /// \ingroup dimacs_group
    29 /// \ingroup dimacs_group
    29 /// \file
    30 /// \file
    30 /// \brief DIMACS file format reader.
    31 /// \brief DIMACS file format reader.
    31 
    32 
    32 namespace lemon {
    33 namespace lemon {
   120   /// \c std::numeric_limits<Capacity>::infinity() will be used if available,
   121   /// \c std::numeric_limits<Capacity>::infinity() will be used if available,
   121   /// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to
   122   /// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to
   122   /// a non-zero value, that value will be used as "infinite".
   123   /// a non-zero value, that value will be used as "infinite".
   123   ///
   124   ///
   124   /// If the file type was previously evaluated by dimacsType(), then
   125   /// If the file type was previously evaluated by dimacsType(), then
   125   /// the descriptor struct should be given by the \c dest parameter.
   126   /// the descriptor struct should be given by the \c desc parameter.
   126   template <typename Digraph, typename LowerMap,
   127   template <typename Digraph, typename LowerMap,
   127             typename CapacityMap, typename CostMap,
   128             typename CapacityMap, typename CostMap,
   128             typename SupplyMap>
   129             typename SupplyMap>
   129   void readDimacsMin(std::istream& is,
   130   void readDimacsMin(std::istream& is,
   130                      Digraph &g,
   131                      Digraph &g,
   274   /// \c std::numeric_limits<Capacity>::infinity() will be used if available,
   275   /// \c std::numeric_limits<Capacity>::infinity() will be used if available,
   275   /// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to
   276   /// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to
   276   /// a non-zero value, that value will be used as "infinite".
   277   /// a non-zero value, that value will be used as "infinite".
   277   ///
   278   ///
   278   /// If the file type was previously evaluated by dimacsType(), then
   279   /// If the file type was previously evaluated by dimacsType(), then
   279   /// the descriptor struct should be given by the \c dest parameter.
   280   /// the descriptor struct should be given by the \c desc parameter.
   280   template<typename Digraph, typename CapacityMap>
   281   template<typename Digraph, typename CapacityMap>
   281   void readDimacsMax(std::istream& is,
   282   void readDimacsMax(std::istream& is,
   282                      Digraph &g,
   283                      Digraph &g,
   283                      CapacityMap& capacity,
   284                      CapacityMap& capacity,
   284                      typename Digraph::Node &s,
   285                      typename Digraph::Node &s,
   301   /// At the beginning, \c g is cleared by \c g.clear(). The arc
   302   /// At the beginning, \c g is cleared by \c g.clear(). The arc
   302   /// lengths are written to the \c length arc map and \c s is set to the
   303   /// lengths are written to the \c length arc map and \c s is set to the
   303   /// source node.
   304   /// source node.
   304   ///
   305   ///
   305   /// If the file type was previously evaluated by dimacsType(), then
   306   /// If the file type was previously evaluated by dimacsType(), then
   306   /// the descriptor struct should be given by the \c dest parameter.
   307   /// the descriptor struct should be given by the \c desc parameter.
   307   template<typename Digraph, typename LengthMap>
   308   template<typename Digraph, typename LengthMap>
   308   void readDimacsSp(std::istream& is,
   309   void readDimacsSp(std::istream& is,
   309                     Digraph &g,
   310                     Digraph &g,
   310                     LengthMap& length,
   311                     LengthMap& length,
   311                     typename Digraph::Node &s,
   312                     typename Digraph::Node &s,
   332   /// \c std::numeric_limits<Capacity>::infinity() will be used if available,
   333   /// \c std::numeric_limits<Capacity>::infinity() will be used if available,
   333   /// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to
   334   /// \c std::numeric_limits<Capacity>::max() otherwise. If \c infty is set to
   334   /// a non-zero value, that value will be used as "infinite".
   335   /// a non-zero value, that value will be used as "infinite".
   335   ///
   336   ///
   336   /// If the file type was previously evaluated by dimacsType(), then
   337   /// If the file type was previously evaluated by dimacsType(), then
   337   /// the descriptor struct should be given by the \c dest parameter.
   338   /// the descriptor struct should be given by the \c desc parameter.
   338   template<typename Digraph, typename CapacityMap>
   339   template<typename Digraph, typename CapacityMap>
   339   void readDimacsCap(std::istream& is,
   340   void readDimacsCap(std::istream& is,
   340                      Digraph &g,
   341                      Digraph &g,
   341                      CapacityMap& capacity,
   342                      CapacityMap& capacity,
   342                      typename CapacityMap::Value infty = 0,
   343                      typename CapacityMap::Value infty = 0,
   343                      DimacsDescriptor desc=DimacsDescriptor()) {
   344                      DimacsDescriptor desc=DimacsDescriptor()) {
   344     typename Digraph::Node u,v;
   345     typename Digraph::Node u,v;
   345     if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is);
   346     if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is);
   346     if(desc.type!=DimacsDescriptor::MAX || desc.type!=DimacsDescriptor::SP)
   347     if(desc.type!=DimacsDescriptor::MAX && desc.type!=DimacsDescriptor::SP)
   347       throw FormatError("Problem type mismatch");
   348       throw FormatError("Problem type mismatch");
   348     _readDimacs(is, g, capacity, u, v, infty, desc);
   349     _readDimacs(is, g, capacity, u, v, infty, desc);
   349   }
   350   }
   350 
   351 
   351   template<typename Graph>
   352   template<typename Graph>
   372   ///   p mat
   373   ///   p mat
   373   /// \endcode
   374   /// \endcode
   374   /// At the beginning, \c g is cleared by \c g.clear().
   375   /// At the beginning, \c g is cleared by \c g.clear().
   375   ///
   376   ///
   376   /// If the file type was previously evaluated by dimacsType(), then
   377   /// If the file type was previously evaluated by dimacsType(), then
   377   /// the descriptor struct should be given by the \c dest parameter.
   378   /// the descriptor struct should be given by the \c desc parameter.
   378   template<typename Graph>
   379   template<typename Graph>
   379   void readDimacsMat(std::istream& is, Graph &g,
   380   void readDimacsMat(std::istream& is, Graph &g,
   380                      DimacsDescriptor desc=DimacsDescriptor())
   381                      DimacsDescriptor desc=DimacsDescriptor())
   381   {
   382   {
   382     if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is);
   383     if(desc.type==DimacsDescriptor::NONE) desc=dimacsType(is);