doc/graph_io.dox
changeset 1901 723b2b81d900
parent 1848 291764ce6d91
child 1909 2d806130e700
equal deleted inserted replaced
13:71a95f67888e 14:ed204329ab82
    29 
    29 
    30 <tt>\@nodeset</tt>
    30 <tt>\@nodeset</tt>
    31 
    31 
    32 The next line contains the names of the nodemaps, separated by whitespaces.  Each
    32 The next line contains the names of the nodemaps, separated by whitespaces.  Each
    33 following line describes a node in the graph: it contains the values of the
    33 following line describes a node in the graph: it contains the values of the
    34 maps in the right order. The map named "id" should contain unique values
    34 maps in the right order. The map named "label" should contain unique values
    35 because it is regarded as an ID-map. These ids need not be numbers but they
    35 because it is regarded as a label map. These labels need not be numbers but they
    36 must identify the nodes uniquely for later reference. For example:
    36 must identify the nodes uniquely for later reference. For example:
    37 
    37 
    38 \code
    38 \code
    39 @nodeset
    39 @nodeset
    40 id  x-coord  y-coord  color
    40 label  x-coord  y-coord  color
    41 3   1.0      4.0      blue
    41 3   1.0      4.0      blue
    42 5   2.3      5.7      red
    42 5   2.3      5.7      red
    43 12  7.8      2.3      green
    43 12  7.8      2.3      green
    44 \endcode
    44 \endcode
    45 
    45 
    48 
    48 
    49 <tt>\@edgeset</tt>
    49 <tt>\@edgeset</tt>
    50 
    50 
    51 The next line contains the whitespace separated list of names of the edge
    51 The next line contains the whitespace separated list of names of the edge
    52 maps.  Each of the next lines describes one edge. The first two elements in
    52 maps.  Each of the next lines describes one edge. The first two elements in
    53 the line are the IDs of the source and target (or tail and head) nodes of the
    53 the line are the labels of the source and target (or tail and head) nodes of the
    54 edge as they occur in the ID node map of the nodeset section. You can also
    54 edge as they occur in the label node map of the nodeset section. You can also
    55 have an optional ID map on the edges for later reference (which has to be
    55 have an optional label map on the edges for later reference (which has to be
    56 unique in this case).
    56 unique in this case).
    57 
    57 
    58 \code
    58 \code
    59 @edgeset
    59 @edgeset
    60              id    weight   label
    60              label      weight   note
    61 3   5        a     4.3      a-edge
    61 3   5        a          4.3      a-edge
    62 5   12       c     2.6      c-edge
    62 5   12       c          2.6      c-edge
    63 3   12       g     3.4      g-edge
    63 3   12       g          3.4      g-edge
    64 \endcode
    64 \endcode
    65 
    65 
    66 The \e nodes section contains <em>labeled (distinguished) nodes</em> 
    66 The \e nodes section contains <em>labeled (distinguished) nodes</em> 
    67 (i.e. nodes having a special
    67 (i.e. nodes having a special
    68 label on them). The section starts with
    68 label on them). The section starts with
    69 
    69 
    70 <tt> \@nodes </tt>
    70 <tt> \@nodes </tt>
    71 
    71 
    72 Each of the next lines contains a label for a node in the graph 
    72 Each of the next lines contains a label for a node in the graph 
    73 and then the ID as described in the \e nodeset section.
    73 and then the label as described in the \e nodeset section.
    74 
    74 
    75 \code
    75 \code
    76 @nodes 
    76 @nodes 
    77 source 3
    77 source 3
    78 target 12
    78 target 12
    79 \endcode
    79 \endcode
    80 
    80 
    81 The last section describes the <em>labeled (distinguished) edges</em>
    81 The last section describes the <em>labeled (distinguished) edges</em>
    82 (i.e. edges having a special label on them). It starts with \c \@edges
    82 (i.e. edges having a special label on them). It starts with \c \@edges
    83 and then each line contains the name of the edge and the ID.
    83 and then each line contains the name of the edge and the label.
    84 
    84 
    85 \code
    85 \code
    86 @edges 
    86 @edges 
    87 observed c
    87 observed c
    88 \endcode
    88 \endcode
   101 author "Balazs DEZSO"
   101 author "Balazs DEZSO"
   102 copyright "Lemon Library"
   102 copyright "Lemon Library"
   103 version 12
   103 version 12
   104 \endcode
   104 \endcode
   105 
   105 
   106 <tt> \@end </tt>
   106 Finally, the file should be closed with \c \@end line.
   107 
       
   108 line.
       
   109 
   107 
   110 
   108 
   111 \section use Using graph input-output
   109 \section use Using graph input-output
   112 
   110 
   113 
   111 
   130 
   128 
   131 The \ref lemon::GraphWriter::writeNodeMap() "writeNodeMap()"
   129 The \ref lemon::GraphWriter::writeNodeMap() "writeNodeMap()"
   132 function declares a \c NodeMap writing command in the
   130 function declares a \c NodeMap writing command in the
   133 \ref lemon::GraphWriter "GraphWriter".
   131 \ref lemon::GraphWriter "GraphWriter".
   134 You should give a name to the map and the map
   132 You should give a name to the map and the map
   135 object as parameters. The NodeMap writing command with name "id" should write a 
   133 object as parameters. The NodeMap writing command with name "label" should write a 
   136 unique map because it will be regarded as an ID map.
   134 unique map because it will be regarded as a label map.
   137 
   135 
   138 \see IdMap, DescriptorMap  
   136 \see IdMap, DescriptorMap  
   139 
   137 
   140 \code
   138 \code
   141 IdMap<ListGraph, Node> nodeIdMap;
   139 IdMap<ListGraph, Node> nodeLabelMap;
   142 writer.writeNodeMap("id", nodeIdMap);
   140 writer.writeNodeMap("label", nodeLabelMap);
   143 
   141 
   144 writer.writeNodeMap("x-coord", xCoordMap);
   142 writer.writeNodeMap("x-coord", xCoordMap);
   145 writer.writeNodeMap("y-coord", yCoordMap);
   143 writer.writeNodeMap("y-coord", yCoordMap);
   146 writer.writeNodeMap("color", colorMap);
   144 writer.writeNodeMap("color", colorMap);
   147 \endcode
   145 \endcode
   155 \code
   153 \code
   156 DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph);
   154 DescriptorMap<ListGraph, Edge, ListGraph::EdgeMap<int> > edgeDescMap(graph);
   157 writer.writeEdgeMap("descriptor", edgeDescMap);
   155 writer.writeEdgeMap("descriptor", edgeDescMap);
   158 
   156 
   159 writer.writeEdgeMap("weight", weightMap);
   157 writer.writeEdgeMap("weight", weightMap);
   160 writer.writeEdgeMap("label", labelMap);
   158 writer.writeEdgeMap("note", noteMap);
   161 \endcode
   159 \endcode
   162 
   160 
   163 With \ref lemon::GraphWriter::writeNode() "writeNode()"
   161 With \ref lemon::GraphWriter::writeNode() "writeNode()"
   164 and \ref lemon::GraphWriter::writeEdge() "writeEdge()"
   162 and \ref lemon::GraphWriter::writeEdge() "writeEdge()"
   165 functions you can designate Nodes and
   163 functions you can designate Nodes and
   312 \endcode  
   310 \endcode  
   313 
   311 
   314 The global functionality of the reader class can be changed by giving a
   312 The global functionality of the reader class can be changed by giving a
   315 special template parameter to the GraphReader class. By default, the
   313 special template parameter to the GraphReader class. By default, the
   316 template parameter is \c DefaultReaderTraits. A reader traits class 
   314 template parameter is \c DefaultReaderTraits. A reader traits class 
   317 should provide an inner template class Reader for each type, and a 
   315 should provide a nested template class Reader for each type, and a 
   318 DefaultReader for skipping a value.
   316 DefaultReader for skipping a value.
   319 
   317 
   320 The specialization of  writing is very similar to that of reading.
   318 The specialization of writing is very similar to that of reading.
   321 
   319 
   322 \section undir Undirected graphs
   320 \section undir Undirected graphs
   323 
   321 
   324 In a file describing an undirected graph (undir graph, for short) you find an
   322 In a file describing an undirected graph (undir graph, for short) you find an
   325 \c undiredgeset section instead of the \c edgeset section. The first line of
   323 \c undiredgeset section instead of the \c edgeset section. The first line of
   331 are two maps with names being the same with a \c '+' and a \c '-' prefix
   329 are two maps with names being the same with a \c '+' and a \c '-' prefix
   332 then this will be read as a directed map.
   330 then this will be read as a directed map.
   333 
   331 
   334 \code
   332 \code
   335 @undiredgeset
   333 @undiredgeset
   336              id    capacity +flow -flow
   334              label      capacity        +flow   -flow
   337 32   2       1     4.3      2.0	  0.0
   335 32   2       1          4.3             2.0     0.0
   338 21   21      5     2.6      0.0   2.6
   336 21   21      5          2.6             0.0     2.6
   339 21   12      8     3.4      0.0   0.0
   337 21   12      8          3.4             0.0     0.0
   340 \endcode
   338 \endcode
   341 
   339 
   342 The \c edges section is changed to \c undiredges section. This section
   340 The \c edges section is changed to \c undiredges section. This section
   343 describes labeled edges and undirected edges. The directed edge label
   341 describes labeled edges and undirected edges. The directed edge label
   344 should start with a \c '+' or a \c '-' prefix to decide the direction
   342 should start with a \c '+' or a \c '-' prefix to decide the direction
   459 \endcode
   457 \endcode
   460 
   458 
   461 Because both the \ref lemon::GraphReader "GraphReader"
   459 Because both the \ref lemon::GraphReader "GraphReader"
   462 and the \ref lemon::UndirGraphReader "UndirGraphReader" can be converted
   460 and the \ref lemon::UndirGraphReader "UndirGraphReader" can be converted
   463 to \ref lemon::LemonReader "LemonReader"
   461 to \ref lemon::LemonReader "LemonReader"
   464 and it can resolve the ID's of the items, the previous
   462 and it can resolve the label's of the items, the previous
   465 result can be achived with the \ref lemon::UndirGraphReader "UndirGraphReader"
   463 result can be achived with the \ref lemon::UndirGraphReader "UndirGraphReader"
   466 class, too.
   464 class, too.
   467 
   465 
   468 
   466 
   469 \code
   467 \code