doc/graph_io.dox
changeset 1948 9e9c035a08be
parent 1901 723b2b81d900
child 1959 264811b995f3
equal deleted inserted replaced
14:ed204329ab82 15:02da8463f3db
   315 should provide a nested template class Reader for each type, and a 
   315 should provide a nested template class Reader for each type, and a 
   316 DefaultReader for skipping a value.
   316 DefaultReader for skipping a value.
   317 
   317 
   318 The specialization of writing is very similar to that of reading.
   318 The specialization of writing is very similar to that of reading.
   319 
   319 
   320 \section undir Undirected graphs
   320 \section u Undirected graphs
   321 
   321 
   322 In a file describing an undirected graph (undir graph, for short) you find an
   322 In a file describing an undirected graph (ugraph, for short) you find an
   323 \c undiredgeset section instead of the \c edgeset section. The first line of
   323 \c uedgeset section instead of the \c edgeset section. The first line of
   324 the section describes the names of the maps on the undirected egdes and all
   324 the section describes the names of the maps on the undirected egdes and all
   325 next lines describe one undirected edge with the the incident nodes and the
   325 next lines describe one undirected edge with the the incident nodes and the
   326 values of the map.
   326 values of the map.
   327 
   327 
   328 The format handles directed edge maps as a syntactical sugar???, if there
   328 The format handles directed edge maps as a syntactical sugar???, if there
   329 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
   330 then this will be read as a directed map.
   330 then this will be read as a directed map.
   331 
   331 
   332 \code
   332 \code
   333 @undiredgeset
   333 @uedgeset
   334              label      capacity        +flow   -flow
   334              label      capacity        +flow   -flow
   335 32   2       1          4.3             2.0     0.0
   335 32   2       1          4.3             2.0     0.0
   336 21   21      5          2.6             0.0     2.6
   336 21   21      5          2.6             0.0     2.6
   337 21   12      8          3.4             0.0     0.0
   337 21   12      8          3.4             0.0     0.0
   338 \endcode
   338 \endcode
   339 
   339 
   340 The \c edges section is changed to \c undiredges section. This section
   340 The \c edges section is changed to \c uedges section. This section
   341 describes labeled edges and undirected edges. The directed edge label
   341 describes labeled edges and undirected edges. The directed edge label
   342 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
   343 of the edge. 
   343 of the edge. 
   344 
   344 
   345 \code
   345 \code
   346 @undiredges
   346 @uedges
   347 undiredge 1
   347 uedge 1
   348 +edge 5
   348 +edge 5
   349 -back 5
   349 -back 5
   350 \endcode
   350 \endcode
   351 
   351 
   352 There are similar classes to the \ref lemon::GraphReader "GraphReader" and
   352 There are similar classes to the \ref lemon::GraphReader "GraphReader" and
   353 \ref lemon::GraphWriter "GraphWriter" which
   353 \ref lemon::GraphWriter "GraphWriter" which
   354 handle the undirected graphs. These classes are
   354 handle the undirected graphs. These classes are
   355 the \ref lemon::UndirGraphReader "UndirGraphReader"
   355 the \ref lemon::UGraphReader "UGraphReader"
   356 and \ref lemon::UndirGraphWriter "UndirGraphWriter".
   356 and \ref lemon::UGraphWriter "UGraphWriter".
   357 
   357 
   358 The \ref lemon::UndirGraphReader::readUndirEdgeMap() "readUndirEdgeMap()"
   358 The \ref lemon::UGraphReader::readUEdgeMap() "readUEdgeMap()"
   359 function reads an undirected map and the
   359 function reads an undirected map and the
   360 \ref lemon::UndirGraphReader::readUndirEdge() "readUndirEdge()"
   360 \ref lemon::UGraphReader::readUEdge() "readUEdge()"
   361 reads an undirected edge from the file, 
   361 reads an undirected edge from the file, 
   362 
   362 
   363 \code
   363 \code
   364 reader.readUndirEdgeMap("capacity", capacityMap);
   364 reader.readUEdgeMap("capacity", capacityMap);
   365 reader.readEdgeMap("flow", flowMap);
   365 reader.readEdgeMap("flow", flowMap);
   366 ...
   366 ...
   367 reader.readUndirEdge("undir_edge", undir_edge);
   367 reader.readUEdge("u_edge", u_edge);
   368 reader.readEdge("edge", edge);
   368 reader.readEdge("edge", edge);
   369 \endcode
   369 \endcode
   370 
   370 
   371 \section advanced Advanced features
   371 \section advanced Advanced features
   372 
   372 
   437 traffic request on the network. This construction can be stored in an
   437 traffic request on the network. This construction can be stored in an
   438 undirected graph and in a directed \c ListEdgeSet class. The example
   438 undirected graph and in a directed \c ListEdgeSet class. The example
   439 shows the input with the \ref lemon::LemonReader "LemonReader" class:
   439 shows the input with the \ref lemon::LemonReader "LemonReader" class:
   440 
   440 
   441 \code
   441 \code
   442 UndirListGraph network;
   442 ListUGraph network;
   443 UndirListGraph::UndirEdgeMap<double> capacity;
   443 ListUGraph::UEdgeMap<double> capacity;
   444 ListEdgeSet<UndirListGraph> traffic(network);
   444 ListEdgeSet<ListUGraph> traffic(network);
   445 ListEdgeSet<UndirListGraph>::EdgeMap<double> request(network);
   445 ListEdgeSet<ListUGraph>::EdgeMap<double> request(network);
   446 
   446 
   447 LemonReader reader(std::cin);
   447 LemonReader reader(std::cin);
   448 NodeSetReader<UndirListGraph> nodesetReader(reader, network);
   448 NodeSetReader<ListUGraph> nodesetReader(reader, network);
   449 UndirEdgeSetReader<UndirListGraph> 
   449 UEdgeSetReader<ListUGraph> 
   450   undirEdgesetReader(reader, network, nodesetReader);
   450   uEdgesetReader(reader, network, nodesetReader);
   451 undirEdgesetReader.readEdgeMap("capacity", capacity);
   451 uEdgesetReader.readEdgeMap("capacity", capacity);
   452 EdgeSetReader<ListEdgeSet<UndirListGraph> > 
   452 EdgeSetReader<ListEdgeSet<ListUGraph> > 
   453   edgesetReader(reader, traffic, nodesetReader, "traffic");
   453   edgesetReader(reader, traffic, nodesetReader, "traffic");
   454 edgesetReader.readEdgeMap("request", request);
   454 edgesetReader.readEdgeMap("request", request);
   455 
   455 
   456 reader.run();
   456 reader.run();
   457 \endcode
   457 \endcode
   458 
   458 
   459 Because both the \ref lemon::GraphReader "GraphReader"
   459 Because both the \ref lemon::GraphReader "GraphReader"
   460 and the \ref lemon::UndirGraphReader "UndirGraphReader" can be converted
   460 and the \ref lemon::UGraphReader "UGraphReader" can be converted
   461 to \ref lemon::LemonReader "LemonReader"
   461 to \ref lemon::LemonReader "LemonReader"
   462 and it can resolve the label's of the items, the previous
   462 and it can resolve the label's of the items, the previous
   463 result can be achived with the \ref lemon::UndirGraphReader "UndirGraphReader"
   463 result can be achived with the \ref lemon::UGraphReader "UGraphReader"
   464 class, too.
   464 class, too.
   465 
   465 
   466 
   466 
   467 \code
   467 \code
   468 UndirListGraph network;
   468 ListUGraph network;
   469 UndirListGraph::UndirEdgeSet<double> capacity;
   469 ListUGraph::UEdgeSet<double> capacity;
   470 ListEdgeSet<UndirListGraph> traffic(network);
   470 ListEdgeSet<ListUGraph> traffic(network);
   471 ListEdgeSet<UndirListGraph>::EdgeMap<double> request(network);
   471 ListEdgeSet<ListUGraph>::EdgeMap<double> request(network);
   472 
   472 
   473 UndirGraphReader<UndirListGraph> reader(std::cin, network);
   473 UGraphReader<ListUGraph> reader(std::cin, network);
   474 reader.readEdgeMap("capacity", capacity);
   474 reader.readEdgeMap("capacity", capacity);
   475 EdgeSetReader<ListEdgeSet<UndirListGraph> > 
   475 EdgeSetReader<ListEdgeSet<ListUGraph> > 
   476   edgesetReader(reader, traffic, reader, "traffic");
   476   edgesetReader(reader, traffic, reader, "traffic");
   477 edgesetReader.readEdgeMap("request", request);
   477 edgesetReader.readEdgeMap("request", request);
   478 
   478 
   479 reader.run();
   479 reader.run();
   480 \endcode
   480 \endcode