Changeset 1744:51d5d41e15b1 in lemon-0.x
- Timestamp:
- 10/26/05 13:09:29 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2272
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
demo/dim_to_lgf.cc
r1641 r1744 162 162 StringMap cost(graph), capacity(graph); 163 163 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(); 165 170 } else if (typeName == "maxflow") { 166 171 Graph graph; … … 168 173 StringMap capacity(graph); 169 174 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(); 171 180 } else if (typeName == "shortestpath") { 172 181 Graph graph; … … 174 183 StringMap capacity(graph); 175 184 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(); 177 189 } else if (typeName == "capacitated") { 178 190 Graph graph; 179 191 StringMap capacity(graph); 180 192 readDimacs(is, graph, capacity); 181 writeGraph(os, graph, capacity); 193 GraphWriter<Graph>(os, graph). 194 writeEdgeMap("capacity", capacity). 195 run(); 182 196 } else if (typeName == "plain") { 183 197 Graph graph; 184 198 readDimacs(is, graph); 185 writeGraph(os, graph);199 GraphWriter<Graph>(os, graph).run(); 186 200 } else { 187 201 cerr << "Invalid type error" << endl; -
lemon/bits/item_reader.h
r1435 r1744 246 246 /// \brief Reader for parsed string. 247 247 /// 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. 250 251 /// 251 252 /// \author Balazs Dezso … … 358 359 ParsedStringReader().read(is, value); 359 360 break; 361 case '[': 362 ParsedStringReader('[', ']').read(is, value); 363 break; 364 case '/': 365 ParsedStringReader('/', '/').read(is, value); 366 break; 360 367 default: 361 is >> value; 368 if (!(is >> value)) 369 throw DataFormatError("DefaultReader format error"); 362 370 break; 363 371 } -
lemon/graph_reader.h
r1705 r1744 340 340 341 341 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 /// 347 350 /// \param is The input stream. 348 351 /// \param g The graph. 349 352 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); 353 355 } 354 356 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. 360 366 /// \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); 367 370 } 368 371 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. 433 373 /// 434 374 /// The \c UndirGraphReader class provides the graph input. … … 807 747 }; 808 748 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 /// 812 758 /// \param is The input stream. 813 759 /// \param g The graph. 814 760 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); 818 763 } 819 764 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. 826 775 /// \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); 833 779 } 834 835 780 836 781 /// @} -
lemon/graph_writer.h
r1540 r1744 285 285 286 286 287 ///\anchor writeGraph() 288 /// 287 289 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 295 /// \param os The output stream. 293 296 /// \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); 302 300 } 303 301 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. 309 310 /// \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); 395 314 } 396 315 … … 685 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 611 /// \param os The output stream. 689 612 /// \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); 694 616 } 695 617 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. 702 628 /// \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); 710 633 } 711 634 712 713 635 /// @} 714 636 -
test/heap_test.cc
r1728 r1744 56 56 std::ifstream input(f_name.c_str()); 57 57 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(); 59 62 60 63 {
Note: See TracChangeset
for help on using the changeset viewer.