demo/lgf_demo.cc
changeset 198 e80e08222fdf
parent 192 7bf5f97d574f
parent 191 abc5b9d0c67e
child 209 765619b7cbb2
equal deleted inserted replaced
4:599c51dbb79e 5:fd6dfbad5773
    18 
    18 
    19 ///\ingroup demos
    19 ///\ingroup demos
    20 ///\file
    20 ///\file
    21 ///\brief Demonstrating graph input and output
    21 ///\brief Demonstrating graph input and output
    22 ///
    22 ///
    23 /// This program gives an example of how to load a directed graph from
    23 /// This program gives an example of how to read and write a digraph
    24 /// an \ref lgf-format "LGF" file with the \ref lemon::DigraphReader
    24 /// and additional maps from/to a stream or a file using the 
    25 /// "DigraphReader" class.
    25 /// \ref lgf-format "LGF" format.
    26 ///
    26 ///
    27 /// The \c "digraph.lgf" file:
    27 /// The \c "digraph.lgf" file:
    28 /// \include digraph.lgf
    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 /// \include lgf_demo.cc
    32 /// \include lgf_demo.cc
    32 
    33 
    33 #include <iostream>
    34 #include <iostream>
    34 #include <lemon/smart_graph.h>
    35 #include <lemon/smart_graph.h>
    35 #include <lemon/lgf_reader.h>
    36 #include <lemon/lgf_reader.h>
    39 
    40 
    40 int main() {
    41 int main() {
    41   SmartDigraph g;
    42   SmartDigraph g;
    42   SmartDigraph::ArcMap<int> cap(g);
    43   SmartDigraph::ArcMap<int> cap(g);
    43   SmartDigraph::Node s, t;
    44   SmartDigraph::Node s, t;
    44 
    45   
    45   digraphReader("digraph.lgf", g). // read the directed graph into g
    46   try {
    46     arcMap("capacity", cap).       // read the 'capacity' arc map into cap
    47     digraphReader("digraph.lgf", g). // read the directed graph into g
    47     node("source", s).             // read 'source' node to s
    48       arcMap("capacity", cap).       // read the 'capacity' arc map into cap
    48     node("target", t).             // read 'target' node to t
    49       node("source", s).             // read 'source' node to s
    49     run();
    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   std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
    57   std::cout << "A digraph is read from 'digraph.lgf'." << std::endl;
    52   std::cout << "Number of nodes: " << countNodes(g) << std::endl;
    58   std::cout << "Number of nodes: " << countNodes(g) << std::endl;
    53   std::cout << "Number of arcs: " << countArcs(g) << std::endl;
    59   std::cout << "Number of arcs: " << countArcs(g) << std::endl;
    54 
    60