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