lemon/graph_writer.h
changeset 1830 ffd6d50fb155
parent 1540 7d028a73d7f2
child 1875 98698b69a902
equal deleted inserted replaced
3:e42449795df4 4:1a0ca208effc
   282     
   282     
   283     AttributeWriter<WriterTraits> attribute_writer;
   283     AttributeWriter<WriterTraits> attribute_writer;
   284   };
   284   };
   285 
   285 
   286 
   286 
   287   ///\anchor writeGraph()
   287 
   288   ///
       
   289   /// \brief Write a graph to the output.
   288   /// \brief Write a graph to the output.
   290   ///
   289   ///
   291   /// Write a graph to the output.
   290   /// It is a helper function to write a graph to the given output
       
   291   /// stream. It gives back a GraphWriter object and this object
       
   292   /// can write more maps, labeled nodes and edges and attributes.
       
   293   /// \warning Do not forget to call the \c run() function.
       
   294   ///
   292   /// \param os The output stream.
   295   /// \param os The output stream.
   293   /// \param g The graph.
   296   /// \param g The graph.
   294   template<typename Graph>
   297   template <typename Graph>
   295   void writeGraph(std::ostream& os, const Graph &g) {
   298   GraphWriter<Graph> graphWriter(std::ostream& os, const Graph &g) {
   296     GraphWriter<Graph> writer(os, g);
   299     return GraphWriter<Graph>(os, g);
   297     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   298     writer.writeNodeMap("id", nodeIdMap);
       
   299     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   300     writer.writeEdgeMap("id", edgeIdMap);
       
   301     writer.run();
       
   302   }
   300   }
   303 
   301 
   304   /// \brief Write a capacitated graph instance to the output.
   302   /// \brief Write a graph to the output.
   305   /// 
   303   ///
   306   /// Write a capacitated graph (graph+capacity on the
   304   /// It is a helper function to write a graph to the given output
   307   /// edges) to the output.
   305   /// file. It gives back a GraphWriter object and this object
   308   /// \param os The output stream.
   306   /// can write more maps, labeled nodes and edges and attributes.
       
   307   /// \warning Do not forget to call the \c run() function.
       
   308   ///
       
   309   /// \param fn The filename.
   309   /// \param g The graph.
   310   /// \param g The graph.
   310   /// \param capacity The capacity map.
   311   template <typename Graph>
   311   template<typename Graph, typename CapacityMap>
   312   GraphWriter<Graph> graphWriter(const std::string& fn, const Graph &g) {
   312   void writeGraph(std::ostream& os, const Graph &g, 
   313     return GraphWriter<Graph>(fn, g);
   313 		  const CapacityMap& capacity) {
       
   314     GraphWriter<Graph> writer(os, g);
       
   315     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   316     writer.writeNodeMap("id", nodeIdMap);
       
   317     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   318     writer.writeEdgeMap("id", edgeIdMap);
       
   319     writer.writeEdgeMap("capacity", capacity);
       
   320     writer.run();
       
   321   }
       
   322 
       
   323   /// \brief Write a shortest path instance to the output.
       
   324   /// 
       
   325   /// Write a shortest path instance (graph+capacity on the
       
   326   /// edges+designated source) to the output.
       
   327   /// \param os The output stream.
       
   328   /// \param g The graph.
       
   329   /// \param capacity The capacity map.
       
   330   /// \param s The source node.
       
   331   template<typename Graph, typename CapacityMap>
       
   332   void writeGraph(std::ostream& os, const Graph &g, 
       
   333 		  const CapacityMap& capacity, const typename Graph::Node &s) {
       
   334     GraphWriter<Graph> writer(os, g);
       
   335     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   336     writer.writeNodeMap("id", nodeIdMap);
       
   337     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   338     writer.writeEdgeMap("id", edgeIdMap);
       
   339     writer.writeEdgeMap("capacity", capacity);
       
   340     writer.writeNode("source", s);
       
   341     writer.run();
       
   342   }
       
   343 
       
   344 
       
   345   /// \brief Write a max flow instance to the output.
       
   346   ///
       
   347   /// Write a max flow instance (graph+capacity on the
       
   348   /// edges+designated source and target) to the output.
       
   349   ///
       
   350   /// \param os The output stream.
       
   351   /// \param g The graph.
       
   352   /// \param capacity The capacity map.
       
   353   /// \param s The source node.
       
   354   /// \param t The target node.
       
   355   template<typename Graph, typename CapacityMap>
       
   356   void writeGraph(std::ostream& os, const Graph &g, 
       
   357 		  const CapacityMap& capacity, const typename Graph::Node &s,
       
   358 		  const typename Graph::Node &t) {
       
   359     GraphWriter<Graph> writer(os, g);
       
   360     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   361     writer.writeNodeMap("id", nodeIdMap);
       
   362     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   363     writer.writeEdgeMap("id", edgeIdMap);
       
   364     writer.writeEdgeMap("capacity", capacity);
       
   365     writer.writeNode("source", s);
       
   366     writer.writeNode("target", t);
       
   367     writer.run();
       
   368   }
       
   369 
       
   370   /// \brief Write a min cost flow instance to the output.
       
   371   ///
       
   372   /// Write a min cost flow instance (graph+capacity on the edges+cost
       
   373   /// function on the edges+designated source and target) to the output.
       
   374   ///
       
   375   /// \param os The output stream.
       
   376   /// \param g The graph.
       
   377   /// \param capacity The capacity map.
       
   378   /// \param s The source node.
       
   379   /// \param t The target node.
       
   380   /// \param cost The cost map.
       
   381   template<typename Graph, typename CapacityMap, typename CostMap>
       
   382   void writeGraph(std::ostream& os, const Graph &g, 
       
   383 		  const CapacityMap& capacity, const typename Graph::Node &s,
       
   384 		  const typename Graph::Node &t, const CostMap& cost) {
       
   385     GraphWriter<Graph> writer(os, g);
       
   386     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   387     writer.writeNodeMap("id", nodeIdMap);
       
   388     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   389     writer.writeEdgeMap("id", edgeIdMap);
       
   390     writer.writeEdgeMap("capacity", capacity);
       
   391     writer.writeEdgeMap("cost", cost);
       
   392     writer.writeNode("source", s);
       
   393     writer.writeNode("target", t);
       
   394     writer.run();
       
   395   }
   314   }
   396 
   315 
   397   /// \brief The undirected graph writer class.
   316   /// \brief The undirected graph writer class.
   398   ///
   317   ///
   399   /// The \c UndirGraphWriter class provides the undir graph output. To write 
   318   /// The \c UndirGraphWriter class provides the undir graph output. To write 
   682     AttributeWriter<WriterTraits> attribute_writer;
   601     AttributeWriter<WriterTraits> attribute_writer;
   683   };
   602   };
   684 
   603 
   685   /// \brief Write an undirected graph to the output.
   604   /// \brief Write an undirected graph to the output.
   686   ///
   605   ///
   687   /// Write an undirected graph to the output.
   606   /// It is a helper function to write an undirected graph to the given output
       
   607   /// stream. It gives back an UndirGraphWriter object and this object
       
   608   /// can write more maps, labeled nodes and edges and attributes.
       
   609   /// \warning Do not forget to call the \c run() function.
       
   610   ///
   688   /// \param os The output stream.
   611   /// \param os The output stream.
   689   /// \param g The graph.
   612   /// \param g The graph.
   690   template<typename Graph>
   613   template <typename Graph>
   691   void writeUndirGraph(std::ostream& os, const Graph &g) {
   614   UndirGraphWriter<Graph> undirGraphWriter(std::ostream& os, const Graph &g) {
   692     UndirGraphWriter<Graph> writer(os, g);
   615     return UndirGraphWriter<Graph>(os, g);
   693     writer.run();
       
   694   }
   616   }
   695 
   617 
   696   /// \brief Write an undirected multigraph (undirected graph + capacity
   618   /// \brief Write an undirected graph to the output.
   697   /// map on the edges) to the output.
   619   ///
   698   ///
   620   /// It is a helper function to write an undirected graph to the given output
   699   /// Write an undirected multigraph (undirected graph + capacity
   621   /// file. It gives back an UndirGraphWriter object and this object
   700   /// map on the edges) to the output.
   622   /// can write more maps, labeled nodes, edges, undirected edges and 
   701   /// \param os The output stream.
   623   /// attributes.
       
   624   ///
       
   625   /// \warning Do not forget to call the \c run() function.
       
   626   ///
       
   627   /// \param fn The output file.
   702   /// \param g The graph.
   628   /// \param g The graph.
   703   /// \param capacity The capacity undirected map.
   629   template <typename Graph>
   704   template<typename Graph, typename CapacityMap>
   630   UndirGraphWriter<Graph> undirGraphWriter(const std::string& fn, 
   705   void writeUndirGraph(std::ostream& os, const Graph &g, 
   631 					   const Graph &g) {
   706 		       const CapacityMap& capacity) {
   632     return UndirGraphWriter<Graph>(fn, g);
   707     UndirGraphWriter<Graph> writer(os, g);
       
   708     writer.writeUndirEdgeMap("capacity", capacity);
       
   709     writer.run();
       
   710   }
   633   }
   711 
   634 
   712 
       
   713   /// @}
   635   /// @}
   714 
   636 
   715 }
   637 }
   716 
   638 
   717 #endif
   639 #endif