lemon/graph_writer.h
changeset 1744 51d5d41e15b1
parent 1540 7d028a73d7f2
child 1875 98698b69a902
     1.1 --- a/lemon/graph_writer.h	Wed Oct 26 10:59:51 2005 +0000
     1.2 +++ b/lemon/graph_writer.h	Wed Oct 26 11:09:29 2005 +0000
     1.3 @@ -284,114 +284,33 @@
     1.4    };
     1.5  
     1.6  
     1.7 -  ///\anchor writeGraph()
     1.8 -  ///
     1.9 +
    1.10    /// \brief Write a graph to the output.
    1.11    ///
    1.12 -  /// Write a graph to the output.
    1.13 -  /// \param os The output stream.
    1.14 -  /// \param g The graph.
    1.15 -  template<typename Graph>
    1.16 -  void writeGraph(std::ostream& os, const Graph &g) {
    1.17 -    GraphWriter<Graph> writer(os, g);
    1.18 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    1.19 -    writer.writeNodeMap("id", nodeIdMap);
    1.20 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    1.21 -    writer.writeEdgeMap("id", edgeIdMap);
    1.22 -    writer.run();
    1.23 -  }
    1.24 -
    1.25 -  /// \brief Write a capacitated graph instance to the output.
    1.26 -  /// 
    1.27 -  /// Write a capacitated graph (graph+capacity on the
    1.28 -  /// edges) to the output.
    1.29 -  /// \param os The output stream.
    1.30 -  /// \param g The graph.
    1.31 -  /// \param capacity The capacity map.
    1.32 -  template<typename Graph, typename CapacityMap>
    1.33 -  void writeGraph(std::ostream& os, const Graph &g, 
    1.34 -		  const CapacityMap& capacity) {
    1.35 -    GraphWriter<Graph> writer(os, g);
    1.36 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    1.37 -    writer.writeNodeMap("id", nodeIdMap);
    1.38 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    1.39 -    writer.writeEdgeMap("id", edgeIdMap);
    1.40 -    writer.writeEdgeMap("capacity", capacity);
    1.41 -    writer.run();
    1.42 -  }
    1.43 -
    1.44 -  /// \brief Write a shortest path instance to the output.
    1.45 -  /// 
    1.46 -  /// Write a shortest path instance (graph+capacity on the
    1.47 -  /// edges+designated source) to the output.
    1.48 -  /// \param os The output stream.
    1.49 -  /// \param g The graph.
    1.50 -  /// \param capacity The capacity map.
    1.51 -  /// \param s The source node.
    1.52 -  template<typename Graph, typename CapacityMap>
    1.53 -  void writeGraph(std::ostream& os, const Graph &g, 
    1.54 -		  const CapacityMap& capacity, const typename Graph::Node &s) {
    1.55 -    GraphWriter<Graph> writer(os, g);
    1.56 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    1.57 -    writer.writeNodeMap("id", nodeIdMap);
    1.58 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    1.59 -    writer.writeEdgeMap("id", edgeIdMap);
    1.60 -    writer.writeEdgeMap("capacity", capacity);
    1.61 -    writer.writeNode("source", s);
    1.62 -    writer.run();
    1.63 -  }
    1.64 -
    1.65 -
    1.66 -  /// \brief Write a max flow instance to the output.
    1.67 -  ///
    1.68 -  /// Write a max flow instance (graph+capacity on the
    1.69 -  /// edges+designated source and target) to the output.
    1.70 +  /// It is a helper function to write a graph to the given output
    1.71 +  /// stream. It gives back a GraphWriter object and this object
    1.72 +  /// can write more maps, labeled nodes and edges and attributes.
    1.73 +  /// \warning Do not forget to call the \c run() function.
    1.74    ///
    1.75    /// \param os The output stream.
    1.76    /// \param g The graph.
    1.77 -  /// \param capacity The capacity map.
    1.78 -  /// \param s The source node.
    1.79 -  /// \param t The target node.
    1.80 -  template<typename Graph, typename CapacityMap>
    1.81 -  void writeGraph(std::ostream& os, const Graph &g, 
    1.82 -		  const CapacityMap& capacity, const typename Graph::Node &s,
    1.83 -		  const typename Graph::Node &t) {
    1.84 -    GraphWriter<Graph> writer(os, g);
    1.85 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
    1.86 -    writer.writeNodeMap("id", nodeIdMap);
    1.87 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
    1.88 -    writer.writeEdgeMap("id", edgeIdMap);
    1.89 -    writer.writeEdgeMap("capacity", capacity);
    1.90 -    writer.writeNode("source", s);
    1.91 -    writer.writeNode("target", t);
    1.92 -    writer.run();
    1.93 +  template <typename Graph>
    1.94 +  GraphWriter<Graph> graphWriter(std::ostream& os, const Graph &g) {
    1.95 +    return GraphWriter<Graph>(os, g);
    1.96    }
    1.97  
    1.98 -  /// \brief Write a min cost flow instance to the output.
    1.99 +  /// \brief Write a graph to the output.
   1.100    ///
   1.101 -  /// Write a min cost flow instance (graph+capacity on the edges+cost
   1.102 -  /// function on the edges+designated source and target) to the output.
   1.103 +  /// It is a helper function to write a graph to the given output
   1.104 +  /// file. It gives back a GraphWriter object and this object
   1.105 +  /// can write more maps, labeled nodes and edges and attributes.
   1.106 +  /// \warning Do not forget to call the \c run() function.
   1.107    ///
   1.108 -  /// \param os The output stream.
   1.109 +  /// \param fn The filename.
   1.110    /// \param g The graph.
   1.111 -  /// \param capacity The capacity map.
   1.112 -  /// \param s The source node.
   1.113 -  /// \param t The target node.
   1.114 -  /// \param cost The cost map.
   1.115 -  template<typename Graph, typename CapacityMap, typename CostMap>
   1.116 -  void writeGraph(std::ostream& os, const Graph &g, 
   1.117 -		  const CapacityMap& capacity, const typename Graph::Node &s,
   1.118 -		  const typename Graph::Node &t, const CostMap& cost) {
   1.119 -    GraphWriter<Graph> writer(os, g);
   1.120 -    IdMap<Graph, typename Graph::Node> nodeIdMap(g);
   1.121 -    writer.writeNodeMap("id", nodeIdMap);
   1.122 -    IdMap<Graph, typename Graph::Edge> edgeIdMap(g);
   1.123 -    writer.writeEdgeMap("id", edgeIdMap);
   1.124 -    writer.writeEdgeMap("capacity", capacity);
   1.125 -    writer.writeEdgeMap("cost", cost);
   1.126 -    writer.writeNode("source", s);
   1.127 -    writer.writeNode("target", t);
   1.128 -    writer.run();
   1.129 +  template <typename Graph>
   1.130 +  GraphWriter<Graph> graphWriter(const std::string& fn, const Graph &g) {
   1.131 +    return GraphWriter<Graph>(fn, g);
   1.132    }
   1.133  
   1.134    /// \brief The undirected graph writer class.
   1.135 @@ -684,32 +603,35 @@
   1.136  
   1.137    /// \brief Write an undirected graph to the output.
   1.138    ///
   1.139 -  /// Write an undirected graph to the output.
   1.140 +  /// It is a helper function to write an undirected graph to the given output
   1.141 +  /// stream. It gives back an UndirGraphWriter object and this object
   1.142 +  /// can write more maps, labeled nodes and edges and attributes.
   1.143 +  /// \warning Do not forget to call the \c run() function.
   1.144 +  ///
   1.145    /// \param os The output stream.
   1.146    /// \param g The graph.
   1.147 -  template<typename Graph>
   1.148 -  void writeUndirGraph(std::ostream& os, const Graph &g) {
   1.149 -    UndirGraphWriter<Graph> writer(os, g);
   1.150 -    writer.run();
   1.151 +  template <typename Graph>
   1.152 +  UndirGraphWriter<Graph> undirGraphWriter(std::ostream& os, const Graph &g) {
   1.153 +    return UndirGraphWriter<Graph>(os, g);
   1.154    }
   1.155  
   1.156 -  /// \brief Write an undirected multigraph (undirected graph + capacity
   1.157 -  /// map on the edges) to the output.
   1.158 +  /// \brief Write an undirected graph to the output.
   1.159    ///
   1.160 -  /// Write an undirected multigraph (undirected graph + capacity
   1.161 -  /// map on the edges) to the output.
   1.162 -  /// \param os The output stream.
   1.163 +  /// It is a helper function to write an undirected graph to the given output
   1.164 +  /// file. It gives back an UndirGraphWriter object and this object
   1.165 +  /// can write more maps, labeled nodes, edges, undirected edges and 
   1.166 +  /// attributes.
   1.167 +  ///
   1.168 +  /// \warning Do not forget to call the \c run() function.
   1.169 +  ///
   1.170 +  /// \param fn The output file.
   1.171    /// \param g The graph.
   1.172 -  /// \param capacity The capacity undirected map.
   1.173 -  template<typename Graph, typename CapacityMap>
   1.174 -  void writeUndirGraph(std::ostream& os, const Graph &g, 
   1.175 -		       const CapacityMap& capacity) {
   1.176 -    UndirGraphWriter<Graph> writer(os, g);
   1.177 -    writer.writeUndirEdgeMap("capacity", capacity);
   1.178 -    writer.run();
   1.179 +  template <typename Graph>
   1.180 +  UndirGraphWriter<Graph> undirGraphWriter(const std::string& fn, 
   1.181 +					   const Graph &g) {
   1.182 +    return UndirGraphWriter<Graph>(fn, g);
   1.183    }
   1.184  
   1.185 -
   1.186    /// @}
   1.187  
   1.188  }