COIN-OR::LEMON - Graph Library

Changeset 1744:51d5d41e15b1 in lemon-0.x


Ignore:
Timestamp:
10/26/05 13:09:29 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2272
Message:

Removing old input/output functions

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • demo/dim_to_lgf.cc

    r1641 r1744  
    162162    StringMap cost(graph), capacity(graph);
    163163    readDimacs(is, graph, capacity, s, t, cost);
    164     writeGraph(os, graph, capacity, s, t, cost);
     164    GraphWriter<Graph>(os, graph).
     165      writeEdgeMap("capacity", capacity).
     166      writeNode("source", s).
     167      writeNode("target", t).
     168      writeEdgeMap("cost", cost).
     169      run();
    165170  } else if (typeName == "maxflow") {
    166171    Graph graph;
     
    168173    StringMap capacity(graph);
    169174    readDimacs(is, graph, capacity, s, t);
    170     writeGraph(os, graph, capacity, s, t);
     175    GraphWriter<Graph>(os, graph).
     176      writeEdgeMap("capacity", capacity).
     177      writeNode("source", s).
     178      writeNode("target", t).
     179      run();
    171180  } else if (typeName == "shortestpath") {
    172181    Graph graph;
     
    174183    StringMap capacity(graph);
    175184    readDimacs(is, graph, capacity, s);
    176     writeGraph(os, graph, capacity, s);
     185    GraphWriter<Graph>(os, graph).
     186      writeEdgeMap("capacity", capacity).
     187      writeNode("source", s).
     188      run();
    177189  } else if (typeName == "capacitated") {
    178190    Graph graph;
    179191    StringMap capacity(graph);
    180192    readDimacs(is, graph, capacity);
    181     writeGraph(os, graph, capacity);
     193    GraphWriter<Graph>(os, graph).
     194      writeEdgeMap("capacity", capacity).
     195      run();
    182196  } else if (typeName == "plain") {
    183197    Graph graph;
    184198    readDimacs(is, graph);
    185     writeGraph(os, graph);
     199    GraphWriter<Graph>(os, graph).run();
    186200  } else {
    187201    cerr << "Invalid type error" << endl;
  • lemon/bits/item_reader.h

    r1435 r1744  
    246246  /// \brief Reader for parsed string.
    247247  ///
    248   /// Reader for parsed strings. You can give the open and close
    249   /// parse characters.
     248  /// Reader for parsed strings. You can define the open and close
     249  /// parse characters. It reads from the input a character sequence
     250  /// which is right parsed.
    250251  ///
    251252  /// \author Balazs Dezso
     
    358359        ParsedStringReader().read(is, value);
    359360        break;
     361      case '[':
     362        ParsedStringReader('[', ']').read(is, value);
     363        break;
     364      case '/':
     365        ParsedStringReader('/', '/').read(is, value);
     366        break;
    360367      default:
    361         is >> value;
     368        if (!(is >> value))
     369          throw DataFormatError("DefaultReader format error");
    362370        break;
    363371      }
  • lemon/graph_reader.h

    r1705 r1744  
    340340
    341341
    342   ///\anchor readGraph()
    343   ///
    344   /// \brief Read a graph from an input stream.
    345   ///
    346   /// Read a graph from an input stream.
     342  /// \brief Read a graph from the input.
     343  ///
     344  /// It is a helper function to read a graph from the given input
     345  /// stream. It gives back an GraphReader object and this object
     346  /// can read more maps, labeled nodes, edges and attributes.
     347  ///
     348  /// \warning Do not forget to call the \c run() function.
     349  ///
    347350  /// \param is The input stream.
    348351  /// \param g The graph.
    349352  template<typename Graph>
    350   void readGraph(std::istream& is, Graph &g) {
    351     GraphReader<Graph> reader(is, g);
    352     reader.run();
     353  GraphReader<Graph> graphReader(std::istream& is, Graph &g) {
     354    return GraphReader<Graph>(is, g);
    353355  }
    354356
    355   /// \brief Read a capacitated graph instance from an input stream.
    356   ///
    357   /// Read a capacitated graph (graph+capacity on the
    358   /// edges) from an input stream.
    359   /// \param is The input stream.
     357  /// \brief Read a graph from the input.
     358  ///
     359  /// It is a helper function to read a graph from the given input
     360  /// file. It gives back an GraphReader object and this object
     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.
    360366  /// \param g The graph.
    361   /// \param capacity The capacity map.
    362   template<typename Graph, typename CapacityMap>
    363   void readGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
    364     GraphReader<Graph> reader(is, g);
    365     reader.readEdgeMap("capacity", capacity);
    366     reader.run();
     367  template<typename Graph>
     368  GraphReader<Graph> graphReader(const std::string& fn, Graph &g) {
     369    return GraphReader<Graph>(fn, g);
    367370  }
    368371
    369   /// \brief Read a shortest path instance from an input stream.
    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.
     372  /// \brief The undirected graph reader class.
    433373  ///
    434374  /// The \c UndirGraphReader class provides the graph input.
     
    807747  };
    808748
    809   /// \brief Read an undirected graph from an input stream.
    810   ///
    811   /// Read an undirected graph from an input stream.
     749  /// \brief Read an undirected graph from the input.
     750  ///
     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  ///
    812758  /// \param is The input stream.
    813759  /// \param g The graph.
    814760  template<typename Graph>
    815   void readUndirGraph(std::istream& is, Graph &g) {
    816     UndirGraphReader<Graph> reader(is, g);
    817     reader.run();
     761  UndirGraphReader<Graph> undirGraphReader(std::istream& is, Graph &g) {
     762    return GraphReader<Graph>(is, g);
    818763  }
    819764
    820   /// \brief Read an undirected multigraph (undirected graph + capacity
    821   /// map on the edges) from an input stream.
    822   ///
    823   /// Read an undirected multigraph (undirected graph + capacity
    824   /// map on the edges) from an input stream.
    825   /// \param is The input stream.
     765  /// \brief Read an undirected graph from the input.
     766  ///
     767  /// It is a helper function to read an undirected graph from the given input
     768  /// file. It gives back an UndirGraphReader object and this object
     769  /// can read more maps, labeled nodes, edges, undirected edges and
     770  /// attributes.
     771  ///
     772  /// \warning Do not forget to call the \c run() function.
     773  ///
     774  /// \param fn The input filename.
    826775  /// \param g The graph.
    827   /// \param capacity The capacity map.
    828   template<typename Graph, typename CapacityMap>
    829   void readUndirGraph(std::istream& is, Graph &g, CapacityMap& capacity) {
    830     UndirGraphReader<Graph> reader(is, g);
    831     reader.readUndirEdgeMap("capacity", capacity);
    832     reader.run();
     776  template<typename Graph>
     777  UndirGraphReader<Graph> undirGraphReader(const std::string& fn, Graph &g) {
     778    return GraphReader<Graph>(fn, g);
    833779  }
    834 
    835780
    836781  /// @}
  • lemon/graph_writer.h

    r1540 r1744  
    285285
    286286
    287   ///\anchor writeGraph()
    288   ///
     287
    289288  /// \brief Write a graph to the output.
    290289  ///
    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  ///
    292295  /// \param os The output stream.
    293296  /// \param g The graph.
    294   template<typename Graph>
    295   void writeGraph(std::ostream& os, const Graph &g) {
    296     GraphWriter<Graph> writer(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();
     297  template <typename Graph>
     298  GraphWriter<Graph> graphWriter(std::ostream& os, const Graph &g) {
     299    return GraphWriter<Graph>(os, g);
    302300  }
    303301
    304   /// \brief Write a capacitated graph instance to the output.
    305   ///
    306   /// Write a capacitated graph (graph+capacity on the
    307   /// edges) to the output.
    308   /// \param os The output stream.
     302  /// \brief Write a graph to the output.
     303  ///
     304  /// It is a helper function to write a graph to the given output
     305  /// file. It gives back a GraphWriter object and this object
     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.
    309310  /// \param g The graph.
    310   /// \param capacity The capacity map.
    311   template<typename Graph, typename CapacityMap>
    312   void writeGraph(std::ostream& os, const Graph &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();
     311  template <typename Graph>
     312  GraphWriter<Graph> graphWriter(const std::string& fn, const Graph &g) {
     313    return GraphWriter<Graph>(fn, g);
    395314  }
    396315
     
    685604  /// \brief Write an undirected graph to the output.
    686605  ///
    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  ///
    688611  /// \param os The output stream.
    689612  /// \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();
     613  template <typename Graph>
     614  UndirGraphWriter<Graph> undirGraphWriter(std::ostream& os, const Graph &g) {
     615    return UndirGraphWriter<Graph>(os, g);
    694616  }
    695617
    696   /// \brief Write an undirected multigraph (undirected graph + capacity
    697   /// map on the edges) to the output.
    698   ///
    699   /// Write an undirected multigraph (undirected graph + capacity
    700   /// map on the edges) to the output.
    701   /// \param os The output stream.
     618  /// \brief Write an undirected graph to the output.
     619  ///
     620  /// It is a helper function to write an undirected graph to the given output
     621  /// file. It gives back an UndirGraphWriter object and this object
     622  /// can write more maps, labeled nodes, edges, undirected edges and
     623  /// attributes.
     624  ///
     625  /// \warning Do not forget to call the \c run() function.
     626  ///
     627  /// \param fn The output file.
    702628  /// \param g The graph.
    703   /// \param capacity The capacity undirected map.
    704   template<typename Graph, typename CapacityMap>
    705   void writeUndirGraph(std::ostream& os, const Graph &g,
    706                        const CapacityMap& capacity) {
    707     UndirGraphWriter<Graph> writer(os, g);
    708     writer.writeUndirEdgeMap("capacity", capacity);
    709     writer.run();
     629  template <typename Graph>
     630  UndirGraphWriter<Graph> undirGraphWriter(const std::string& fn,
     631                                           const Graph &g) {
     632    return UndirGraphWriter<Graph>(fn, g);
    710633  }
    711634
    712 
    713635  /// @}
    714636
  • test/heap_test.cc

    r1728 r1744  
    5656  std::ifstream input(f_name.c_str());
    5757  check(input, "Input file '" << f_name << "' not found.");
    58   readGraph(input, graph, length, start); 
     58  GraphReader<Graph>(input, graph).
     59    readEdgeMap("length", length).
     60    readNode("source", start).
     61    run(); 
    5962 
    6063  {
Note: See TracChangeset for help on using the changeset viewer.