Simplify the first example code + fix toc
authorPeter Kovacs <kpeter@inf.elte.hu>
Mon, 03 Nov 2008 23:46:30 +0100
changeset 16ed4c8506e151
parent 15 7cc2418766c3
child 17 0b3b26cd1cea
Simplify the first example code + fix toc
demo/hello_lemon.cc
getting_started.dox
toc.txt
     1.1 --- a/demo/hello_lemon.cc	Sat Nov 01 08:25:30 2008 +0000
     1.2 +++ b/demo/hello_lemon.cc	Mon Nov 03 23:46:30 2008 +0100
     1.3 @@ -17,12 +17,9 @@
     1.4   */
     1.5  
     1.6  ///\file
     1.7 -///\brief Demonstrating the basic concepts and fetures of LEMON
     1.8 +///\brief Simple "Hello World!" program for LEMON.
     1.9  ///
    1.10 -/// This program is intended to be a "Hello World!" program that shows
    1.11 -/// the very basic notions of LEMON: \ref graphs "graphs" and
    1.12 -/// \ref maps "maps".
    1.13 -///
    1.14 +/// Simple "Hello World!" program for LEMON.
    1.15  /// \include hello_lemon.cc
    1.16  
    1.17  #include <iostream>
    1.18 @@ -30,67 +27,17 @@
    1.19  
    1.20  int main()
    1.21  {
    1.22 -  // Convenience type definitions
    1.23 -  typedef lemon::ListDigraph Digraph;
    1.24 -  typedef Digraph::Node Node;
    1.25 -  typedef Digraph::Arc Arc;
    1.26 -  typedef Digraph::NodeIt NodeIt;
    1.27 -  typedef Digraph::ArcIt ArcIt;
    1.28 -  typedef Digraph::ArcMap<int> LengthMap;
    1.29 -  using lemon::INVALID;
    1.30 +  typedef lemon::ListDigraph Graph;
    1.31 +  Graph g;
    1.32  
    1.33 -  // Create a directed graph
    1.34 -  Digraph g;
    1.35 +  Graph::Node u = g.addNode();
    1.36 +  Graph::Node v = g.addNode();
    1.37 +  Graph::Arc  e = g.addArc(u, v);
    1.38  
    1.39 -  // Add nodes to the digraph
    1.40 -  Node v1 = g.addNode();
    1.41 -  Node v2 = g.addNode();
    1.42 -  Node v3 = g.addNode();
    1.43 -  Node v4 = g.addNode();
    1.44 -
    1.45 -  // Add arcs to the digraph
    1.46 -  Arc v1_v2 = g.addArc(v1, v2);
    1.47 -  Arc v1_v3 = g.addArc(v1, v3);
    1.48 -  Arc v2_v3 = g.addArc(v2, v3);
    1.49 -  Arc v2_v4 = g.addArc(v2, v4);
    1.50 -  Arc v3_v4 = g.addArc(v3, v4);
    1.51 -
    1.52 -  // Create an arc map (length)
    1.53 -  LengthMap length(g);
    1.54 -
    1.55 -  // Set the length of each arc
    1.56 -  length[v1_v2]  = 10;
    1.57 -  length[v1_v3]  = 20;
    1.58 -  length[v2_v3] = 5;
    1.59 -  length[v2_v4] = 25;
    1.60 -  length[v3_v4] = 10;
    1.61 -
    1.62 -  // Welcome message
    1.63 -  std::cout << "Hello World!" << std::endl;
    1.64 -  std::cout << "This is LEMON library here. We have a direceted graph.";
    1.65 -  std::cout << std::endl << std::endl;
    1.66 -
    1.67 -  // Iterate through the nodes and print their IDs
    1.68 -  std::cout << "Nodes:";
    1.69 -  for (NodeIt n(g); n != INVALID; ++n)
    1.70 -    std::cout << " " << g.id(n);
    1.71 -  std::cout << std::endl;
    1.72 -
    1.73 -  // Iterate through the arcs and print the IDs of their
    1.74 -  // source and target nodes
    1.75 -  std::cout << "Arcs:";
    1.76 -  for (ArcIt a(g); a != INVALID; ++a)
    1.77 -    std::cout << " (" << g.id(g.source(a)) << ","
    1.78 -              << g.id(g.target(a)) << ")";
    1.79 -  std::cout << std::endl << std::endl;
    1.80 -
    1.81 -  // Iterate through the arcs and print their length
    1.82 -  std::cout << "There is a map on the arcs (length):" << std::endl;
    1.83 -  std::cout << std::endl;
    1.84 -  for (ArcIt a(g); a != INVALID; ++a)
    1.85 -    std::cout << "length(" << g.id(g.source(a)) << ","
    1.86 -              << g.id(g.target(a)) << ")=" << length[a] << std::endl;
    1.87 -  std::cout << std::endl;
    1.88 +  std::cout << "Hello World! This is LEMON library here." << std::endl;
    1.89 +  std::cout << "We have a directed graph with "
    1.90 +            << countNodes(g) << " nodes and "
    1.91 +            << countArcs(g) << " arc." << std::endl;
    1.92  
    1.93    return 0;
    1.94  }
     2.1 --- a/getting_started.dox	Sat Nov 01 08:25:30 2008 +0000
     2.2 +++ b/getting_started.dox	Mon Nov 03 23:46:30 2008 +0100
     2.3 @@ -29,37 +29,16 @@
     2.4  \skip #include
     2.5  \until }
     2.6  
     2.7 -First let us briefly explain how this example program works.
     2.8 -(The used notions will be discussed in detail in the following sections.)
     2.9 +In this small example a directed graph is created with two nodes and
    2.10 +an arc added to it.
    2.11  
    2.12 -After some convenience typedefs we create a directed graph (\e digraph)
    2.13 -and add some nodes and arcs to it.
    2.14 -ListDigraph is one of the digraph classes implemented in LEMON.
    2.15 -It is based on linked lists, therefore iterating through its nodes and
    2.16 -arcs is fast.
    2.17 +Now let us compile this code.
    2.18 +(We suppose that you have it in a file called <tt>hello_lemon.cc</tt>.)
    2.19  
    2.20 -Then we iterate through all nodes of the digraph and print their unique
    2.21 -IDs. We use a constructor of the node iterator to initialize it to the
    2.22 -first node.
    2.23 -The <tt>operator++</tt> is used to step to the next node. After the last
    2.24 -node the iterator becomes invalid (i.e. it is set to \c INVALID).
    2.25 -This is what we exploit in the stop condition.
    2.26 -We iterate through all arcs of the digraph very similarly and print the
    2.27 -IDs of their source (tail) and target (head) nodes using the \c source()
    2.28 -and \c target() member functions.
    2.29 -
    2.30 -After that we create an arc map, which is actually a mapping that assigns
    2.31 -an \c int value (length) to each arc, and we set this value for each arc.
    2.32 -Finally we iterate through all arcs again and print their lengths.
    2.33 -
    2.34 -Now let us compile this simple example program.
    2.35 -
    2.36 -[SEC]hello_lemon_system[SEC] If LEMON is Installed System-Wide
    2.37 -
    2.38 -If LEMON is installed system-wide (into directory \c /usr/local),
    2.39 +If LEMON is installed <b>system-wide</b> (into directory \c /usr/local),
    2.40  then it is very easy to compile this program with the
    2.41  following command (the argument <tt>-lemon</tt> tells the compiler
    2.42 -that we are using the installed LEMON):
    2.43 +that we are using the installed LEMON).
    2.44  
    2.45  \verbatim
    2.46  g++ -lemon hello_lemon.cc -o hello_lemon
    2.47 @@ -72,11 +51,9 @@
    2.48  ./hello_lemon
    2.49  \endverbatim
    2.50  
    2.51 -[SEC]hello_lemon_user[SEC] If LEMON is Installed User-Local
    2.52 -
    2.53 -Compiling the code is a bit more difficult if you installed LEMON
    2.54 -user-local into a directory (e.g. <tt>~/lemon</tt>) or if you just
    2.55 -skipped the step <tt>make install</tt>.
    2.56 +If LEMON is installed <b>user-local</b> into a directory
    2.57 +(e.g. <tt>~/lemon</tt>) or if you just skipped the step
    2.58 +<tt>make install</tt>, then compiling the code is a bit more difficult.
    2.59  You have to issue a command like this.
    2.60  
    2.61  \verbatim
    2.62 @@ -86,34 +63,14 @@
    2.63  If everything has gone well, then our program prints out the followings.
    2.64  
    2.65  \verbatim
    2.66 -Hello World!
    2.67 -This is LEMON library here. We have a direceted graph.
    2.68 -
    2.69 -Nodes: 3 2 1 0
    2.70 -Arcs: (2,3) (1,3) (1,2) (0,2) (0,1)
    2.71 -
    2.72 -There is a map on the arcs (length):
    2.73 -
    2.74 -length(2,3)=10
    2.75 -length(1,3)=25
    2.76 -length(1,2)=5
    2.77 -length(0,2)=20
    2.78 -length(0,1)=10
    2.79 +Hello World! This is LEMON library here.
    2.80 +We have a directed graph with 2 nodes and 1 arc.
    2.81  \endverbatim
    2.82  
    2.83 -You may note that iterating through the nodes and arcs is done in the
    2.84 -reverse order compared to the creating order (the IDs are in decreasing
    2.85 -order).
    2.86 -This is due to implementation aspects, that may differ at other graph
    2.87 -types, moreover it may be changed in the next releases.
    2.88 -Thus you should not exploit this method in any way, you should not
    2.89 -suppose anything about the iteration order.
    2.90 -
    2.91  If you managed to compile and run this example code without any problems,
    2.92 -you can go on reading this tutorial to get to know more features and tools
    2.93 -of LEMON.
    2.94 -Otherwise if you encountered problems that you did not manage to solve,
    2.95 -do not hesitate to
    2.96 +you may go on reading this tutorial to get to know the basic notions,
    2.97 +features and tools of LEMON. However if you encountered problems that
    2.98 +you did not manage to solve, do not hesitate to
    2.99  <a href="mailto:lemon-user@lemon.cs.elte.hu"><b>contact us</b></a>.
   2.100  
   2.101  [TRAILER]
     3.1 --- a/toc.txt	Sat Nov 01 08:25:30 2008 +0000
     3.2 +++ b/toc.txt	Mon Nov 03 23:46:30 2008 +0100
     3.3 @@ -2,16 +2,14 @@
     3.4  ** intro_lemon
     3.5  ** intro_tutorial
     3.6  * hello_lemon
     3.7 -** hello_lemon_system
     3.8 -** hello_lemon_user
     3.9 -**_digraph_build
    3.10 -**_digraph_iterate
    3.11 -**_standard_maps
    3.12 -**_algorithms
    3.13 -***_alg_bfs_dfs
    3.14 -***_alg_dijkstra
    3.15 -***_alg_kruskal
    3.16 -**_undir_graphs
    3.17 +*_digraph_build
    3.18 +*_digraph_iterate
    3.19 +*_standard_maps
    3.20 +*_algorithms
    3.21 +**_alg_bfs_dfs
    3.22 +**_alg_dijkstra
    3.23 +**_alg_kruskal
    3.24 +*_undir_graphs
    3.25  *_tools
    3.26  **_lgf
    3.27  **_glemon