Ticket #35: digraph_reader_doc.patch
File digraph_reader_doc.patch, 12.8 KB (added by , 17 years ago) |
---|
-
lemon/lgf_reader.h
# HG changeset patch # User Balazs Dezso <deba@inf.elte.hu> # Date 1210511869 -7200 # Node ID f6b69e8d7fa38c99540c7affa9ecf6572d473d16 # Parent 5c3604513ed0256e35e5fd50c54cd0e37362397e Documentation for DigraphReader diff -r 5c3604513ed0 -r f6b69e8d7fa3 lemon/lgf_reader.h
a b 295 295 } 296 296 297 297 } 298 299 /// \e 298 299 /// \ingroup lemon_io 300 /// 301 /// \brief LGF reader for directed graphs 302 /// 303 /// The \e LGF (LEMON graph file) format is the default file format 304 /// of the LEMON library. It is a text based, section oriented 305 /// format, which defines some standard sections for storing graphs 306 /// in text files. Each line with \c '#' first non-whitespace 307 /// character are denoted as comment line. Each section starts with 308 /// a header line, these lines starts with \c '@' character and the 309 /// name of section type. The standard sections are \c \@nodes, \c 310 /// \@arcs or \c \@edges (these two names are completely equivalent) 311 /// and \@attributes. Each header lines could contain an optional 312 /// name, which can be use to distinguish the sections of the same 313 /// type. 314 /// 315 /// The \@nodes section stores node maps for a node set. The first 316 /// line comprises from the names of the maps, these map names are 317 /// sequences of non-whitespace characters. One of the maps should 318 /// be called \c "label", which plays specific role in the file. 319 /// Each following non-empty line, until a line starting with \c '@' 320 /// character, describes a node in the graph. These lines contain 321 /// the values of the node maps associated to the current node. The 322 /// values are plain or quoted tokens, a plain token is a sequence 323 /// of a non-whitespace characters. A quoted token is a character 324 /// sequence surrounded by double quotes, and the sequence could 325 /// contain several escape sequences. 326 /// 327 /// The \c \@arcs or \c \@edges section is very similar to the \c 328 /// \@nodes section, it starts with a line consists from the names of 329 /// the arc maps, the \c "label" map is also necessary. The 330 /// following lines contain the description of the arcs, but before 331 /// the map values the line comprises the source and target of the 332 /// arc, these tokens should be occured in the \c \@nodes section as 333 /// a node label. 334 /// 335 /// The \c \@attrbiutes section contains key-value pairs, each line 336 /// starts with an attribute name, and then an attribute value. The 337 /// name is a sequence of non-whitespace characters, while the value 338 /// is plain or quoted string literal. The value could be a node or 339 /// arc label. 340 /// 341 ///\code 342 /// @nodes 343 /// label coordinates size title 344 /// 1 (10,20) 10 "First node" 345 /// 2 (80,80) 8 "Second node" 346 /// 3 (40,10) 10 "Third node" 347 /// @arcs 348 /// capacity 349 /// 1 2 16 350 /// 1 3 12 351 /// 2 3 18 352 /// @attributes 353 /// source 1 354 /// target 3 355 /// caption "LEMON test digraph" 356 ///\endcode 357 /// 358 /// The reading method is organized as batch processing. The user 359 /// creates a reader object, then several reading rules can be added 360 /// to the reader, and finally executes the reading with the \c 361 /// run() member function. A map reading rule can be added to the 362 /// reader with the \c nodeMap() or \c arcMap() members. The 363 /// optional converter parameter can be a standard functor, which 364 /// converts an std::string to the value type of the map, if it is 365 /// set, it determines how the read string literal is converted to 366 /// the map's value type. If the functor is not set, then the 367 /// default method will perform this task. One map could be read in 368 /// multiple map objects, if more reading rule is used with the same 369 /// map name. The \c attribute(), \c node() and \c arc() functions 370 /// can be used to add attribute reading rules. 371 /// 372 ///\code 373 /// DigraphReader<Digraph>(std::cin, digraph). 374 /// nodeMap("coordinates", coord_map). 375 /// arcMap("capacity", cap_map). 376 /// node("source", src). 377 /// node("target", trg). 378 /// attribute("caption", caption). 379 /// run(); 380 ///\endcode 381 /// 382 /// In the default behaviour the reader uses the first section in 383 /// the file of the proper type. If a section has an optional name, 384 /// then it can be select to read with the \c nodes(), \c arcs() or 385 /// \c attributes() functions. 386 /// 387 /// The \c useNodes() and \c useArcs() functions can be used to 388 /// specify that the nodes or arcs should not be constructed during 389 /// the reading, the argument of these functions is a node map or 390 /// arc map, which determines the label map for the items. One 391 /// application of these member is the multipass reading, which is a 392 /// very important approach in the LEMON IO, because several tasks 393 /// are solveable just with this technic. If two \e \@arcs should be 394 /// read from the file (for example transport matrix), then it could 395 /// be made with two phases. The first phase reads the node set and 396 /// one of the arc set, and it should read the label column to a 397 /// map. The second phase could read the second arc set into an \e 398 /// ArcSet class (\c SmartArcSet or \c ListArcSet), the previously 399 /// read label node map should be given to the \c useNodes() 400 /// functions. An other multipass application is reading path into 401 /// node map or arc map. It is impossible in singlepass, because the 402 /// arcs are not constructed yet, when the node maps are read. 300 403 template <typename _Digraph> 301 404 class DigraphReader { 302 405 public: … … 341 444 342 445 public: 343 446 344 /// \e 447 /// \brief Constructor 448 /// 449 /// Construct a directed graph reader, which reads from the given 450 /// input stream. 345 451 DigraphReader(std::istream& is, Digraph& digraph) 346 452 : _is(&is), local_is(false), _digraph(digraph), 347 453 _use_nodes(false), _use_arcs(false) {} 348 454 349 /// \e 455 /// \brief Constructor 456 /// 457 /// Construct a directed graph reader, which reads from the given 458 /// file. 350 459 DigraphReader(const std::string& fn, Digraph& digraph) 351 460 : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph), 352 461 _use_nodes(false), _use_arcs(false) {} 353 354 355 /// \e 462 463 /// \brief Constructor 464 /// 465 /// Construct a directed graph reader, which reads from the given 466 /// file. 356 467 DigraphReader(const char* fn, Digraph& digraph) 357 468 : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph), 358 469 _use_nodes(false), _use_arcs(false) {} 359 470 360 /// \e 471 /// \brief Copy constructor 472 /// 473 /// The copy constructor transfers all data from the other reader, 474 /// therefore the copied reader will not be useable more. 361 475 DigraphReader(DigraphReader& other) 362 476 : _is(other._is), local_is(other.local_is), _digraph(other._digraph), 363 477 _use_nodes(other._use_nodes), _use_arcs(other._use_arcs) { … … 377 491 _attributes_caption = other._attributes_caption; 378 492 } 379 493 380 /// \ e494 /// \brief Destructor 381 495 ~DigraphReader() { 382 496 for (typename NodeMaps::iterator it = _node_maps.begin(); 383 497 it != _node_maps.end(); ++it) { … … 406 520 407 521 public: 408 522 409 /// \e 523 /// \name Reading rules 524 /// @{ 525 526 /// \brief Node map reading rule 527 /// 528 /// Add a node map reading rule to the reader. 410 529 template <typename Map> 411 530 DigraphReader& nodeMap(const std::string& caption, Map& map) { 412 531 checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); … … 416 535 return *this; 417 536 } 418 537 419 /// \e 538 /// \brief Node map reading rule 539 /// 540 /// Add a node map reading rule with specialized converter to the 541 /// reader. 420 542 template <typename Map, typename Converter> 421 543 DigraphReader& nodeMap(const std::string& caption, Map& map, 422 544 const Converter& converter = Converter()) { … … 427 549 return *this; 428 550 } 429 551 430 /// \e 552 /// \brief Arc map reading rule 553 /// 554 /// Add an arc map reading rule to the reader. 431 555 template <typename Map> 432 556 DigraphReader& arcMap(const std::string& caption, Map& map) { 433 557 checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>(); … … 437 561 return *this; 438 562 } 439 563 440 /// \e 564 /// \brief Arc map reading rule 565 /// 566 /// Add an arc map reading rule with specialized converter to the 567 /// reader. 441 568 template <typename Map, typename Converter> 442 569 DigraphReader& arcMap(const std::string& caption, Map& map, 443 570 const Converter& converter = Converter()) { … … 448 575 return *this; 449 576 } 450 577 451 /// \e 578 /// \brief Attribute reading rule 579 /// 580 /// Add an attribute reading rule to the reader. 452 581 template <typename Value> 453 582 DigraphReader& attribute(const std::string& caption, Value& value) { 454 583 _reader_bits::ValueStorageBase* storage = … … 457 586 return *this; 458 587 } 459 588 460 /// \e 589 /// \brief Attribute reading rule 590 /// 591 /// Add an attribute reading rule with specialized converter to the 592 /// reader. 461 593 template <typename Value, typename Converter> 462 594 DigraphReader& attribute(const std::string& caption, Value& value, 463 595 const Converter& converter = Converter()) { … … 467 599 return *this; 468 600 } 469 601 470 /// \e 602 /// \brief Node reading rule 603 /// 604 /// Add a node reading rule with specialized converter to the 605 /// reader. 471 606 DigraphReader& node(const std::string& caption, Node& node) { 472 607 typedef _reader_bits::MapLookUpConverter<Node> Converter; 473 608 Converter converter(_node_index); … … 477 612 return *this; 478 613 } 479 614 480 /// \e 615 /// \brief Arc reading rule 616 /// 617 /// Add an arc reading rule with specialized converter to the 618 /// reader. 481 619 DigraphReader& arc(const std::string& caption, Arc& arc) { 482 620 typedef _reader_bits::MapLookUpConverter<Arc> Converter; 483 621 Converter converter(_arc_index); … … 487 625 return *this; 488 626 } 489 627 490 /// \e 628 /// @} 629 630 /// \name Select section by name 631 /// @{ 632 633 /// \brief Set \c \@nodes section to be read 634 /// 635 /// Set \c \@nodes section to be read 491 636 DigraphReader& nodes(const std::string& caption) { 492 637 _nodes_caption = caption; 493 638 return *this; 494 639 } 495 640 496 /// \e 641 /// \brief Set \c \@arcs section to be read 642 /// 643 /// Set \c \@arcs section to be read 497 644 DigraphReader& arcs(const std::string& caption) { 498 645 _arcs_caption = caption; 499 646 return *this; 500 647 } 501 648 502 /// \e 649 /// \brief Set \c \@attributes section to be read 650 /// 651 /// Set \c \@attributes section to be read 503 652 DigraphReader& attributes(const std::string& caption) { 504 653 _attributes_caption = caption; 505 654 return *this; 506 655 } 507 656 508 /// \e 657 /// @} 658 659 /// \name Using previously constructed node or arc set 660 /// @{ 661 662 /// \brief Use previously constructed node set 663 /// 664 /// Use previously constructed node set, and specify the node 665 /// label map. 509 666 template <typename Map> 510 667 DigraphReader& useNodes(const Map& map) { 511 668 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); … … 518 675 return *this; 519 676 } 520 677 521 /// \e 678 /// \brief Use previously constructed node set 679 /// 680 /// Use previously constructed node set, and specify the node 681 /// label map and a functor which converts the label map values to 682 /// std::string. 522 683 template <typename Map, typename Converter> 523 684 DigraphReader& useNodes(const Map& map, 524 685 const Converter& converter = Converter()) { … … 531 692 return *this; 532 693 } 533 694 534 /// \e 695 /// \brief Use previously constructed arc set 696 /// 697 /// Use previously constructed arc set, and specify the arc 698 /// label map. 535 699 template <typename Map> 536 700 DigraphReader& useArcs(const Map& map) { 537 701 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>(); … … 544 708 return *this; 545 709 } 546 710 547 /// \e 711 /// \brief Use previously constructed arc set 712 /// 713 /// Use previously constructed arc set, and specify the arc 714 /// label map and a functor which converts the label map values to 715 /// std::string. 548 716 template <typename Map, typename Converter> 549 717 DigraphReader& useArcs(const Map& map, 550 718 const Converter& converter = Converter()) { … … 556 724 } 557 725 return *this; 558 726 } 727 728 /// @} 559 729 560 730 private: 561 731 … … 827 997 } 828 998 829 999 public: 830 831 /// \e 1000 1001 /// \name Execution of the reader 1002 /// @{ 1003 1004 /// \brief Start the batch processing 1005 /// 1006 /// This function starts the batch processing 832 1007 void run() { 833 1008 834 1009 LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); … … 891 1066 } 892 1067 893 1068 } 1069 1070 /// @} 894 1071 895 1072 }; 896 1073