COIN-OR::LEMON - Graph Library

source: lemon-0.x/doc/lemon_file_format.dox @ 2370:ed6539025f27

Last change on this file since 2370:ed6539025f27 was 2216:1e45cdeea3cc, checked in by Alpar Juttner, 18 years ago

The recent progresses on the tutorial due to Mark.

File size: 7.8 KB
Line 
1namespace lemon {
2/*!
3
4
5\page lemon_file_format LEMON Graph File Format
6
7The standard graph IO enables one to store graphs and additional maps
8(i.e. functions on the nodes or edges) in a flexible and efficient way.
9Before you read this page you should be familiar with LEMON
10\ref graphs "graphs" and \ref maps-page "maps".
11
12\section format The general file format
13
14The file contains sections in the following order:
15
16\li nodeset
17\li edgeset
18\li nodes
19\li edges
20\li attributes
21
22Some of these sections can be omitted, but you will basicly need the nodeset
23section (unless your graph has no nodes at all) and the edgeset section
24(unless your graph has no edges at all).
25
26The nodeset section describes the nodes of your graph: it identifies the nodes
27and gives the maps defined on them, if any. It starts with the
28following line:
29
30<tt>\@nodeset</tt>
31
32The next line contains the names of the nodemaps, separated by whitespaces.  Each
33following line describes a node in the graph: it contains the values of the
34maps in the right order. The map named "label" should contain unique values
35because it is regarded as a label map. These labels need not be numbers but they
36must identify the nodes uniquely for later reference. For example:
37
38\code
39@nodeset
40label  x-coord  y-coord  color
413   1.0      4.0      blue
425   2.3      5.7      red
4312  7.8      2.3      green
44\endcode
45
46The edgeset section is very similar to the nodeset section, it has
47the same coloumn oriented structure. It starts with the line
48
49<tt>\@edgeset</tt>
50
51The next line contains the whitespace separated list of names of the edge
52maps.  Each of the next lines describes one edge. The first two elements in
53the line are the labels of the source and target (or tail and head) nodes of the
54edge as they occur in the label node map of the nodeset section. You can also
55have an optional label map on the edges for later reference (which has to be
56unique in this case).
57
58\code
59@edgeset
60             label      weight   note
613   5        a          4.3      a-edge
625   12       c          2.6      c-edge
633   12       g          3.4      g-edge
64\endcode
65
66The \e nodes section contains <em>labeled (distinguished) nodes</em>
67(i.e. nodes having a special
68label on them). The section starts with
69
70<tt> \@nodes </tt>
71
72Each of the next lines contains a label for a node in the graph
73and then the label as described in the \e nodeset section.
74
75\code
76@nodes
77source 3
78target 12
79\endcode
80
81The last section describes the <em>labeled (distinguished) edges</em>
82(i.e. edges having a special label on them). It starts with \c \@edges
83and then each line contains the name of the edge and the label.
84
85\code
86@edges
87observed c
88\endcode
89
90
91The file may contain empty lines and comment lines. The comment lines
92start with an \c # character.
93
94The attributes section can handle some information about the graph. It
95contains key-value pairs in each line (a key and the mapped value to key). The
96key should be a string without whitespaces, the value can be of various types.
97
98\code
99@attributes
100title "Four colored planar graph"
101author "Balazs DEZSO"
102copyright "Lemon Library"
103version 12
104\endcode
105
106Finally, the file should be closed with \c \@end line.
107
108
109\section use Using graph input-output
110
111
112The graph input and output is based on <em> reading and writing
113commands</em>. The user gives reading and writing commands to the reader or
114writer class, then he calls the \c run() method that executes all the given
115commands.
116
117\subsection write Writing a graph
118
119The \ref lemon::GraphWriter "GraphWriter" template class
120provides the graph output. To write a graph
121you should first give writing commands to the writer. You can declare
122writing command as \c NodeMap or \c EdgeMap writing and labeled Node and
123Edge writing.
124
125\code
126GraphWriter<ListGraph> writer(std::cout, graph);
127\endcode
128
129The \ref lemon::GraphWriter::writeNodeMap() "writeNodeMap()"
130function declares a \c NodeMap writing command in the
131\ref lemon::GraphWriter "GraphWriter".
132You should give a name to the map and the map
133object as parameters. The NodeMap writing command with name "label" should write a
134unique map because it will be regarded as a label map.
135
136\see IdMap, DescriptorMap 
137
138\code
139IdMap<ListGraph, Node> nodeLabelMap;
140writer.writeNodeMap("label", nodeLabelMap);
141
142writer.writeNodeMap("x-coord", xCoordMap);
143writer.writeNodeMap("y-coord", yCoordMap);
144writer.writeNodeMap("color", colorMap);
145\endcode
146
147With the \ref lemon::GraphWriter::writeEdgeMap() "writeEdgeMap()"
148member function you can give an edge map
149writing command similar to the NodeMaps.
150
151\see IdMap, DescriptorMap 
152
153\code
154DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph);
155writer.writeEdgeMap("descriptor", edgeDescMap);
156
157writer.writeEdgeMap("weight", weightMap);
158writer.writeEdgeMap("note", noteMap);
159\endcode
160
161With \ref lemon::GraphWriter::writeNode() "writeNode()"
162and \ref lemon::GraphWriter::writeEdge() "writeEdge()"
163functions you can designate Nodes and
164Edges in the graph. For example, you can write out the source and target node
165of a maximum flow instance.
166
167\code
168writer.writeNode("source", sourceNode);
169writer.writeNode("target", targetNode);
170
171writer.writeEdge("observed", edge);
172\endcode
173
174With \ref lemon::GraphWriter::writeAttribute() "writeAttribute()"
175function you can write an attribute to the file.
176
177\code
178writer.writeAttribute("author", "Balazs DEZSO");
179writer.writeAttribute("version", 12);
180\endcode
181
182After you give all write commands you must call the
183\ref lemon::GraphWriter::run() "run()" member
184function, which executes all the writing commands.
185
186\code
187writer.run();
188\endcode
189
190\subsection reading Reading a graph
191
192The file to be read may contain several maps and labeled nodes or edges.
193If you read a graph you need not read all the maps and items just those
194that you need. The interface of the \ref lemon::GraphReader "GraphReader"
195is very similar to
196the \ref lemon::GraphWriter "GraphWriter"
197but the reading method does not depend on the order of the
198given commands.
199
200The reader object assumes that each not read value does not contain
201whitespaces, therefore it has some extra possibilities to control how
202it should skip the values when the string representation contains spaces.
203
204\code
205GraphReader<ListGraph> reader(std::cin, graph);
206\endcode
207
208The \ref lemon::GraphReader::readNodeMap() "readNodeMap()"
209function reads a map from the \c nodeset section.
210If there is a map that you do not want to read from the file and there are
211whitespaces in the string represenation of the values then you should
212call the \ref lemon::GraphReader::skipNodeMap() "skipNodeMap()"
213template member function with proper parameters.
214
215\see QuotedStringReader
216
217\code
218reader.readNodeMap("x-coord", xCoordMap);
219reader.readNodeMap("y-coord", yCoordMap);
220
221reader.readNodeMap<QuotedStringReader>("label", labelMap);
222reader.skipNodeMap<QuotedStringReader>("description");
223
224reader.readNodeMap("color", colorMap);
225\endcode
226
227With the \ref lemon::GraphReader::readEdgeMap() "readEdgeMap()"
228member function you can give an edge map
229reading command similar to the NodeMaps.
230
231\code
232reader.readEdgeMap("weight", weightMap);
233reader.readEdgeMap("label", labelMap);
234\endcode
235
236With \ref lemon::GraphReader::readNode() "readNode()"
237and \ref lemon::GraphReader::readEdge() "readEdge()"
238functions you can read labeled Nodes and
239Edges.
240
241\code
242reader.readNode("source", sourceNode);
243reader.readNode("target", targetNode);
244
245reader.readEdge("observed", edge);
246\endcode
247
248With \ref lemon::GraphReader::readAttribute() "readAttribute()"
249function you can read an attribute from the file.
250
251\code
252std::string author;
253writer.readAttribute("author", author);
254int version;
255writer.writeAttribute("version", version);
256\endcode
257
258After you give all read commands you must call the
259\ref lemon::GraphReader::run() "run()" member
260function, which executes all the commands.
261
262\code
263reader.run();
264\endcode
265
266If you want to lear more, read the \ref read_write_bg "background technics".
267
268\author Balazs Dezso
269*/
270}
Note: See TracBrowser for help on using the repository browser.