lemon/graph_writer.h
changeset 1534 b86aad11f842
parent 1526 8c14aa8f27a2
child 1540 7d028a73d7f2
equal deleted inserted replaced
1:0c1fbae3474f 2:60a8444ddaca
    15  */
    15  */
    16 
    16 
    17 ///\ingroup io_group
    17 ///\ingroup io_group
    18 ///\file
    18 ///\file
    19 ///\brief Lemon Graph Format writer.
    19 ///\brief Lemon Graph Format writer.
       
    20 ///
    20 
    21 
    21 #ifndef LEMON_GRAPH_WRITER_H
    22 #ifndef LEMON_GRAPH_WRITER_H
    22 #define LEMON_GRAPH_WRITER_H
    23 #define LEMON_GRAPH_WRITER_H
    23 
    24 
    24 #include <iostream>
    25 #include <iostream>
    34   /// \brief The graph writer class.
    35   /// \brief The graph writer class.
    35   ///
    36   ///
    36   /// The \c GraphWriter class provides the graph output. 
    37   /// The \c GraphWriter class provides the graph output. 
    37   /// Before you read this documentation it might be useful to read the general
    38   /// Before you read this documentation it might be useful to read the general
    38   /// description of  \ref graph-io-page "Graph Input-Output".
    39   /// description of  \ref graph-io-page "Graph Input-Output".
       
    40   /// If you don't need very sophisticated
       
    41   /// behaviour then you can use the versions of the public function
       
    42   /// \ref writeGraph() to output a graph (or a max flow instance etc).
       
    43   ///
    39   /// To write a graph
    44   /// To write a graph
    40   /// you should first give writing commands to the writer. You can declare
    45   /// you should first give writing commands to the writer. You can declare
    41   /// write commands as \c NodeMap or \c EdgeMap writing and labeled Node and
    46   /// write commands as \c NodeMap or \c EdgeMap writing and labeled Node and
    42   /// Edge writing.
    47   /// Edge writing.
    43   ///
    48   ///
   274     
   279     
   275     AttributeWriter<WriterTraits> attribute_writer;
   280     AttributeWriter<WriterTraits> attribute_writer;
   276   };
   281   };
   277 
   282 
   278 
   283 
       
   284   ///\anchor writeGraph()
       
   285   ///
   279   /// \brief Write a graph to the output.
   286   /// \brief Write a graph to the output.
   280   ///
   287   ///
   281   /// Write a graph to the output.
   288   /// Write a graph to the output.
       
   289   /// \param os The output stream.
       
   290   /// \param g The graph.
       
   291   template<typename Graph>
       
   292   void writeGraph(std::ostream& os, const Graph &g) {
       
   293     GraphWriter<Graph> writer(os, g);
       
   294     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   295     writer.writeNodeMap("id", nodeIdMap);
       
   296     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   297     writer.writeEdgeMap("id", edgeIdMap);
       
   298     writer.run();
       
   299   }
       
   300 
       
   301   /// \brief Write a capacitated graph instance to the output.
       
   302   /// 
       
   303   /// Write a capacitated graph (graph+capacity on the
       
   304   /// edges) to the output.
       
   305   /// \param os The output stream.
       
   306   /// \param g The graph.
       
   307   /// \param capacity The capacity map.
       
   308   template<typename Graph, typename CapacityMap>
       
   309   void writeGraph(std::ostream& os, const Graph &g, 
       
   310 		  const CapacityMap& capacity) {
       
   311     GraphWriter<Graph> writer(os, g);
       
   312     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   313     writer.writeNodeMap("id", nodeIdMap);
       
   314     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   315     writer.writeEdgeMap("id", edgeIdMap);
       
   316     writer.writeEdgeMap("capacity", capacity);
       
   317     writer.run();
       
   318   }
       
   319 
       
   320   /// \brief Write a shortest path instance to the output.
       
   321   /// 
       
   322   /// Write a shortest path instance (graph+capacity on the
       
   323   /// edges+designated source) to the output.
       
   324   /// \param os The output stream.
       
   325   /// \param g The graph.
       
   326   /// \param capacity The capacity map.
       
   327   /// \param s The source node.
       
   328   template<typename Graph, typename CapacityMap>
       
   329   void writeGraph(std::ostream& os, const Graph &g, 
       
   330 		  const CapacityMap& capacity, const typename Graph::Node &s) {
       
   331     GraphWriter<Graph> writer(os, g);
       
   332     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   333     writer.writeNodeMap("id", nodeIdMap);
       
   334     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   335     writer.writeEdgeMap("id", edgeIdMap);
       
   336     writer.writeEdgeMap("capacity", capacity);
       
   337     writer.writeNode("source", s);
       
   338     writer.run();
       
   339   }
       
   340 
       
   341 
       
   342   /// \brief Write a max flow instance to the output.
       
   343   ///
       
   344   /// Write a max flow instance (graph+capacity on the
       
   345   /// edges+designated source and target) to the output.
       
   346   ///
       
   347   /// \param os The output stream.
       
   348   /// \param g The graph.
       
   349   /// \param capacity The capacity map.
       
   350   /// \param s The source node.
       
   351   /// \param t The target node.
       
   352   template<typename Graph, typename CapacityMap>
       
   353   void writeGraph(std::ostream& os, const Graph &g, 
       
   354 		  const CapacityMap& capacity, const typename Graph::Node &s,
       
   355 		  const typename Graph::Node &t) {
       
   356     GraphWriter<Graph> writer(os, g);
       
   357     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   358     writer.writeNodeMap("id", nodeIdMap);
       
   359     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   360     writer.writeEdgeMap("id", edgeIdMap);
       
   361     writer.writeEdgeMap("capacity", capacity);
       
   362     writer.writeNode("source", s);
       
   363     writer.writeNode("target", t);
       
   364     writer.run();
       
   365   }
       
   366 
       
   367   /// \brief Write a min cost flow instance to the output.
       
   368   ///
       
   369   /// Write a min cost flow instance (graph+capacity on the edges+cost
       
   370   /// function on the edges+designated source and target) to the output.
       
   371   ///
   282   /// \param os The output stream.
   372   /// \param os The output stream.
   283   /// \param g The graph.
   373   /// \param g The graph.
   284   /// \param capacity The capacity map.
   374   /// \param capacity The capacity map.
   285   /// \param s The source node.
   375   /// \param s The source node.
   286   /// \param t The target node.
   376   /// \param t The target node.
   299     writer.writeNode("source", s);
   389     writer.writeNode("source", s);
   300     writer.writeNode("target", t);
   390     writer.writeNode("target", t);
   301     writer.run();
   391     writer.run();
   302   }
   392   }
   303 
   393 
   304   /// \brief Write a graph to the output.
       
   305   ///
       
   306   /// Write a graph to the output.
       
   307   /// \param os The output stream.
       
   308   /// \param g The graph.
       
   309   /// \param capacity The capacity map.
       
   310   /// \param s The source node.
       
   311   /// \param t The target node.
       
   312   template<typename Graph, typename CapacityMap>
       
   313   void writeGraph(std::ostream& os, const Graph &g, 
       
   314 		  const CapacityMap& capacity, const typename Graph::Node &s,
       
   315 		  const typename Graph::Node &t) {
       
   316     GraphWriter<Graph> writer(os, g);
       
   317     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   318     writer.writeNodeMap("id", nodeIdMap);
       
   319     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   320     writer.writeEdgeMap("id", edgeIdMap);
       
   321     writer.writeEdgeMap("capacity", capacity);
       
   322     writer.writeNode("source", s);
       
   323     writer.writeNode("target", t);
       
   324     writer.run();
       
   325   }
       
   326 
       
   327   /// \brief Write a graph to the output.
       
   328   ///
       
   329   /// Write a graph to the output.
       
   330   /// \param os The output stream.
       
   331   /// \param g The graph.
       
   332   /// \param capacity The capacity map.
       
   333   /// \param s The source node.
       
   334   template<typename Graph, typename CapacityMap>
       
   335   void writeGraph(std::ostream& os, const Graph &g, 
       
   336 		  const CapacityMap& capacity, const typename Graph::Node &s) {
       
   337     GraphWriter<Graph> writer(os, g);
       
   338     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   339     writer.writeNodeMap("id", nodeIdMap);
       
   340     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   341     writer.writeEdgeMap("id", edgeIdMap);
       
   342     writer.writeEdgeMap("capacity", capacity);
       
   343     writer.writeNode("source", s);
       
   344     writer.run();
       
   345   }
       
   346 
       
   347   /// \brief Write a graph to the output.
       
   348   ///
       
   349   /// Write a graph to the output.
       
   350   /// \param os The output stream.
       
   351   /// \param g The graph.
       
   352   /// \param capacity The capacity map.
       
   353   template<typename Graph, typename CapacityMap>
       
   354   void writeGraph(std::ostream& os, const Graph &g, 
       
   355 		  const CapacityMap& capacity) {
       
   356     GraphWriter<Graph> writer(os, g);
       
   357     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   358     writer.writeNodeMap("id", nodeIdMap);
       
   359     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   360     writer.writeEdgeMap("id", edgeIdMap);
       
   361     writer.writeEdgeMap("capacity", capacity);
       
   362     writer.run();
       
   363   }
       
   364 
       
   365   /// \brief Write a graph to the output.
       
   366   ///
       
   367   /// Write a graph to the output.
       
   368   /// \param os The output stream.
       
   369   /// \param g The graph.
       
   370   template<typename Graph>
       
   371   void writeGraph(std::ostream& os, const Graph &g) {
       
   372     GraphWriter<Graph> writer(os, g);
       
   373     IdMap<Graph, typename Graph::Node> nodeIdMap(g);
       
   374     writer.writeNodeMap("id", nodeIdMap);
       
   375     IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
       
   376     writer.writeEdgeMap("id", edgeIdMap);
       
   377     writer.run();
       
   378   }
       
   379 
       
   380   /// \brief The undirected graph writer class.
   394   /// \brief The undirected graph writer class.
   381   ///
   395   ///
   382   /// The \c UndirGraphWriter class provides the undir graph output. To write 
   396   /// The \c UndirGraphWriter class provides the undir graph output. To write 
   383   /// a graph you should first give writing commands to the writer. You can 
   397   /// a graph you should first give writing commands to the writer. You can 
   384   /// declare write command as \c NodeMap, \c EdgeMap or \c UndirEdgeMap 
   398   /// declare write command as \c NodeMap, \c EdgeMap or \c UndirEdgeMap 
   663     UndirEdgeWriter<Graph> undir_edge_writer;
   677     UndirEdgeWriter<Graph> undir_edge_writer;
   664     
   678     
   665     AttributeWriter<WriterTraits> attribute_writer;
   679     AttributeWriter<WriterTraits> attribute_writer;
   666   };
   680   };
   667 
   681 
       
   682   /// \brief Write an undirected graph to the output.
       
   683   ///
       
   684   /// Write an undirected graph to the output.
       
   685   /// \param os The output stream.
       
   686   /// \param g The graph.
       
   687   template<typename Graph>
       
   688   void writeUndirGraph(std::ostream& os, const Graph &g) {
       
   689     UndirGraphWriter<Graph> writer(os, g);
       
   690     writer.run();
       
   691   }
   668 
   692 
   669   /// \brief Write an undirected multigraph (undirected graph + capacity
   693   /// \brief Write an undirected multigraph (undirected graph + capacity
   670   /// map on the edges) to the output.
   694   /// map on the edges) to the output.
   671   ///
   695   ///
   672   /// Write an undirected multigraph (undirected graph + capacity
   696   /// Write an undirected multigraph (undirected graph + capacity
   680     UndirGraphWriter<Graph> writer(os, g);
   704     UndirGraphWriter<Graph> writer(os, g);
   681     writer.writeUndirEdgeMap("capacity", capacity);
   705     writer.writeUndirEdgeMap("capacity", capacity);
   682     writer.run();
   706     writer.run();
   683   }
   707   }
   684 
   708 
   685   /// \brief Write an undirected graph to the output.
       
   686   ///
       
   687   /// Write an undirected graph to the output.
       
   688   /// \param os The output stream.
       
   689   /// \param g The graph.
       
   690   template<typename Graph>
       
   691   void writeUndirGraph(std::ostream& os, const Graph &g) {
       
   692     UndirGraphWriter<Graph> writer(os, g);
       
   693     writer.run();
       
   694   }
       
   695 
   709 
   696   /// @}
   710   /// @}
   697 
   711 
   698 }
   712 }
   699 
   713