doc/getstart.dox
author klao
Mon, 27 Jun 2005 19:47:09 +0000
changeset 1519 17e367a93cbb
parent 1517 b303c1741c9a
child 1520 c2c76e4598f6
permissions -rw-r--r--
getstart improvements
     1 /**
     2 \page getstart How to start using LEMON
     3 
     4 In this page we detail how to start using LEMON, from downloading it to
     5 your computer, through the steps of installation, to showing a simple
     6 "Hello World" type program that already uses LEMON. We assume that you
     7 have a basic knowledge of your operating system and \c C++ programming
     8 language. The procedure is pretty straightforward, but if you have any
     9 difficulties don't hesitate to
    10 <a href="http://lemon.cs.elte.hu/mailinglists.html">ask</a>.
    11 
    12 \section requirementsLEMON Hardware and software requirements
    13 
    14 In LEMON we use C++ templates heavily, thus compilation takes a
    15 considerable amount of time and memory. So some decent box would be
    16 advantageous. But otherwise there are no special hardware requirements.
    17 
    18 You will need a recent C++ compiler. Our primary target is the GNU C++
    19 Compiler (g++), from version 3.3 upwards. We also checked the Intel C
    20 compiler (icc). Microsoft Visual C++ .NET version was also reported to
    21 work (but not the earlier versions). If you want to develop with LEMON
    22 under Windows you could consider using Cygwin.
    23 
    24 
    25 In this description we will suppose a linux environment and GNU C Compiler.
    26 
    27 \section downloadLEMON How to download LEMON
    28 
    29 You can download LEMON from the LEMON web site:
    30 http://lemon.cs.elte.hu/dowload.html.
    31 There you will find released versions in form of <tt>.tar.gz</tt> files.
    32 If you want a developer version (for example you want to contribute in
    33 developing the library LEMON) then you might want to use our Subversion
    34 repository. This case is not detailed here, so from now on we suppose that
    35 you downloaded a tar.gz file.
    36 
    37 
    38 
    39 \section installLEMON How to install LEMON
    40 
    41 In order to install LEMON you have to do the following
    42 
    43 Download the tarball (named <tt>lemon-x.y.z.tar.gz</tt> where \c x,\c y
    44 and \c z are numbers indicating the version of the library: in our example
    45 we will have <tt>lemon-0.3.1.tar.gz</tt>) and issue the following
    46 commands:
    47 
    48 \verbatim
    49 tar xvzf lemon-0.3.1.tar.gz
    50 cd lemon-0.3.1
    51 ./configure
    52 make
    53 make check   #(This is optional, but recomended. It runs a bunch of tests.)
    54 make install
    55 \endverbatim
    56 
    57 These commands install LEMON under \c /usr/local (you will
    58 need root privileges to be able to install to that
    59 directory). If you want to install it to some other place, then
    60 pass the \c --prefix=DIR flag to \c ./configure. In what follows
    61 we will assume that you were able to install to directory
    62 \c /usr/local, otherwise some extra care is to be taken to use the
    63 library.
    64 
    65 We briefly explain these commands below.
    66 
    67 \verbatim
    68 tar xvzf lemon-0.3.1.tar.gz
    69 \endverbatim
    70 This command untars the <tt>tar.gz</tt> file into a directory named <tt>
    71 lemon-0.3.1</tt>.
    72 
    73 \verbatim
    74 cd lemon-0.3.1
    75 \endverbatim
    76 Enters the directory.
    77 
    78 \verbatim
    79 ./configure
    80 \endverbatim
    81 Does some configuration (creates makefiles etc).
    82 \todo Explain the most important switches here (gui, doc, glpk, cplex).
    83 
    84 \verbatim
    85 make
    86 \endverbatim
    87 This command compiles the non-template part of LEMON into
    88 <b>libemon.a</b> file. It also compiles some benchmark and demo
    89 programs.
    90 
    91 \verbatim
    92 make check
    93 \endverbatim
    94 This is an optional step: it runs the test programs that we
    95 developed for LEMON to check whether the library works properly on
    96 your platform.
    97 
    98 \verbatim
    99 make install
   100 \endverbatim
   101 This will copy the directory structure to its final destination (e.g. to \c
   102 /usr/local) so that your system can access it. This command should
   103 be issued as "root", unless you provided a \c --prefix switch to
   104 the \c cofugure to install the library in non-default location.
   105 
   106 \section helloworld My first program using LEMON
   107 
   108 If you have installed LEMON on your system you can paste the
   109 following code segment into a file (named e.g. \c hello_lemon.cc)
   110 to have a first working program that uses library LEMON.
   111 
   112 \code
   113 #include <iostream>
   114 #include <lemon/list_graph.h>
   115 
   116 int main()
   117 {
   118   typedef lemon::ListGraph Graph;
   119   typedef Graph::EdgeIt EdgeIt;
   120   typedef Graph::NodeIt NodeIt;
   121   using lemon::INVALID;
   122 
   123   Graph g;
   124   
   125   for (int i = 0; i < 3; i++)
   126     g.addNode();
   127   
   128   for (NodeIt i(g); i!=INVALID; ++i)
   129     for (NodeIt j(g); j!=INVALID; ++j)
   130       if (i != j) g.addEdge(i, j);
   131 
   132   std::cout << "Nodes:";
   133   for (NodeIt i(g); i!=INVALID; ++i)
   134     std::cout << " " << g.id(i);
   135   std::cout << std::endl;
   136 
   137   std::cout << "Edges:";
   138   for (EdgeIt i(g); i!=INVALID; ++i)
   139     std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
   140   std::cout << std::endl;
   141 }
   142 \endcode
   143 
   144 First let us briefly explain how this program works.
   145 
   146 ListGraph is one of LEMON's graph classes. It is based on linked lists,
   147 therefore iterating throuh its edges and nodes is fast.
   148 
   149 After some convenient typedefs we create a graph and add three nodes to it.
   150 Then we add edges to it to form a complete graph.
   151 
   152 Then we iterate through all nodes of the graph. We use a constructor of the
   153 node iterator to initialize it to the first node. The operator++ is used to
   154 step to the next node. Using operator++ on the iterator pointing to the last
   155 node invalidates the iterator i.e. sets its value to
   156 \ref lemon::INVALID "INVALID". This is what we exploit in the stop condition.
   157 
   158 We can also iterate through all edges of the graph very similarly. The 
   159 \c target and
   160 \c source member functions can be used to access the endpoints of an edge.
   161 
   162 If you have saved the preceding code into a file named, say, \c
   163 hello_lemon.cc and your installation of LEMON into directory \c
   164 /usr/local was successful then it is very easy to compile this
   165 program with the following command (the argument <tt>-lemon</tt>
   166 tells the compiler that we are using the installed library LEMON):
   167 
   168 \verbatim
   169 g++ hello_lemon.cc -o hello_lemon -lemon
   170 \endverbatim
   171 
   172 As a result you will get the exacutable \c hello_lemon in
   173 this directory that you can run by the command 
   174 \verbatim
   175 ./hello_lemon
   176 \endverbatim
   177 
   178 
   179 If everything has gone well then the previous code fragment prints
   180 out the following:
   181 
   182 \verbatim
   183 Nodes: 2 1 0
   184 
   185 Edges: (0,2) (1,2) (0,1) (2,1) (1,0) (2,0)
   186 \endverbatim
   187 
   188 Congratulations!
   189 
   190 If you want to see more features, go to the
   191 \ref quicktour "Quick Tour to LEMON",
   192 if you want to see see some demo programs then go to our 
   193 \ref demoprograms "Demo Programs" page! 
   194 
   195 
   196 */