gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 1 0
merge default
1 file changed with 16 insertions and 10 deletions:
↑ Collapse diff ↑
Ignore white space 24 line context
... ...
@@ -11,51 +11,57 @@
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
///\ingroup demos
20 20
///\file
21 21
///\brief Demonstrating graph input and output
22 22
///
23
/// This program gives an example of how to load a directed graph from
24
/// an \ref lgf-format "LGF" file with the \ref lemon::DigraphReader
25
/// "DigraphReader" class.
23
/// This program gives an example of how to read and write a digraph
24
/// and additional maps from/to a stream or a file using the 
25
/// \ref lgf-format "LGF" format.
26 26
///
27 27
/// The \c "digraph.lgf" file:
28 28
/// \include digraph.lgf
29 29
///
30
/// And the program which reads it:
30
/// And the program which reads it and prints the digraph to the
31
/// standard output:
31 32
/// \include lgf_demo.cc
32 33

	
33 34
#include <iostream>
34 35
#include <lemon/smart_graph.h>
35 36
#include <lemon/lgf_reader.h>
36 37
#include <lemon/lgf_writer.h>
37 38

	
38 39
using namespace lemon;
39 40

	
40 41
int main() {
41 42
  SmartDigraph g;
42 43
  SmartDigraph::ArcMap<int> cap(g);
43 44
  SmartDigraph::Node s, t;
44

	
45
  digraphReader("digraph.lgf", g). // read the directed graph into g
46
    arcMap("capacity", cap).       // read the 'capacity' arc map into cap
47
    node("source", s).             // read 'source' node to s
48
    node("target", t).             // read 'target' node to t
49
    run();
45
  
46
  try {
47
    digraphReader("digraph.lgf", g). // read the directed graph into g
48
      arcMap("capacity", cap).       // read the 'capacity' arc map into cap
49
      node("source", s).             // read 'source' node to s
50
      node("target", t).             // read 'target' node to t
51
      run();
52
  } catch (DataFormatError& error) { // check if there was any error
53
    std::cerr << "Error: " << error.what() << std::endl;
54
    return -1;
55
  }
50 56

	
51 57
  std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
52 58
  std::cout << "Number of nodes: " << countNodes(g) << std::endl;
53 59
  std::cout << "Number of arcs: " << countArcs(g) << std::endl;
54 60

	
55 61
  std::cout << "We can write it to the standard output:" << std::endl;
56 62

	
57 63
  digraphWriter(std::cout, g).     // write g to the standard output
58 64
    arcMap("capacity", cap).       // write cap into 'capacity'
59 65
    node("source", s).             // write s to 'source'
60 66
    node("target", t).             // write t to 'target'
61 67
    run();
0 comments (0 inline)