lemon/graph_reader.h
changeset 1824 3a15b39a7c78
parent 1705 3f63d9db307b
child 1875 98698b69a902
equal deleted inserted replaced
4:899e9f96fe8b 5:a6e85bc18d0f
   337     
   337     
   338     AttributeReader<ReaderTraits> attribute_reader;
   338     AttributeReader<ReaderTraits> attribute_reader;
   339   };
   339   };
   340 
   340 
   341 
   341 
   342   ///\anchor readGraph()
   342   /// \brief Read a graph from the input.
   343   ///
   343   ///
   344   /// \brief Read a graph from an input stream.
   344   /// It is a helper function to read a graph from the given input
   345   ///
   345   /// stream. It gives back an GraphReader object and this object
   346   /// Read a graph from an input stream.
   346   /// can read more maps, labeled nodes, edges and attributes.
       
   347   ///
       
   348   /// \warning Do not forget to call the \c run() function.
       
   349   ///
   347   /// \param is The input stream.
   350   /// \param is The input stream.
   348   /// \param g The graph.
   351   /// \param g The graph.
   349   template<typename Graph>
   352   template<typename Graph>
   350   void readGraph(std::istream& is, Graph &g) {
   353   GraphReader<Graph> graphReader(std::istream& is, Graph &g) {
   351     GraphReader<Graph> reader(is, g);
   354     return GraphReader<Graph>(is, g);
   352     reader.run();
       
   353   }
   355   }
   354 
   356 
   355   /// \brief Read a capacitated graph instance from an input stream.
   357   /// \brief Read a graph from the input.
   356   /// 
   358   ///
   357   /// Read a capacitated graph (graph+capacity on the
   359   /// It is a helper function to read a graph from the given input
   358   /// edges) from an input stream.
   360   /// file. It gives back an GraphReader object and this object
   359   /// \param is The input stream.
   361   /// can read more maps, labeled nodes, edges and attributes.
       
   362   ///
       
   363   /// \warning Do not forget to call the \c run() function.
       
   364   ///
       
   365   /// \param fn The input filename.
   360   /// \param g The graph.
   366   /// \param g The graph.
   361   /// \param capacity The capacity map.
   367   template<typename Graph>
   362   template<typename Graph, typename CapacityMap>
   368   GraphReader<Graph> graphReader(const std::string& fn, Graph &g) {
   363   void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
   369     return GraphReader<Graph>(fn, g);
   364     GraphReader<Graph> reader(is, g);
       
   365     reader.readEdgeMap("capacity", capacity);
       
   366     reader.run();
       
   367   }
   370   }
   368 
   371 
   369   /// \brief Read a shortest path instance from an input stream.
   372   /// \brief The undirected graph reader class.
   370   /// 
       
   371   /// Read a shortest path instance (graph+capacity on the
       
   372   /// edges+designated source) from an input stream.
       
   373   /// \param is The input stream.
       
   374   /// \param g The graph.
       
   375   /// \param capacity The capacity map.
       
   376   /// \param s The source node.
       
   377   template<typename Graph, typename CapacityMap>
       
   378   void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
       
   379 		  typename Graph::Node &s) {
       
   380     GraphReader<Graph> reader(is, g);
       
   381     reader.readEdgeMap("capacity", capacity);
       
   382     reader.readNode("source", s);
       
   383     reader.run();
       
   384   }
       
   385 
       
   386 
       
   387 
       
   388   /// \brief Read a max flow instance from an input stream.
       
   389   ///
       
   390   /// Read a max flow instance (graph+capacity on the
       
   391   /// edges+designated source and target) from an input stream.
       
   392   ///
       
   393   /// \param is The input stream.
       
   394   /// \param g The graph.
       
   395   /// \param capacity The capacity map.
       
   396   /// \param s The source node.
       
   397   /// \param t The target node.
       
   398   template<typename Graph, typename CapacityMap>
       
   399   void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
       
   400 		  typename Graph::Node &s, typename Graph::Node &t) {
       
   401     GraphReader<Graph> reader(is, g);
       
   402     reader.readEdgeMap("capacity", capacity);
       
   403     reader.readNode("source", s);
       
   404     reader.readNode("target", t);
       
   405     reader.run();
       
   406   }
       
   407 
       
   408   /// \brief Read a min cost flow instance from an input stream.
       
   409   ///
       
   410   /// Read a min cost flow instance (graph+capacity on the edges+cost
       
   411   /// function on the edges+designated source and target) from an input stream.
       
   412   ///
       
   413   /// \param is The input stream.
       
   414   /// \param g The graph.
       
   415   /// \param capacity The capacity map.
       
   416   /// \param s The source node.
       
   417   /// \param t The target node.
       
   418   /// \param cost The cost map.
       
   419   template<typename Graph, typename CapacityMap, typename CostMap>
       
   420   void readGraph(std::istream& is, Graph &g, CapacityMap& capacity, 
       
   421 		  typename Graph::Node &s, typename Graph::Node &t, 
       
   422 		  CostMap& cost) {
       
   423     GraphReader<Graph> reader(is, g);
       
   424     reader.readEdgeMap("capacity", capacity);
       
   425     reader.readEdgeMap("cost", cost);
       
   426     reader.readNode("source", s);
       
   427     reader.readNode("target", t);
       
   428     reader.run();
       
   429   }
       
   430 
       
   431 
       
   432   /// \brief The undir graph reader class.
       
   433   ///
   373   ///
   434   /// The \c UndirGraphReader class provides the graph input. 
   374   /// The \c UndirGraphReader class provides the graph input. 
   435   /// Before you read this documentation it might be useful to read the general
   375   /// Before you read this documentation it might be useful to read the general
   436   /// description of  \ref graph-io-page "Graph Input-Output".
   376   /// description of  \ref graph-io-page "Graph Input-Output".
   437   ///
   377   ///
   804     UndirEdgeReader<Graph> undir_edge_reader;
   744     UndirEdgeReader<Graph> undir_edge_reader;
   805     
   745     
   806     AttributeReader<ReaderTraits> attribute_reader;
   746     AttributeReader<ReaderTraits> attribute_reader;
   807   };
   747   };
   808 
   748 
   809   /// \brief Read an undirected graph from an input stream.
   749   /// \brief Read an undirected graph from the input.
   810   ///
   750   ///
   811   /// Read an undirected graph from an input stream.
   751   /// It is a helper function to read an undirected graph from the given input
       
   752   /// stream. It gives back an UndirGraphReader object and this object
       
   753   /// can read more maps, labeled nodes, edges, undirected edges and
       
   754   /// attributes.
       
   755   ///
       
   756   /// \warning Do not forget to call the \c run() function.
       
   757   ///
   812   /// \param is The input stream.
   758   /// \param is The input stream.
   813   /// \param g The graph.
   759   /// \param g The graph.
   814   template<typename Graph>
   760   template<typename Graph>
   815   void readUndirGraph(std::istream& is, Graph &g) {
   761   UndirGraphReader<Graph> undirGraphReader(std::istream& is, Graph &g) {
   816     UndirGraphReader<Graph> reader(is, g);
   762     return GraphReader<Graph>(is, g);
   817     reader.run();
       
   818   }
   763   }
   819 
   764 
   820   /// \brief Read an undirected multigraph (undirected graph + capacity
   765   /// \brief Read an undirected graph from the input.
   821   /// map on the edges) from an input stream.
   766   ///
   822   ///
   767   /// It is a helper function to read an undirected graph from the given input
   823   /// Read an undirected multigraph (undirected graph + capacity
   768   /// file. It gives back an UndirGraphReader object and this object
   824   /// map on the edges) from an input stream.
   769   /// can read more maps, labeled nodes, edges, undirected edges and 
   825   /// \param is The input stream.
   770   /// attributes.
       
   771   ///
       
   772   /// \warning Do not forget to call the \c run() function.
       
   773   ///
       
   774   /// \param fn The input filename.
   826   /// \param g The graph.
   775   /// \param g The graph.
   827   /// \param capacity The capacity map.
   776   template<typename Graph>
   828   template<typename Graph, typename CapacityMap>
   777   UndirGraphReader<Graph> undirGraphReader(const std::string& fn, Graph &g) {
   829   void readUndirGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
   778     return GraphReader<Graph>(fn, g);
   830     UndirGraphReader<Graph> reader(is, g);
       
   831     reader.readUndirEdgeMap("capacity", capacity);
       
   832     reader.run();
       
   833   }
   779   }
   834 
       
   835 
   780 
   836   /// @}
   781   /// @}
   837 }
   782 }
   838 
   783 
   839 #endif
   784 #endif