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