# HG changeset patch # User Peter Kovacs # Date 1225752390 -3600 # Node ID ed4c8506e151bb7c11faef6ed9b9509bccfdbce4 # Parent 7cc2418766c3a0ce25766a2ebf81733a0efa3bd6 Simplify the first example code + fix toc diff -r 7cc2418766c3 -r ed4c8506e151 demo/hello_lemon.cc --- a/demo/hello_lemon.cc Sat Nov 01 08:25:30 2008 +0000 +++ b/demo/hello_lemon.cc Mon Nov 03 23:46:30 2008 +0100 @@ -17,12 +17,9 @@ */ ///\file -///\brief Demonstrating the basic concepts and fetures of LEMON +///\brief Simple "Hello World!" program for LEMON. /// -/// This program is intended to be a "Hello World!" program that shows -/// the very basic notions of LEMON: \ref graphs "graphs" and -/// \ref maps "maps". -/// +/// Simple "Hello World!" program for LEMON. /// \include hello_lemon.cc #include @@ -30,67 +27,17 @@ int main() { - // Convenience type definitions - typedef lemon::ListDigraph Digraph; - typedef Digraph::Node Node; - typedef Digraph::Arc Arc; - typedef Digraph::NodeIt NodeIt; - typedef Digraph::ArcIt ArcIt; - typedef Digraph::ArcMap LengthMap; - using lemon::INVALID; + typedef lemon::ListDigraph Graph; + Graph g; - // Create a directed graph - Digraph g; + Graph::Node u = g.addNode(); + Graph::Node v = g.addNode(); + Graph::Arc e = g.addArc(u, v); - // Add nodes to the digraph - Node v1 = g.addNode(); - Node v2 = g.addNode(); - Node v3 = g.addNode(); - Node v4 = g.addNode(); - - // Add arcs to the digraph - Arc v1_v2 = g.addArc(v1, v2); - Arc v1_v3 = g.addArc(v1, v3); - Arc v2_v3 = g.addArc(v2, v3); - Arc v2_v4 = g.addArc(v2, v4); - Arc v3_v4 = g.addArc(v3, v4); - - // Create an arc map (length) - LengthMap length(g); - - // Set the length of each arc - length[v1_v2] = 10; - length[v1_v3] = 20; - length[v2_v3] = 5; - length[v2_v4] = 25; - length[v3_v4] = 10; - - // Welcome message - std::cout << "Hello World!" << std::endl; - std::cout << "This is LEMON library here. We have a direceted graph."; - std::cout << std::endl << std::endl; - - // Iterate through the nodes and print their IDs - std::cout << "Nodes:"; - for (NodeIt n(g); n != INVALID; ++n) - std::cout << " " << g.id(n); - std::cout << std::endl; - - // Iterate through the arcs and print the IDs of their - // source and target nodes - std::cout << "Arcs:"; - for (ArcIt a(g); a != INVALID; ++a) - std::cout << " (" << g.id(g.source(a)) << "," - << g.id(g.target(a)) << ")"; - std::cout << std::endl << std::endl; - - // Iterate through the arcs and print their length - std::cout << "There is a map on the arcs (length):" << std::endl; - std::cout << std::endl; - for (ArcIt a(g); a != INVALID; ++a) - std::cout << "length(" << g.id(g.source(a)) << "," - << g.id(g.target(a)) << ")=" << length[a] << std::endl; - std::cout << std::endl; + std::cout << "Hello World! This is LEMON library here." << std::endl; + std::cout << "We have a directed graph with " + << countNodes(g) << " nodes and " + << countArcs(g) << " arc." << std::endl; return 0; } diff -r 7cc2418766c3 -r ed4c8506e151 getting_started.dox --- a/getting_started.dox Sat Nov 01 08:25:30 2008 +0000 +++ b/getting_started.dox Mon Nov 03 23:46:30 2008 +0100 @@ -29,37 +29,16 @@ \skip #include \until } -First let us briefly explain how this example program works. -(The used notions will be discussed in detail in the following sections.) +In this small example a directed graph is created with two nodes and +an arc added to it. -After some convenience typedefs we create a directed graph (\e digraph) -and add some nodes and arcs to it. -ListDigraph is one of the digraph classes implemented in LEMON. -It is based on linked lists, therefore iterating through its nodes and -arcs is fast. +Now let us compile this code. +(We suppose that you have it in a file called hello_lemon.cc.) -Then we iterate through all nodes of the digraph and print their unique -IDs. We use a constructor of the node iterator to initialize it to the -first node. -The operator++ is used to step to the next node. After the last -node the iterator becomes invalid (i.e. it is set to \c INVALID). -This is what we exploit in the stop condition. -We iterate through all arcs of the digraph very similarly and print the -IDs of their source (tail) and target (head) nodes using the \c source() -and \c target() member functions. - -After that we create an arc map, which is actually a mapping that assigns -an \c int value (length) to each arc, and we set this value for each arc. -Finally we iterate through all arcs again and print their lengths. - -Now let us compile this simple example program. - -[SEC]hello_lemon_system[SEC] If LEMON is Installed System-Wide - -If LEMON is installed system-wide (into directory \c /usr/local), +If LEMON is installed system-wide (into directory \c /usr/local), then it is very easy to compile this program with the following command (the argument -lemon tells the compiler -that we are using the installed LEMON): +that we are using the installed LEMON). \verbatim g++ -lemon hello_lemon.cc -o hello_lemon @@ -72,11 +51,9 @@ ./hello_lemon \endverbatim -[SEC]hello_lemon_user[SEC] If LEMON is Installed User-Local - -Compiling the code is a bit more difficult if you installed LEMON -user-local into a directory (e.g. ~/lemon) or if you just -skipped the step make install. +If LEMON is installed user-local into a directory +(e.g. ~/lemon) or if you just skipped the step +make install, then compiling the code is a bit more difficult. You have to issue a command like this. \verbatim @@ -86,34 +63,14 @@ If everything has gone well, then our program prints out the followings. \verbatim -Hello World! -This is LEMON library here. We have a direceted graph. - -Nodes: 3 2 1 0 -Arcs: (2,3) (1,3) (1,2) (0,2) (0,1) - -There is a map on the arcs (length): - -length(2,3)=10 -length(1,3)=25 -length(1,2)=5 -length(0,2)=20 -length(0,1)=10 +Hello World! This is LEMON library here. +We have a directed graph with 2 nodes and 1 arc. \endverbatim -You may note that iterating through the nodes and arcs is done in the -reverse order compared to the creating order (the IDs are in decreasing -order). -This is due to implementation aspects, that may differ at other graph -types, moreover it may be changed in the next releases. -Thus you should not exploit this method in any way, you should not -suppose anything about the iteration order. - If you managed to compile and run this example code without any problems, -you can go on reading this tutorial to get to know more features and tools -of LEMON. -Otherwise if you encountered problems that you did not manage to solve, -do not hesitate to +you may go on reading this tutorial to get to know the basic notions, +features and tools of LEMON. However if you encountered problems that +you did not manage to solve, do not hesitate to contact us. [TRAILER] diff -r 7cc2418766c3 -r ed4c8506e151 toc.txt --- a/toc.txt Sat Nov 01 08:25:30 2008 +0000 +++ b/toc.txt Mon Nov 03 23:46:30 2008 +0100 @@ -2,16 +2,14 @@ ** intro_lemon ** intro_tutorial * hello_lemon -** hello_lemon_system -** hello_lemon_user -**_digraph_build -**_digraph_iterate -**_standard_maps -**_algorithms -***_alg_bfs_dfs -***_alg_dijkstra -***_alg_kruskal -**_undir_graphs +*_digraph_build +*_digraph_iterate +*_standard_maps +*_algorithms +**_alg_bfs_dfs +**_alg_dijkstra +**_alg_kruskal +*_undir_graphs *_tools **_lgf **_glemon