doc/graph_io.dox
changeset 1284 b941d044f87b
parent 1114 eb57527fd183
child 1333 2640cf6547ff
equal deleted inserted replaced
0:4a9aa541f51c 1:ac02b3fe98d4
       
     1 namespace lemon {
     1 /*!
     2 /*!
     2 
     3 
     3 
     4 
     4 
     5 
     5 \page graph-io-page Graph Input-Output
     6 \page graph-io-page Graph Input-Output
     6 
     7 
     7 The standard graph IO makes possible to store graphs and additional maps
     8 The standard graph IO makes possible to store graphs and additional maps
     8 in flexible and efficient way. 
     9 in a flexible and efficient way. 
     9 
    10 
    10 \section format The general file format
    11 \section format The general file format
    11 
    12 
    12 The graph file contains at most four section in the next order:
    13 The graph file contains at most four section in the next order:
    13 
    14 
    31 \endcode
    32 \endcode
    32 
    33 
    33 The edgeset section is very similar to the nodeset section, it has
    34 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 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 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 element in the line
    37 Each of the next lines describes one edge. The first two elements in the line
    37 is the ID of the source and target node as occurs in the first node map. 
    38 are the ID of the source and target node as they occur in the first node map. 
    38 
    39 
    39 \code
    40 \code
    40 @edgeset
    41 @edgeset
    41              id    weight   label
    42              id    weight   label
    42 3   5        a     4.3      a-edge
    43 3   5        a     4.3      a-edge
    43 5   12       c     2.6      c-edge
    44 5   12       c     2.6      c-edge
    44 3   12       g     3.4      g-edge
    45 3   12       g     3.4      g-edge
    45 \endcode
    46 \endcode
    46 
    47 
    47 The next section contains outpointed nodes. The section starts with
    48 The next section contains <em>labeles nodes</em> (i.e. nodes having a special
       
    49 label on them). The section starts with
    48 \c \@nodes. Each of the next lines contains a label for a node in the graph 
    50 \c \@nodes. Each of the next lines contains a label for a node in the graph 
    49 and then the ID described in the first column in the nodeset.
    51 and then the ID described in the first column in the nodeset.
    50 
    52 
    51 \code
    53 \code
    52 @nodes 
    54 @nodes 
    53 source 3
    55 source 3
    54 target 12
    56 target 12
    55 \endcode
    57 \endcode
    56 
    58 
    57 The last section describes the outpointed edges. It starts with \c \@edges
    59 The last section describes the <em>labeles edges</em>
       
    60 (i.e. edges having a special
       
    61 label on them). It starts with \c \@edges
    58 and then each line contains the name of the edge and the ID.
    62 and then each line contains the name of the edge and the ID.
    59 
    63 
    60 \code
    64 \code
    61 @nodes 
    65 @nodes 
    62 observed c
    66 observed c
    71 @end
    75 @end
    72 \endcode
    76 \endcode
    73 
    77 
    74 \section use Using graph input-output
    78 \section use Using graph input-output
    75 The graph input and output based on writing and reading commands. The user
    79 The graph input and output based on writing and reading commands. The user
    76 adds writing and reading commands for the reader or writer class, after 
    80 adds writing and reading commands for the reader or writer class, then 
    77 calls the \c run() method what executes all the given commands.
    81 calls the \c run() method that executes all the given commands.
    78 
    82 
    79 \subsection write Writing a graph
    83 \subsection write Writing a graph
    80 
    84 
    81 The \c GraphWriter class provides the graph output. To write a graph
    85 The \c GraphWriter class provides the graph output. To write a graph
    82 you should first give writing commands for the writer. You can declare
    86 you should first give writing commands for the writer. You can declare
    83 write command as \c NodeMap or \c EdgeMap writing and outpointed Node and
    87 write command as \c NodeMap or \c EdgeMap writing and labeled Node and
    84 Edge writing.
    88 Edge writing.
    85 
    89 
    86 \code
    90 \code
    87 GraphWriter<ListGraph> writer(graph);
    91 GraphWriter<ListGraph> writer(graph);
    88 \endcode
    92 \endcode
    89 
    93 
    90 The \c addNodeMap() function declares a \c NodeMap writing command in the
    94 The \c addNodeMap() function declares a \c NodeMap writing command in the
    91 \c GraphWriter. You should give as parameter the name of the map and the map
    95 \c GraphWriter. You should give as parameter the name of the map and the map
    92 object. The first NodeMap writing command should write an unique map because
    96 object. The first NodeMap writing command should write a unique map because
    93 it is regarded as ID map.
    97 it is regarded as ID map.
    94 
    98 
    95 \see IdMap, DescriptorMap  
    99 \see IdMap, DescriptorMap  
    96 
   100 
    97 \code
   101 \code
   126 
   130 
   127 writer.addEdge("observed", edge);
   131 writer.addEdge("observed", edge);
   128 \endcode
   132 \endcode
   129 
   133 
   130 After you give all write commands you must call the \c run() member
   134 After you give all write commands you must call the \c run() member
   131 function, what execute all the write commands.
   135 function, which execute all the write commands.
   132 
   136 
   133 \code
   137 \code
   134 writer.run();
   138 writer.run();
   135 \endcode
   139 \endcode
   136 
   140 
   137 \subsection reading Reading a graph
   141 \subsection reading Reading a graph
   138 
   142 
   139 The given file format may contain many maps and outpointed nodes or edges.
   143 The given file format may contain several maps and labeled nodes or edges.
   140 If you read a graph you need not read all the maps and items just those
   144 If you read a graph you need not read all the maps and items just those
   141 that you need. The interface of the \c GraphReader is very similar to
   145 that you need. The interface of the \c GraphReader is very similar to
   142 the GraphWriter but the reading method does not depend on the order the
   146 the GraphWriter but the reading method does not depend on the order the
   143 given commands.
   147 given commands.
   144 
   148 
   145 The reader object suppose that each not readed value does not contains 
   149 The reader object suppose that each not readed value does not contain 
   146 whitespaces therefore it has some extra possibilities to control how could
   150 whitespaces, therefore it has some extra possibilities to control how
   147 it skip the values when the string representation contains spaces.
   151 it should skip the values when the string representation contains spaces.
   148 
   152 
   149 \code
   153 \code
   150 GraphReader<ListGraph> reader(graph);
   154 GraphReader<ListGraph> reader(graph);
   151 \endcode
   155 \endcode
   152 
   156 
   153 The \c addNodeMap() function reads a map from the \c \@nodeset section.
   157 The \c addNodeMap() function reads a map from the \c \@nodeset section.
   154 If there is a map what you do not want to read from the file and there is
   158 If there is a map that you do not want to read from the file and there is
   155 whitespace in the string represenation of the values then you should
   159 whitespace in the string represenation of the values then you should
   156 call the \c skipNodeMap() template member function with proper parameters.
   160 call the \c skipNodeMap() template member function with proper parameters.
   157 
   161 
   158 \see QuotedStringReader
   162 \see QuotedStringReader
   159 \code
   163 \code
   172 \code
   176 \code
   173 reader.addEdgeMap("weight", weightMap);
   177 reader.addEdgeMap("weight", weightMap);
   174 reader.addEdgeMap("label", labelMap);
   178 reader.addEdgeMap("label", labelMap);
   175 \endcode
   179 \endcode
   176 
   180 
   177 With \c addNode() and \c addEdge() functions you can read outpointed Nodes and
   181 With \c addNode() and \c addEdge() functions you can read labeled Nodes and
   178 Edges.
   182 Edges.
   179 
   183 
   180 \code
   184 \code
   181 reader.addNode("source", sourceNode);
   185 reader.addNode("source", sourceNode);
   182 reader.addNode("target", targetNode);
   186 reader.addNode("target", targetNode);
   183 
   187 
   184 reader.addEdge("observed", edge);
   188 reader.addEdge("observed", edge);
   185 \endcode
   189 \endcode
   186 
   190 
   187 After you give all read commands you must call the \c run() member
   191 After you give all read commands you must call the \c run() member
   188 function, what execute all the commands.
   192 function, which execute all the commands.
   189 
   193 
   190 \code
   194 \code
   191 reader.run();
   195 reader.run();
   192 \endcode
   196 \endcode
   193 
   197 
   231 ...
   235 ...
   232 reader.addNodeMap<LengthReader>("strings", lengthMap);
   236 reader.addNodeMap<LengthReader>("strings", lengthMap);
   233 \endcode  
   237 \endcode  
   234 
   238 
   235 The global functionality of the reader class can be changed by giving a
   239 The global functionality of the reader class can be changed by giving a
   236 special template parameter for the GraphReader class. In default way the
   240 special template parameter for the GraphReader class. By default, the
   237 template parameter the \c DefaultReaderTraits. A reader traits class 
   241 template parameter is \c DefaultReaderTraits. A reader traits class 
   238 should provide an inner template class Reader for each type, and an 
   242 should provide an inner template class Reader for each type, and an 
   239 DefaultReader for skipping a value.
   243 DefaultReader for skipping a value.
   240 
   244 
   241 The specialization of the writing should be very similar to the reading.
   245 The specialization of the writing should be very similar to the reading.
   242 
   246 
   243 
   247 
   244 */
   248 */
       
   249 }