doc/graph_io.dox
changeset 1522 321661278137
parent 1394 f0c48d7fa73d
child 1526 8c14aa8f27a2
equal deleted inserted replaced
3:1ab0553929ac 4:e5009c503812
     2 /*!
     2 /*!
     3 
     3 
     4 
     4 
     5 \page graph-io-page Graph Input-Output
     5 \page graph-io-page Graph Input-Output
     6 
     6 
     7 The standard graph IO makes possible to store graphs and additional maps
     7 The standard graph IO enables to store graphs and additional maps
     8 in a flexible and efficient way. 
     8 in a flexible and efficient way. 
     9 
     9 
    10 \section format The general file format
    10 \section format The general file format
    11 
    11 
    12 The graph file contains at most four section in the next order:
    12 The file contains at most four sections in the following order:
    13 
    13 
    14 \li nodeset
    14 \li nodeset
    15 \li edgeset
    15 \li edgeset
    16 \li nodes
    16 \li nodes
    17 \li edges
    17 \li edges
    18 
    18 
    19 The nodeset section starts with the \c \@nodeset line.
    19 The nodeset section starts with the following line:
    20 The next line contains the names of the maps separated by whitespaces.
    20 
    21 Each following line describes a node in the graph, it contains
    21 <tt>\@nodeset</tt>
    22 in the right order the values of the maps. The map named "id" should contain
    22 
    23 unique values because it regarded as ID-map. 
    23 The next line contains the names of the nodemaps, separated by whitespaces.  Each
       
    24 following line describes a node in the graph: it contains the values of the
       
    25 maps in the right order. The map named "id" should contain unique values
       
    26 because it is regarded as an ID-map. For example:
    24 
    27 
    25 \code
    28 \code
    26 @nodeset
    29 @nodeset
    27 id  x-coord  y-coord  color
    30 id  x-coord  y-coord  color
    28 3   1.0      4.0      blue
    31 3   1.0      4.0      blue
    29 5   2.3      5.7      red
    32 5   2.3      5.7      red
    30 12  7.8      2.3      green
    33 12  7.8      2.3      green
    31 \endcode
    34 \endcode
    32 
    35 
    33 The edgeset section is very similar to the nodeset section, it has
    36 The edgeset section is very similar to the nodeset section, it has
    34 same coloumn oriented structure. It starts with the line \c \@edgeset
    37 the same coloumn oriented structure. It starts with the line 
    35 The next line contains the whitespace separated list of names of the map.
    38 
       
    39 <tt>\@edgeset</tt>
       
    40 
       
    41 The next line contains the whitespace separated list of names of the maps.
    36 Each of the next lines describes one edge. The first two elements in the line
    42 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. 
    43 are the IDs of the source and target (or tail and head) node of the edge as they occur in the ID node
       
    44 map. You can also have an optional ID map on the edges for later reference.
    38 
    45 
    39 \code
    46 \code
    40 @edgeset
    47 @edgeset
    41              id    weight   label
    48              id    weight   label
    42 3   5        a     4.3      a-edge
    49 3   5        a     4.3      a-edge
    44 3   12       g     3.4      g-edge
    51 3   12       g     3.4      g-edge
    45 \endcode
    52 \endcode
    46 
    53 
    47 The next section contains <em>labeled nodes</em> (i.e. nodes having a special
    54 The next section contains <em>labeled nodes</em> (i.e. nodes having a special
    48 label on them). The section starts with
    55 label on them). The section starts with
    49 \c \@nodes. Each of the next lines contains a label for a node in the graph 
    56 
    50 and then the ID described in the nodeset.
    57 <tt> \@nodes </tt>
       
    58 
       
    59 Each of the next lines contains a label for a node in the graph 
       
    60 and then the ID described in the nodeset section.
    51 
    61 
    52 \code
    62 \code
    53 @nodes 
    63 @nodes 
    54 source 3
    64 source 3
    55 target 12
    65 target 12
    62 \code
    72 \code
    63 @nodes 
    73 @nodes 
    64 observed c
    74 observed c
    65 \endcode
    75 \endcode
    66 
    76 
    67 The file ends with the \c \@end line.
       
    68 
    77 
    69 The file may contain empty lines and comment lines. The comment lines
    78 The file may contain empty lines and comment lines. The comment lines
    70 start with an \c # character.
    79 start with an \c # character.
    71 
    80 
    72 \code
    81 The file ends with the 
    73 @end
    82 
    74 \endcode
    83 <tt> \@end </tt>
       
    84 
       
    85 line.
       
    86 
    75 
    87 
    76 \section use Using graph input-output
    88 \section use Using graph input-output
    77 The graph input and output based on writing and reading commands. The user
    89 The graph input and output is based on reading and writing  commands. The user
    78 adds writing and reading commands for the reader or writer class, then 
    90 adds reading and writing commands to the reader or writer class, then he
    79 calls the \c run() method that executes all the given commands.
    91 calls the \c run() method that executes all the given commands.
    80 
    92 
    81 \subsection write Writing a graph
    93 \subsection write Writing a graph
    82 
    94 
    83 The \c GraphWriter class provides the graph output. To write a graph
    95 The \c GraphWriter class provides the graph output. To write a graph
    88 \code
   100 \code
    89 GraphWriter<ListGraph> writer(std::cout, graph);
   101 GraphWriter<ListGraph> writer(std::cout, graph);
    90 \endcode
   102 \endcode
    91 
   103 
    92 The \c writeNodeMap() function declares a \c NodeMap writing command in the
   104 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
   105 \c GraphWriter. You should give a name of the map and the map
    94 object. The NodeMap writing command with name "id" should write a 
   106 object as parameters. The NodeMap writing command with name "id" should write a 
    95 unique map because it is regarded as ID map.
   107 unique map because it is regarded as ID map.
    96 
   108 
    97 \see IdMap, DescriptorMap  
   109 \see IdMap, DescriptorMap  
    98 
   110 
    99 \code
   111 \code
   107 
   119 
   108 With the \c writeEdgeMap() member function you can give an edge map
   120 With the \c writeEdgeMap() member function you can give an edge map
   109 writing command similar to the NodeMaps.
   121 writing command similar to the NodeMaps.
   110 
   122 
   111 \see IdMap, DescriptorMap  
   123 \see IdMap, DescriptorMap  
       
   124 
   112 \code
   125 \code
   113 DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph);
   126 DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph);
   114 writer.writeEdgeMap("descriptor", edgeDescMap);
   127 writer.writeEdgeMap("descriptor", edgeDescMap);
   115 
   128 
   116 writer.writeEdgeMap("weight", weightMap);
   129 writer.writeEdgeMap("weight", weightMap);
   117 writer.writeEdgeMap("label", labelMap);
   130 writer.writeEdgeMap("label", labelMap);
   118 \endcode
   131 \endcode
   119 
   132 
   120 With \c writeNode() and \c writeEdge() functions you can point out Nodes and
   133 With \c writeNode() and \c writeEdge() functions you can designate Nodes and
   121 Edges in the graph. By example, you can write out the source and target
   134 Edges in the graph. For example, you can write out the source and target node
   122 of the graph.
   135 of a maximum flow instance.
   123 
   136 
   124 \code
   137 \code
   125 writer.writeNode("source", sourceNode);
   138 writer.writeNode("source", sourceNode);
   126 writer.writeNode("target", targetNode);
   139 writer.writeNode("target", targetNode);
   127 
   140 
   128 writer.writeEdge("observed", edge);
   141 writer.writeEdge("observed", edge);
   129 \endcode
   142 \endcode
   130 
   143 
   131 After you give all write commands you must call the \c run() member
   144 After you give all write commands you must call the \c run() member
   132 function, which execute all the writer commands.
   145 function, which executes all the writing commands.
   133 
   146 
   134 \code
   147 \code
   135 writer.run();
   148 writer.run();
   136 \endcode
   149 \endcode
   137 
   150 
   138 \subsection reading Reading a graph
   151 \subsection reading Reading a graph
   139 
   152 
   140 The given file format may contain several maps and labeled nodes or edges.
   153 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
   154 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
   155 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
   156 the GraphWriter but the reading method does not depend on the order of the
   144 given commands.
   157 given commands.
   145 
   158 
   146 The reader object suppose that each not readed value does not contain 
   159 The reader object assumes that each not readed value does not contain 
   147 whitespaces, therefore it has some extra possibilities to control how
   160 whitespaces, therefore it has some extra possibilities to control how
   148 it should skip the values when the string representation contains spaces.
   161 it should skip the values when the string representation contains spaces.
   149 
   162 
   150 \code
   163 \code
   151 GraphReader<ListGraph> reader(std::cin, graph);
   164 GraphReader<ListGraph> reader(std::cin, graph);
   152 \endcode
   165 \endcode
   153 
   166 
   154 The \c readNodeMap() function reads a map from the \c \@nodeset section.
   167 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
   168 If there is a map that you do not want to read from the file and there are
   156 whitespace in the string represenation of the values then you should
   169 whitespaces in the string represenation of the values then you should
   157 call the \c skipNodeMap() template member function with proper parameters.
   170 call the \c skipNodeMap() template member function with proper parameters.
   158 
   171 
   159 \see QuotedStringReader
   172 \see QuotedStringReader
       
   173 
   160 \code
   174 \code
   161 reader.readNodeMap("x-coord", xCoordMap);
   175 reader.readNodeMap("x-coord", xCoordMap);
   162 reader.readNodeMap("y-coord", yCoordMap);
   176 reader.readNodeMap("y-coord", yCoordMap);
   163 
   177 
   164 reader.readNodeMap<QuotedStringReader>("label", labelMap);
   178 reader.readNodeMap<QuotedStringReader>("label", labelMap);
   184 
   198 
   185 reader.readEdge("observed", edge);
   199 reader.readEdge("observed", edge);
   186 \endcode
   200 \endcode
   187 
   201 
   188 After you give all read commands you must call the \c run() member
   202 After you give all read commands you must call the \c run() member
   189 function, which execute all the commands.
   203 function, which executes all the commands.
   190 
   204 
   191 \code
   205 \code
   192 reader.run();
   206 reader.run();
   193 \endcode
   207 \endcode
   194 
   208 
   195 \section types The background of the Reading and Writing
   209 \section types The background of Reading and Writing
   196 The \c GraphReader should know how can read a Value from the given map.
   210 The \c GraphReader should know how to read a Value from the given map.
   197 By the default implementation the input operator reads a value from
   211 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.
   212 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
   213 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 
   214 want to store it in map, the reader skips a character sequence without 
   201 whitespace. 
   215 whitespace.