Major improvements in NetworkSimplex.
Main changes:
- Use -potenital[] instead of potential[] to conform to the usual
terminology.
- Use function parameter instead of #define commands to select pivot rule.
- Use much faster implementation for the candidate list pivot rule.
It is about 5-20 times faster now.
- Add a new pivot rule called "Limited Search" that is a modified
version of "Block Search". It is about 25 percent faster on rather
sparse graphs.
- By default "Limited Search" is used for sparse graphs and
"Block Search" is used otherwise. This combined method is the most
efficient on every input class.
- Change the name of private members to start with "_".
- Change the name of function parameters not to start with "_".
- Remove unnecessary documentation for private members.
- Many doc improvements.
3 * This file is a part of LEMON, a generic C++ optimization library
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
21 ///\brief Lemon Graph Format reader.
23 #ifndef LEMON_GRAPH_READER_H
24 #define LEMON_GRAPH_READER_H
28 #include <lemon/error.h>
29 #include <lemon/lemon_reader.h>
33 /// \addtogroup lemon_io
36 /// \brief The graph reader class.
38 /// The \c GraphReader class provides the graph input.
39 /// Before you read this documentation it might be useful to read the general
40 /// description of \ref graph-io-page "Graph Input-Output".
42 /// The file to be read may contain several maps and labeled
43 /// (designated) nodes or edges.
45 /// If you read a graph you need not read all the maps and items just those
46 /// that you need. The interface of the \c GraphReader is very similar to
47 /// the GraphWriter but the reading method does not depend on the order the
48 /// given commands (i.e. you don't have to insist on the order in which the
49 /// maps are given in the file).
51 /// The reader object assumes that not read values do not contain
52 /// whitespaces, therefore it has some extra possibilities to control how
53 /// it should skip the values when the string representation contains spaces.
56 /// GraphReader<ListGraph> reader(std::cin, graph);
59 /// The \c readNodeMap() function reads a map from the \c \@nodeset section.
60 /// If there is a map that you do not want to read from the file and there is
61 /// whitespace in the string represenation of the values then you should
62 /// call the \c skipNodeMap() template member function with proper
66 /// reader.readNodeMap("coords", coords);
68 /// reader.skipNodeMap("description", desc);
70 /// reader.readNodeMap("color", colorMap);
73 /// With the \c readEdgeMap() member function you can give an edge map
74 /// reading command similar to the NodeMaps.
77 /// reader.readEdgeMap("weight", weightMap);
78 /// reader.readEdgeMap("label", labelMap);
81 /// With \c readNode() and \c readEdge() functions you can read
82 /// labeled Nodes and Edges.
85 /// reader.readNode("source", sourceNode);
86 /// reader.readNode("target", targetNode);
88 /// reader.readEdge("observed", edge);
91 /// With the \c readAttribute() functions you can read an attribute
92 /// into a variable. You can specify the reader for the attribute as
95 /// After you give all read commands you must call the \c run() member
96 /// function, which executes all the commands.
102 /// \see DefaultReaderTraits
103 /// \see QuotedStringReader
104 /// \see \ref GraphWriter
105 /// \see \ref graph-io-page
106 /// \author Balazs Dezso
107 template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
111 typedef _Graph Graph;
112 typedef typename Graph::Node Node;
113 typedef typename Graph::Edge Edge;
115 typedef _ReaderTraits ReaderTraits;
116 typedef typename ReaderTraits::Skipper DefaultSkipper;
118 /// \brief Construct a new GraphReader.
120 /// Construct a new GraphReader. It reads into the given graph
121 /// and it uses the given reader as the default skipper.
122 GraphReader(std::istream& _is, Graph& _graph,
123 const DefaultSkipper& _skipper = DefaultSkipper())
124 : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
125 nodeset_reader(*reader, _graph, std::string(), skipper),
126 edgeset_reader(*reader, _graph, nodeset_reader,
127 std::string(), skipper),
128 node_reader(*reader, nodeset_reader, std::string()),
129 edge_reader(*reader, edgeset_reader, std::string()),
130 attribute_reader(*reader, std::string()) {}
132 /// \brief Construct a new GraphReader.
134 /// Construct a new GraphReader. It reads into the given graph
135 /// and it uses the given reader as the default skipper.
136 GraphReader(const std::string& _filename, Graph& _graph,
137 const DefaultSkipper& _skipper = DefaultSkipper())
138 : reader(new LemonReader(_filename)), own_reader(true),
140 nodeset_reader(*reader, _graph, std::string(), skipper),
141 edgeset_reader(*reader, _graph, nodeset_reader,
142 std::string(), skipper),
143 node_reader(*reader, nodeset_reader, std::string()),
144 edge_reader(*reader, edgeset_reader, std::string()),
145 attribute_reader(*reader, std::string()) {}
147 /// \brief Construct a new GraphReader.
149 /// Construct a new GraphReader. It reads into the given graph
150 /// and it uses the given reader as the default skipper.
151 GraphReader(LemonReader& _reader, Graph& _graph,
152 const DefaultSkipper& _skipper = DefaultSkipper())
153 : reader(_reader), own_reader(false), skipper(_skipper),
154 nodeset_reader(*reader, _graph, std::string(), skipper),
155 edgeset_reader(*reader, _graph, nodeset_reader,
156 std::string(), skipper),
157 node_reader(*reader, nodeset_reader, std::string()),
158 edge_reader(*reader, edgeset_reader, std::string()),
159 attribute_reader(*reader, std::string()) {}
161 /// \brief Destruct the graph reader.
163 /// Destruct the graph reader.
169 /// \brief Give a new node map reading command to the reader.
171 /// Give a new node map reading command to the reader.
172 template <typename Map>
173 GraphReader& readNodeMap(std::string name, Map& map) {
174 nodeset_reader.readNodeMap(name, map);
178 template <typename Map>
179 GraphReader& readNodeMap(std::string name, const Map& map) {
180 nodeset_reader.readNodeMap(name, map);
184 /// \brief Give a new node map reading command to the reader.
186 /// Give a new node map reading command to the reader.
187 template <typename ItemReader, typename Map>
188 GraphReader& readNodeMap(std::string name, Map& map,
189 const ItemReader& ir = ItemReader()) {
190 nodeset_reader.readNodeMap(name, map, ir);
194 template <typename ItemReader, typename Map>
195 GraphReader& readNodeMap(std::string name, const Map& map,
196 const ItemReader& ir = ItemReader()) {
197 nodeset_reader.readNodeMap(name, map, ir);
201 /// \brief Give a new node map skipping command to the reader.
203 /// Give a new node map skipping command to the reader.
204 template <typename ItemReader>
205 GraphReader& skipNodeMap(std::string name,
206 const ItemReader& ir = ItemReader()) {
207 nodeset_reader.skipNodeMap(name, ir);
211 /// \brief Give a new edge map reading command to the reader.
213 /// Give a new edge map reading command to the reader.
214 template <typename Map>
215 GraphReader& readEdgeMap(std::string name, Map& map) {
216 edgeset_reader.readEdgeMap(name, map);
220 template <typename Map>
221 GraphReader& readEdgeMap(std::string name, const Map& map) {
222 edgeset_reader.readEdgeMap(name, map);
227 /// \brief Give a new edge map reading command to the reader.
229 /// Give a new edge map reading command to the reader.
230 template <typename ItemReader, typename Map>
231 GraphReader& readEdgeMap(std::string name, Map& map,
232 const ItemReader& ir = ItemReader()) {
233 edgeset_reader.readEdgeMap(name, map, ir);
237 template <typename ItemReader, typename Map>
238 GraphReader& readEdgeMap(std::string name, const Map& map,
239 const ItemReader& ir = ItemReader()) {
240 edgeset_reader.readEdgeMap(name, map, ir);
244 /// \brief Give a new edge map skipping command to the reader.
246 /// Give a new edge map skipping command to the reader.
247 template <typename ItemReader>
248 GraphReader& skipEdgeMap(std::string name,
249 const ItemReader& ir = ItemReader()) {
250 edgeset_reader.skipEdgeMap(name, ir);
254 /// \brief Give a new labeled node reading command to the reader.
256 /// Give a new labeled node reading command to the reader.
257 GraphReader& readNode(std::string name, Node& node) {
258 node_reader.readNode(name, node);
262 /// \brief Give a new labeled edge reading command to the reader.
264 /// Give a new labeled edge reading command to the reader.
265 GraphReader& readEdge(std::string name, Edge& edge) {
266 edge_reader.readEdge(name, edge);
270 /// \brief Give a new attribute reading command.
272 /// Give a new attribute reading command.
273 template <typename Value>
274 GraphReader& readAttribute(std::string name, Value& value) {
275 attribute_reader.readAttribute(name, value);
279 /// \brief Give a new attribute reading command.
281 /// Give a new attribute reading command.
282 template <typename ItemReader, typename Value>
283 GraphReader& readAttribute(std::string name, Value& value,
284 const ItemReader& ir = ItemReader()) {
285 attribute_reader.readAttribute(name, value, ir);
289 /// \brief Conversion operator to LemonReader.
291 /// Conversion operator to LemonReader. It makes possible to access the
292 /// encapsulated \e LemonReader, this way you can attach to this reader
293 /// new instances of \e LemonReader::SectionReader. For more details see
294 /// the \ref rwbackground "Background of Reading and Writing".
295 operator LemonReader&() {
299 /// \brief Executes the reading commands.
301 /// Executes the reading commands.
307 /// \brief Returns true if the reader can give back the items by its label.
309 /// \brief Returns true if the reader can give back the items by its label.
310 bool isLabelReader() const {
311 return nodeset_reader.isLabelReader() && edgeset_reader.isLabelReader();
314 /// \brief Gives back the node by its label.
316 /// It reads an label from the stream and gives back which node belongs to
317 /// it. It is possible only if there was read a "label" named node map.
318 void readLabel(std::istream& is, Node& node) const {
319 nodeset_reader.readLabel(is, node);
322 /// \brief Gives back the edge by its label.
324 /// It reads an label from the stream and gives back which edge belongs to
325 /// it. It is possible only if there was read a "label" named edge map.
326 void readLabel(std::istream& is, Edge& edge) const {
327 edgeset_reader.readLabel(is, edge);
335 DefaultSkipper skipper;
337 NodeSetReader<Graph, ReaderTraits> nodeset_reader;
338 EdgeSetReader<Graph, ReaderTraits> edgeset_reader;
340 NodeReader<Graph> node_reader;
341 EdgeReader<Graph> edge_reader;
343 AttributeReader<ReaderTraits> attribute_reader;
347 /// \brief The undirected graph reader class.
349 /// The \c UGraphReader class provides the graph input.
350 /// Before you read this documentation it might be useful to read the general
351 /// description of \ref graph-io-page "Graph Input-Output".
353 /// The given file format may contain several maps and labeled nodes or
356 /// If you read a graph you need not read all the maps and items just those
357 /// that you need. The interface of the \c UGraphReader is very similar
358 /// to the UGraphWriter but the reading method does not depend on the
359 /// order of the given commands.
361 /// The reader object suppose that each not read value does not contain
362 /// whitespaces, therefore it has some extra possibilities to control how
363 /// it should skip the values when the string representation contains spaces.
366 /// UGraphReader<ListUGraph> reader(std::cin, graph);
369 /// The \c readNodeMap() function reads a map from the \c \@nodeset section.
370 /// If there is a map that you do not want to read from the file and there is
371 /// whitespace in the string represenation of the values then you should
372 /// call the \c skipNodeMap() template member function with proper
376 /// reader.readNodeMap("coords", coords);
378 /// reader.skipNodeMap("description", desc);
380 /// reader.readNodeMap("color", colorMap);
383 /// With the \c readUEdgeMap() member function you can give an
384 /// uedge map reading command similar to the NodeMaps.
387 /// reader.readUEdgeMap("capacity", capacityMap);
390 /// The reading of the directed edge maps is just a syntactical sugar.
391 /// It reads two undirected edgemaps into a directed edge map. The
392 /// undirected edge maps' name should be start with the \c '+' and the
393 /// \c '-' character and the same.
396 /// reader.readEdgeMap("flow", flowMap);
399 /// With \c readNode() and \c readUEdge() functions you can read
400 /// labeled Nodes and UEdges.
403 /// reader.readNode("source", sourceNode);
404 /// reader.readNode("target", targetNode);
406 /// reader.readUEdge("observed", uEdge);
409 /// With the \c readAttribute() functions you can read an attribute
410 /// in a variable. You can specify the reader for the attribute as
413 /// After you give all read commands you must call the \c run() member
414 /// function, which execute all the commands.
421 /// \see DefaultReaderTraits
422 /// \see \ref UGraphWriter
423 /// \see \ref graph-io-page
425 /// \author Balazs Dezso
426 template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
430 typedef _Graph Graph;
431 typedef typename Graph::Node Node;
432 typedef typename Graph::Edge Edge;
433 typedef typename Graph::UEdge UEdge;
435 typedef _ReaderTraits ReaderTraits;
436 typedef typename ReaderTraits::Skipper DefaultSkipper;
438 /// \brief Construct a new UGraphReader.
440 /// Construct a new UGraphReader. It reads into the given graph
441 /// and it use the given reader as the default skipper.
442 UGraphReader(std::istream& _is, Graph& _graph,
443 const DefaultSkipper& _skipper = DefaultSkipper())
444 : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
445 nodeset_reader(*reader, _graph, std::string(), skipper),
446 uedgeset_reader(*reader, _graph, nodeset_reader,
447 std::string(), skipper),
448 node_reader(*reader, nodeset_reader, std::string()),
449 uedge_reader(*reader, uedgeset_reader, std::string()),
450 attribute_reader(*reader, std::string()) {}
452 /// \brief Construct a new UGraphReader.
454 /// Construct a new UGraphReader. It reads into the given graph
455 /// and it use the given reader as the default skipper.
456 UGraphReader(const std::string& _filename, Graph& _graph,
457 const DefaultSkipper& _skipper = DefaultSkipper())
458 : reader(new LemonReader(_filename)), own_reader(true),
460 nodeset_reader(*reader, _graph, std::string(), skipper),
461 uedgeset_reader(*reader, _graph, nodeset_reader,
462 std::string(), skipper),
463 node_reader(*reader, nodeset_reader, std::string()),
464 uedge_reader(*reader, uedgeset_reader, std::string()),
465 attribute_reader(*reader, std::string()) {}
467 /// \brief Construct a new UGraphReader.
469 /// Construct a new UGraphReader. It reads into the given graph
470 /// and it use the given reader as the default skipper.
471 UGraphReader(LemonReader& _reader, Graph& _graph,
472 const DefaultSkipper& _skipper = DefaultSkipper())
473 : reader(_reader), own_reader(false), skipper(_skipper),
474 nodeset_reader(*reader, _graph, std::string(), skipper),
475 uedgeset_reader(*reader, _graph, nodeset_reader,
476 std::string(), skipper),
477 node_reader(*reader, nodeset_reader, std::string()),
478 uedge_reader(*reader, uedgeset_reader, std::string()),
479 attribute_reader(*reader, std::string()) {}
481 /// \brief Destruct the graph reader.
483 /// Destruct the graph reader.
489 /// \brief Give a new node map reading command to the reader.
491 /// Give a new node map reading command to the reader.
492 template <typename Map>
493 UGraphReader& readNodeMap(std::string name, Map& map) {
494 nodeset_reader.readNodeMap(name, map);
498 template <typename Map>
499 UGraphReader& readNodeMap(std::string name, const Map& map) {
500 nodeset_reader.readNodeMap(name, map);
504 /// \brief Give a new node map reading command to the reader.
506 /// Give a new node map reading command to the reader.
507 template <typename ItemReader, typename Map>
508 UGraphReader& readNodeMap(std::string name, Map& map,
509 const ItemReader& ir = ItemReader()) {
510 nodeset_reader.readNodeMap(name, map, ir);
514 template <typename ItemReader, typename Map>
515 UGraphReader& readNodeMap(std::string name, const Map& map,
516 const ItemReader& ir = ItemReader()) {
517 nodeset_reader.readNodeMap(name, map, ir);
521 /// \brief Give a new node map skipping command to the reader.
523 /// Give a new node map skipping command to the reader.
524 template <typename ItemReader>
525 UGraphReader& skipNodeMap(std::string name,
526 const ItemReader& ir = ItemReader()) {
527 nodeset_reader.skipNodeMap(name, ir);
531 /// \brief Give a new undirected edge map reading command to the reader.
533 /// Give a new undirected edge map reading command to the reader.
534 template <typename Map>
535 UGraphReader& readUEdgeMap(std::string name, Map& map) {
536 uedgeset_reader.readUEdgeMap(name, map);
540 template <typename Map>
541 UGraphReader& readUEdgeMap(std::string name, const Map& map) {
542 uedgeset_reader.readUEdgeMap(name, map);
547 /// \brief Give a new undirected edge map reading command to the reader.
549 /// Give a new undirected edge map reading command to the reader.
550 template <typename ItemReader, typename Map>
551 UGraphReader& readUEdgeMap(std::string name, Map& map,
552 const ItemReader& ir = ItemReader()) {
553 uedgeset_reader.readUEdgeMap(name, map, ir);
557 template <typename ItemReader, typename Map>
558 UGraphReader& readUEdgeMap(std::string name, const Map& map,
559 const ItemReader& ir = ItemReader()) {
560 uedgeset_reader.readUEdgeMap(name, map, ir);
564 /// \brief Give a new undirected edge map skipping command to the reader.
566 /// Give a new undirected edge map skipping command to the reader.
567 template <typename ItemReader>
568 UGraphReader& skipUEdgeMap(std::string name,
569 const ItemReader& ir = ItemReader()) {
570 uedgeset_reader.skipUMap(name, ir);
575 /// \brief Give a new edge map reading command to the reader.
577 /// Give a new edge map reading command to the reader.
578 template <typename Map>
579 UGraphReader& readEdgeMap(std::string name, Map& map) {
580 uedgeset_reader.readEdgeMap(name, map);
584 template <typename Map>
585 UGraphReader& readEdgeMap(std::string name, const Map& map) {
586 uedgeset_reader.readEdgeMap(name, map);
591 /// \brief Give a new edge map reading command to the reader.
593 /// Give a new edge map reading command to the reader.
594 template <typename ItemReader, typename Map>
595 UGraphReader& readEdgeMap(std::string name, Map& map,
596 const ItemReader& ir = ItemReader()) {
597 uedgeset_reader.readEdgeMap(name, map, ir);
601 template <typename ItemReader, typename Map>
602 UGraphReader& readEdgeMap(std::string name, const Map& map,
603 const ItemReader& ir = ItemReader()) {
604 uedgeset_reader.readEdgeMap(name, map, ir);
608 /// \brief Give a new edge map skipping command to the reader.
610 /// Give a new edge map skipping command to the reader.
611 template <typename ItemReader>
612 UGraphReader& skipEdgeMap(std::string name,
613 const ItemReader& ir = ItemReader()) {
614 uedgeset_reader.skipEdgeMap(name, ir);
618 /// \brief Give a new labeled node reading command to the reader.
620 /// Give a new labeled node reading command to the reader.
621 UGraphReader& readNode(std::string name, Node& node) {
622 node_reader.readNode(name, node);
626 /// \brief Give a new labeled edge reading command to the reader.
628 /// Give a new labeled edge reading command to the reader.
629 UGraphReader& readEdge(std::string name, Edge& edge) {
630 uedge_reader.readEdge(name, edge);
633 /// \brief Give a new labeled undirected edge reading command to the
636 /// Give a new labeled undirected edge reading command to the reader.
637 UGraphReader& readUEdge(std::string name, UEdge& edge) {
638 uedge_reader.readUEdge(name, edge);
641 /// \brief Give a new attribute reading command.
643 /// Give a new attribute reading command.
644 template <typename Value>
645 UGraphReader& readAttribute(std::string name, Value& value) {
646 attribute_reader.readAttribute(name, value);
650 /// \brief Give a new attribute reading command.
652 /// Give a new attribute reading command.
653 template <typename ItemReader, typename Value>
654 UGraphReader& readAttribute(std::string name, Value& value,
655 const ItemReader& ir = ItemReader()) {
656 attribute_reader.readAttribute(name, value, ir);
660 /// \brief Conversion operator to LemonReader.
662 /// Conversion operator to LemonReader. It make possible
663 /// to access the encapsulated \e LemonReader, this way
664 /// you can attach to this reader new instances of
665 /// \e LemonReader::SectionReader.
666 operator LemonReader&() {
670 /// \brief Executes the reading commands.
672 /// Executes the reading commands.
678 /// \brief Returns true if the reader can give back the items by its label.
680 /// Returns true if the reader can give back the items by its label.
681 bool isLabelReader() const {
682 return nodeset_reader.isLabelReader() &&
683 uedgeset_reader.isLabelReader();
686 /// \brief Gives back the node by its label.
688 /// It reads an label from the stream and gives back which node belongs to
689 /// it. It is possible only if there was read a "label" named node map.
690 void readLabel(std::istream& is, Node& node) const {
691 return nodeset_reader.readLabel(is, node);
694 /// \brief Gives back the edge by its label
696 /// It reads an label from the stream and gives back which edge belongs to
697 /// it. It is possible only if there was read a "label" named edge map.
698 void readLabel(std::istream& is, Edge& edge) const {
699 return uedgeset_reader.readLabel(is, edge);
702 /// \brief Gives back the undirected edge by its label.
704 /// It reads an label from the stream and gives back which undirected edge
705 /// belongs to it. It is possible only if there was read a "label" named
707 void readLabel(std::istream& is, UEdge& uedge) const {
708 return uedgeset_reader.readLabel(is, uedge);
717 DefaultSkipper skipper;
719 NodeSetReader<Graph, ReaderTraits> nodeset_reader;
720 UEdgeSetReader<Graph, ReaderTraits> uedgeset_reader;
722 NodeReader<Graph> node_reader;
723 UEdgeReader<Graph> uedge_reader;
725 AttributeReader<ReaderTraits> attribute_reader;
728 /// \brief The bipartite graph reader class.
730 /// The \c BpUGraphReader class provides the graph input.
731 /// Before you read this documentation it might be useful to read the general
732 /// description of \ref graph-io-page "Graph Input-Output".
734 /// The given file format may contain several maps and labeled nodes or
737 /// If you read a graph you need not read all the maps and items just those
738 /// that you need. The interface of the \c BpUGraphReader is very similar
739 /// to the BpUGraphWriter but the reading method does not depend on the
740 /// order of the given commands.
742 /// The reader object suppose that each not read value does not contain
743 /// whitespaces, therefore it has some extra possibilities to control how
744 /// it should skip the values when the string representation contains spaces.
747 /// BpUGraphReader<ListBpUGraph> reader(std::cin, graph);
750 /// The \c readANodeMap() function reads a map from the A-part of
751 /// the\c \@bpnodeset section, while the \c readBNodeMap() reads
752 /// from the B-part of the section. If you use the \c readNodeMap()
753 /// function, then the given map should appear in both part of the
754 /// section. If there is a map that you do not want to read from the
755 /// file and there is whitespace in the string represenation of the
756 /// values then you should call the \c skipANodeMap(), \c
757 /// skipBNodeMap() or \c skipNodeMap() template member function with
758 /// proper parameters.
761 /// reader.readNodeMap("coords", coords);
762 /// reader.readANodeMap("range", range);
763 /// reader.readANodeMap("benefit", benefit);
765 /// reader.skipNodeMap("description", desc);
767 /// reader.readNodeMap("color", colorMap);
770 /// With the \c readUEdgeMap() member function you can give an
771 /// uedge map reading command similar to the NodeMaps.
774 /// reader.readUEdgeMap("capacity", capacityMap);
775 /// reader.readEdgeMap("flow", flowMap);
778 /// With \c readNode() and \c readUEdge() functions you can read
779 /// labeled Nodes and UEdges.
782 /// reader.readNode("source", sourceNode);
783 /// reader.readNode("target", targetNode);
785 /// reader.readUEdge("observed", uEdge);
788 /// With the \c readAttribute() functions you can read an attribute
789 /// in a variable. You can specify the reader for the attribute as
792 /// After you give all read commands you must call the \c run() member
793 /// function, which execute all the commands.
800 /// \see DefaultReaderTraits
801 /// \see \ref UGraphWriter
802 /// \see \ref graph-io-page
804 /// \author Balazs Dezso
805 template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
806 class BpUGraphReader {
809 typedef _Graph Graph;
810 typedef typename Graph::Node Node;
811 typedef typename Graph::Edge Edge;
812 typedef typename Graph::UEdge UEdge;
814 typedef _ReaderTraits ReaderTraits;
815 typedef typename ReaderTraits::Skipper DefaultSkipper;
817 /// \brief Construct a new BpUGraphReader.
819 /// Construct a new BpUGraphReader. It reads into the given graph
820 /// and it use the given reader as the default skipper.
821 BpUGraphReader(std::istream& _is, Graph& _graph,
822 const DefaultSkipper& _skipper = DefaultSkipper())
823 : reader(new LemonReader(_is)), own_reader(true), skipper(_skipper),
824 nodeset_reader(*reader, _graph, std::string(), skipper),
825 uedgeset_reader(*reader, _graph, nodeset_reader,
826 std::string(), skipper),
827 node_reader(*reader, nodeset_reader, std::string()),
828 uedge_reader(*reader, uedgeset_reader, std::string()),
829 attribute_reader(*reader, std::string()) {}
831 /// \brief Construct a new BpUGraphReader.
833 /// Construct a new BpUGraphReader. It reads into the given graph
834 /// and it use the given reader as the default skipper.
835 BpUGraphReader(const std::string& _filename, Graph& _graph,
836 const DefaultSkipper& _skipper = DefaultSkipper())
837 : reader(new LemonReader(_filename)), own_reader(true),
839 nodeset_reader(*reader, _graph, std::string(), skipper),
840 uedgeset_reader(*reader, _graph, nodeset_reader,
841 std::string(), skipper),
842 node_reader(*reader, nodeset_reader, std::string()),
843 uedge_reader(*reader, uedgeset_reader, std::string()),
844 attribute_reader(*reader, std::string()) {}
846 /// \brief Construct a new BpUGraphReader.
848 /// Construct a new BpUGraphReader. It reads into the given graph
849 /// and it use the given reader as the default skipper.
850 BpUGraphReader(LemonReader& _reader, Graph& _graph,
851 const DefaultSkipper& _skipper = DefaultSkipper())
852 : reader(_reader), own_reader(false), skipper(_skipper),
853 nodeset_reader(*reader, _graph, std::string(), skipper),
854 uedgeset_reader(*reader, _graph, nodeset_reader,
855 std::string(), skipper),
856 node_reader(*reader, nodeset_reader, std::string()),
857 uedge_reader(*reader, uedgeset_reader, std::string()),
858 attribute_reader(*reader, std::string()) {}
860 /// \brief Destruct the graph reader.
862 /// Destruct the graph reader.
868 /// \brief Give a new node map reading command to the reader.
870 /// Give a new node map reading command to the reader.
871 template <typename Map>
872 BpUGraphReader& readNodeMap(std::string name, Map& map) {
873 nodeset_reader.readNodeMap(name, map);
877 template <typename Map>
878 BpUGraphReader& readNodeMap(std::string name, const Map& map) {
879 nodeset_reader.readNodeMap(name, map);
883 /// \brief Give a new node map reading command to the reader.
885 /// Give a new node map reading command to the reader.
886 template <typename ItemReader, typename Map>
887 BpUGraphReader& readNodeMap(std::string name, Map& map,
888 const ItemReader& ir = ItemReader()) {
889 nodeset_reader.readNodeMap(name, map, ir);
893 template <typename ItemReader, typename Map>
894 BpUGraphReader& readNodeMap(std::string name, const Map& map,
895 const ItemReader& ir = ItemReader()) {
896 nodeset_reader.readNodeMap(name, map, ir);
900 /// \brief Give a new node map skipping command to the reader.
902 /// Give a new node map skipping command to the reader.
903 template <typename ItemReader>
904 BpUGraphReader& skipNodeMap(std::string name,
905 const ItemReader& ir = ItemReader()) {
906 nodeset_reader.skipNodeMap(name, ir);
910 /// \brief Give a new A-node map reading command to the reader.
912 /// Give a new A-node map reading command to the reader.
913 template <typename Map>
914 BpUGraphReader& readANodeMap(std::string name, Map& map) {
915 nodeset_reader.readANodeMap(name, map);
919 template <typename Map>
920 BpUGraphReader& readANodeMap(std::string name, const Map& map) {
921 nodeset_reader.readANodeMap(name, map);
925 /// \brief Give a new A-node map reading command to the reader.
927 /// Give a new A-node map reading command to the reader.
928 template <typename ItemReader, typename Map>
929 BpUGraphReader& readANodeMap(std::string name, Map& map,
930 const ItemReader& ir = ItemReader()) {
931 nodeset_reader.readANodeMap(name, map, ir);
935 template <typename ItemReader, typename Map>
936 BpUGraphReader& readANodeMap(std::string name, const Map& map,
937 const ItemReader& ir = ItemReader()) {
938 nodeset_reader.readNodeMap(name, map, ir);
942 /// \brief Give a new A-node map skipping command to the reader.
944 /// Give a new A-node map skipping command to the reader.
945 template <typename ItemReader>
946 BpUGraphReader& skipANodeMap(std::string name,
947 const ItemReader& ir = ItemReader()) {
948 nodeset_reader.skipANodeMap(name, ir);
952 /// \brief Give a new B-node map reading command to the reader.
954 /// Give a new B-node map reading command to the reader.
955 template <typename Map>
956 BpUGraphReader& readBNodeMap(std::string name, Map& map) {
957 nodeset_reader.readBNodeMap(name, map);
961 template <typename Map>
962 BpUGraphReader& readBNodeMap(std::string name, const Map& map) {
963 nodeset_reader.readBNodeMap(name, map);
967 /// \brief Give a new B-node map reading command to the reader.
969 /// Give a new B-node map reading command to the reader.
970 template <typename ItemReader, typename Map>
971 BpUGraphReader& readBNodeMap(std::string name, Map& map,
972 const ItemReader& ir = ItemReader()) {
973 nodeset_reader.readBNodeMap(name, map, ir);
977 template <typename ItemReader, typename Map>
978 BpUGraphReader& readBNodeMap(std::string name, const Map& map,
979 const ItemReader& ir = ItemReader()) {
980 nodeset_reader.readNodeMap(name, map, ir);
984 /// \brief Give a new B-node map skipping command to the reader.
986 /// Give a new B-node map skipping command to the reader.
987 template <typename ItemReader>
988 BpUGraphReader& skipBNodeMap(std::string name,
989 const ItemReader& ir = ItemReader()) {
990 nodeset_reader.skipBNodeMap(name, ir);
994 /// \brief Give a new undirected edge map reading command to the reader.
996 /// Give a new undirected edge map reading command to the reader.
997 template <typename Map>
998 BpUGraphReader& readUEdgeMap(std::string name, Map& map) {
999 uedgeset_reader.readUEdgeMap(name, map);
1003 template <typename Map>
1004 BpUGraphReader& readUEdgeMap(std::string name, const Map& map) {
1005 uedgeset_reader.readUEdgeMap(name, map);
1010 /// \brief Give a new undirected edge map reading command to the reader.
1012 /// Give a new undirected edge map reading command to the reader.
1013 template <typename ItemReader, typename Map>
1014 BpUGraphReader& readUEdgeMap(std::string name, Map& map,
1015 const ItemReader& ir = ItemReader()) {
1016 uedgeset_reader.readUEdgeMap(name, map, ir);
1020 template <typename ItemReader, typename Map>
1021 BpUGraphReader& readUEdgeMap(std::string name, const Map& map,
1022 const ItemReader& ir = ItemReader()) {
1023 uedgeset_reader.readUEdgeMap(name, map, ir);
1027 /// \brief Give a new undirected edge map skipping command to the reader.
1029 /// Give a new undirected edge map skipping command to the reader.
1030 template <typename ItemReader>
1031 BpUGraphReader& skipUEdgeMap(std::string name,
1032 const ItemReader& ir = ItemReader()) {
1033 uedgeset_reader.skipUMap(name, ir);
1038 /// \brief Give a new edge map reading command to the reader.
1040 /// Give a new edge map reading command to the reader.
1041 template <typename Map>
1042 BpUGraphReader& readEdgeMap(std::string name, Map& map) {
1043 uedgeset_reader.readEdgeMap(name, map);
1047 template <typename Map>
1048 BpUGraphReader& readEdgeMap(std::string name, const Map& map) {
1049 uedgeset_reader.readEdgeMap(name, map);
1054 /// \brief Give a new edge map reading command to the reader.
1056 /// Give a new edge map reading command to the reader.
1057 template <typename ItemReader, typename Map>
1058 BpUGraphReader& readEdgeMap(std::string name, Map& map,
1059 const ItemReader& ir = ItemReader()) {
1060 uedgeset_reader.readEdgeMap(name, map, ir);
1064 template <typename ItemReader, typename Map>
1065 BpUGraphReader& readEdgeMap(std::string name, const Map& map,
1066 const ItemReader& ir = ItemReader()) {
1067 uedgeset_reader.readEdgeMap(name, map, ir);
1071 /// \brief Give a new edge map skipping command to the reader.
1073 /// Give a new edge map skipping command to the reader.
1074 template <typename ItemReader>
1075 BpUGraphReader& skipEdgeMap(std::string name,
1076 const ItemReader& ir = ItemReader()) {
1077 uedgeset_reader.skipEdgeMap(name, ir);
1081 /// \brief Give a new labeled node reading command to the reader.
1083 /// Give a new labeled node reading command to the reader.
1084 BpUGraphReader& readNode(std::string name, Node& node) {
1085 node_reader.readNode(name, node);
1089 /// \brief Give a new labeled edge reading command to the reader.
1091 /// Give a new labeled edge reading command to the reader.
1092 BpUGraphReader& readEdge(std::string name, Edge& edge) {
1093 uedge_reader.readEdge(name, edge);
1096 /// \brief Give a new labeled undirected edge reading command to the
1099 /// Give a new labeled undirected edge reading command to the reader.
1100 BpUGraphReader& readUEdge(std::string name, UEdge& edge) {
1101 uedge_reader.readUEdge(name, edge);
1104 /// \brief Give a new attribute reading command.
1106 /// Give a new attribute reading command.
1107 template <typename Value>
1108 BpUGraphReader& readAttribute(std::string name, Value& value) {
1109 attribute_reader.readAttribute(name, value);
1113 /// \brief Give a new attribute reading command.
1115 /// Give a new attribute reading command.
1116 template <typename ItemReader, typename Value>
1117 BpUGraphReader& readAttribute(std::string name, Value& value,
1118 const ItemReader& ir = ItemReader()) {
1119 attribute_reader.readAttribute(name, value, ir);
1123 /// \brief Conversion operator to LemonReader.
1125 /// Conversion operator to LemonReader. It make possible
1126 /// to access the encapsulated \e LemonReader, this way
1127 /// you can attach to this reader new instances of
1128 /// \e LemonReader::SectionReader.
1129 operator LemonReader&() {
1133 /// \brief Executes the reading commands.
1135 /// Executes the reading commands.
1141 /// \brief Returns true if the reader can give back the items by its label.
1143 /// Returns true if the reader can give back the items by its label.
1144 bool isLabelReader() const {
1145 return nodeset_reader.isLabelReader() &&
1146 uedgeset_reader.isLabelReader();
1149 /// \brief Gives back the node by its label.
1151 /// It reads an label from the stream and gives back which node belongs to
1152 /// it. It is possible only if there was read a "label" named node map.
1153 void readLabel(std::istream& is, Node& node) const {
1154 return nodeset_reader.readLabel(is, node);
1157 /// \brief Gives back the edge by its label
1159 /// It reads an label from the stream and gives back which edge belongs to
1160 /// it. It is possible only if there was read a "label" named edge map.
1161 void readLabel(std::istream& is, Edge& edge) const {
1162 return uedgeset_reader.readLabel(is, edge);
1165 /// \brief Gives back the undirected edge by its label.
1167 /// It reads an label from the stream and gives back which undirected edge
1168 /// belongs to it. It is possible only if there was read a "label" named
1170 void readLabel(std::istream& is, UEdge& uedge) const {
1171 return uedgeset_reader.readLabel(is, uedge);
1177 LemonReader* reader;
1180 DefaultSkipper skipper;
1182 BpNodeSetReader<Graph, ReaderTraits> nodeset_reader;
1183 UEdgeSetReader<Graph, ReaderTraits> uedgeset_reader;
1185 NodeReader<Graph> node_reader;
1186 UEdgeReader<Graph> uedge_reader;
1188 AttributeReader<ReaderTraits> attribute_reader;