- lp_test is made working.
- some more 'const' for those who like them..
5 \page graph-io-page Graph Input-Output
7 The standard graph IO makes possible to store graphs and additional maps
8 in a flexible and efficient way.
10 \section format The general file format
12 The graph file contains at most four section in the next order:
19 The nodeset section starts with the \c \@nodeset line.
20 The next line contains the names of the maps separated by whitespaces.
21 Each following line describes a node in the graph, it contains
22 in the right order the values of the maps. The map named "id" should contain
23 unique values because it regarded as ID-map.
27 id x-coord y-coord color
33 The edgeset section is very similar to the nodeset section, it has
34 same coloumn oriented structure. It starts with the line \c \@edgeset
35 The next line contains the whitespace separated list of names of the map.
36 Each of the next lines describes one edge. The first two elements in the line
37 are the ID of the source and target node as they occur in the ID node map.
47 The next section contains <em>labeled nodes</em> (i.e. nodes having a special
48 label on them). The section starts with
49 \c \@nodes. Each of the next lines contains a label for a node in the graph
50 and then the ID described in the nodeset.
58 The last section describes the <em>labeled edges</em>
59 (i.e. edges having a special label on them). It starts with \c \@edges
60 and then each line contains the name of the edge and the ID.
67 The file ends with the \c \@end line.
69 The file may contain empty lines and comment lines. The comment lines
70 start with an \c # character.
76 \section use Using graph input-output
77 The graph input and output based on writing and reading commands. The user
78 adds writing and reading commands for the reader or writer class, then
79 calls the \c run() method that executes all the given commands.
81 \subsection write Writing a graph
83 The \c GraphWriter class provides the graph output. To write a graph
84 you should first give writing commands for the writer. You can declare
85 write command as \c NodeMap or \c EdgeMap writing and labeled Node and
89 GraphWriter<ListGraph> writer(std::cout, graph);
92 The \c writeNodeMap() function declares a \c NodeMap writing command in the
93 \c GraphWriter. You should give as parameter the name of the map and the map
94 object. The NodeMap writing command with name "id" should write a
95 unique map because it is regarded as ID map.
97 \see IdMap, DescriptorMap
100 IdMap<ListGraph, Node> nodeIdMap;
101 writer.writeNodeMap("id", nodeIdMap);
103 writer.writeNodeMap("x-coord", xCoordMap);
104 writer.writeNodeMap("y-coord", yCoordMap);
105 writer.writeNodeMap("color", colorMap);
108 With the \c writeEdgeMap() member function you can give an edge map
109 writing command similar to the NodeMaps.
111 \see IdMap, DescriptorMap
113 DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph);
114 writer.writeEdgeMap("descriptor", edgeDescMap);
116 writer.writeEdgeMap("weight", weightMap);
117 writer.writeEdgeMap("label", labelMap);
120 With \c writeNode() and \c writeEdge() functions you can point out Nodes and
121 Edges in the graph. By example, you can write out the source and target
125 writer.writeNode("source", sourceNode);
126 writer.writeNode("target", targetNode);
128 writer.writeEdge("observed", edge);
131 After you give all write commands you must call the \c run() member
132 function, which execute all the writer commands.
138 \subsection reading Reading a graph
140 The given file format may contain several maps and labeled nodes or edges.
141 If you read a graph you need not read all the maps and items just those
142 that you need. The interface of the \c GraphReader is very similar to
143 the GraphWriter but the reading method does not depend on the order the
146 The reader object suppose that each not readed value does not contain
147 whitespaces, therefore it has some extra possibilities to control how
148 it should skip the values when the string representation contains spaces.
151 GraphReader<ListGraph> reader(std::cin, graph);
154 The \c readNodeMap() function reads a map from the \c \@nodeset section.
155 If there is a map that you do not want to read from the file and there is
156 whitespace in the string represenation of the values then you should
157 call the \c skipNodeMap() template member function with proper parameters.
159 \see QuotedStringReader
161 reader.readNodeMap("x-coord", xCoordMap);
162 reader.readNodeMap("y-coord", yCoordMap);
164 reader.readNodeMap<QuotedStringReader>("label", labelMap);
165 reader.skipNodeMap<QuotedStringReader>("description");
167 reader.readNodeMap("color", colorMap);
170 With the \c readEdgeMap() member function you can give an edge map
171 reading command similar to the NodeMaps.
174 reader.readEdgeMap("weight", weightMap);
175 reader.readEdgeMap("label", labelMap);
178 With \c readNode() and \c readEdge() functions you can read labeled Nodes and
182 reader.readNode("source", sourceNode);
183 reader.readNode("target", targetNode);
185 reader.readEdge("observed", edge);
188 After you give all read commands you must call the \c run() member
189 function, which execute all the commands.
195 \section types The background of the Reading and Writing
196 The \c GraphReader should know how can read a Value from the given map.
197 By the default implementation the input operator reads a value from
198 the stream and the type of the readed value is the value type of the given map.
199 When the reader should skip a value in the stream, because you do not
200 want to store it in map, the reader skips a character sequence without
203 If you want to change the functionality of the reader, you can use
204 template parameters to specialize it. When you give a reading
205 command for a map you can give a Reader type as template parameter.
206 With this template parameter you can control how the Reader reads
207 a value from the stream.
209 The reader has the next structure:
212 typedef TypeName Value;
214 void read(std::istream& is, Value& value);
218 By example, the \c "strings" nodemap contains strings and you do not need
219 the value of the string just the length. Then you can implement own Reader
223 struct LengthReader {
226 void read(std::istream& is, Value& value) {
229 value = tmp.length();
233 reader.readNodeMap<LengthReader>("strings", lengthMap);
236 The global functionality of the reader class can be changed by giving a
237 special template parameter for the GraphReader class. By default, the
238 template parameter is \c DefaultReaderTraits. A reader traits class
239 should provide an inner template class Reader for each type, and an
240 DefaultReader for skipping a value.
242 The specialization of the writing should be very similar to the reading.