getting_started.dox
author Peter Kovacs <kpeter@inf.elte.hu>
Thu, 23 Oct 2008 14:07:30 +0200
changeset 6 da96f28684f7
parent 3 0cf8882c7e7c
child 7 934258c64b6b
permissions -rw-r--r--
Extend and improve the first two chapters
kpeter@3
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
kpeter@3
     2
 *
kpeter@3
     3
 * This file is a part of LEMON, a generic C++ optimization library.
kpeter@3
     4
 *
kpeter@3
     5
 * Copyright (C) 2003-2008
kpeter@3
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
kpeter@3
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
kpeter@3
     8
 *
kpeter@3
     9
 * Permission to use, modify and distribute this software is granted
kpeter@3
    10
 * provided that this copyright notice appears in all copies. For
kpeter@3
    11
 * precise terms see the accompanying LICENSE file.
kpeter@3
    12
 *
kpeter@3
    13
 * This software is provided "AS IS" with no warranty of any kind,
kpeter@3
    14
 * express or implied, and with no claim as to its suitability for any
kpeter@3
    15
 * purpose.
kpeter@3
    16
 *
kpeter@3
    17
 */
kpeter@3
    18
kpeter@3
    19
/**
kpeter@6
    20
\page getting_started Getting Started
kpeter@3
    21
kpeter@3
    22
In this page we detail how to start using LEMON, from downloading it to
kpeter@3
    23
your computer, through the steps of installation, to showing a simple
kpeter@3
    24
"Hello World" type program that already uses LEMON. We assume that you
kpeter@3
    25
have a basic knowledge of your operating system and C++ programming
kpeter@3
    26
language. The procedure is pretty straightforward, but if you have any
kpeter@6
    27
difficulties do not hesitate to
kpeter@3
    28
<a href="mailto:lemon-user@lemon.cs.elte.hu"><b>ask</b></a>.
kpeter@3
    29
kpeter@3
    30
\section requirements_lemon Hardware and Software Requirements
kpeter@3
    31
kpeter@3
    32
In LEMON we use C++ templates heavily, thus compilation takes a
kpeter@3
    33
considerable amount of time and memory. So some decent box would be
kpeter@6
    34
advantageousm, but otherwise there are no special hardware requirements.
kpeter@3
    35
kpeter@3
    36
You will need a recent C++ compiler. Our primary target is the GNU C++
kpeter@3
    37
Compiler (g++), from version 3.3 upwards. We also checked the Intel C++
kpeter@6
    38
Compiler (icc) and Microsoft Visual C++ (on Windows).
kpeter@6
    39
If you want to develop with LEMON under Windows, you can use a Windows
kpeter@6
    40
installer or you can consider using Cygwin.
kpeter@3
    41
kpeter@3
    42
In this description we will suppose a Linux environment and GNU C++ Compiler.
kpeter@6
    43
If you would like to develop under Windows and use a Windows installer,
kpeter@6
    44
you could skip the following sections and continue reading \ref hello_lemon.
kpeter@6
    45
However keep in mind that you have to make appropriate steps instead of
kpeter@6
    46
the instructions detailed here to be able to compile the example code
kpeter@6
    47
with your compiler.
kpeter@3
    48
kpeter@3
    49
\subsection requirements_lp LP Solver Requirements
kpeter@3
    50
kpeter@3
    51
The LEMON LP solver interface can use the GLPK (GNU Linear Programming
kpeter@6
    52
Kit), CPLEX and SoPlex solver. If you want to use it, you will need at
kpeter@6
    53
least one of these.
kpeter@6
    54
See the <b><tt>INSTALL</tt></b> file how to enable these at compile time.
kpeter@3
    55
kpeter@3
    56
\section download_lemon How to Download LEMON
kpeter@3
    57
kpeter@6
    58
You can download LEMON from our web site:
kpeter@6
    59
<a href="http://lemon.cs.elte.hu/">http://lemon.cs.elte.hu/</a>.
kpeter@6
    60
There you will find released versions in form of <tt>.tar.gz</tt> files
kpeter@6
    61
(and Windows installers).
kpeter@3
    62
If you want a developer version (for example you want to contribute in
kpeter@6
    63
developing LEMON) then you might want to use our Mercurial repository.
kpeter@6
    64
This case is detailed \ref hg_checkout "later", so from now on we
kpeter@6
    65
suppose that you downloaded a <tt>.tar.gz</tt> file.
kpeter@3
    66
kpeter@3
    67
\section install_lemon How to Install LEMON
kpeter@3
    68
kpeter@3
    69
In order to install LEMON you have to do the following steps.
kpeter@3
    70
kpeter@3
    71
Download the tarball (named <tt>lemon-x.y.z.tar.gz</tt> where \c x, \c y
kpeter@3
    72
and \c z are numbers indicating the version of the library, in our example
kpeter@3
    73
we will have <tt>lemon-1.0.tar.gz</tt>) and issue the following commands:
kpeter@3
    74
kpeter@3
    75
\verbatim
kpeter@3
    76
tar xvzf lemon-1.0.tar.gz
kpeter@3
    77
cd lemon-1.0
kpeter@3
    78
./configure
kpeter@3
    79
make
kpeter@3
    80
make check    # This is optional, but recommended. It runs a bunch of tests.
kpeter@3
    81
make install
kpeter@3
    82
\endverbatim
kpeter@3
    83
kpeter@3
    84
These commands install LEMON under \c /usr/local (you will
kpeter@3
    85
need root privileges to be able to install to that
kpeter@3
    86
directory). If you want to install it to some other place, then
kpeter@3
    87
pass the \c --prefix=DIRECTORY flag to <tt>./configure</tt>, for example:
kpeter@3
    88
kpeter@3
    89
\verbatim
kpeter@3
    90
./configure --prefix=/home/username/lemon
kpeter@3
    91
\endverbatim
kpeter@3
    92
kpeter@3
    93
In what follows we will assume that you were able to install to directory
kpeter@3
    94
\c /usr/local, otherwise some extra care is to be taken to use the library.
kpeter@3
    95
kpeter@3
    96
We briefly explain these commands below.
kpeter@3
    97
kpeter@3
    98
\verbatim
kpeter@3
    99
tar xvzf lemon-1.0.tar.gz
kpeter@3
   100
\endverbatim
kpeter@3
   101
This command untars the <tt>tar.gz</tt> file into a directory named
kpeter@3
   102
<tt>lemon-1.0</tt>.
kpeter@3
   103
kpeter@3
   104
\verbatim
kpeter@3
   105
cd lemon-1.0
kpeter@3
   106
\endverbatim
kpeter@3
   107
This command enters the directory.
kpeter@3
   108
kpeter@3
   109
\verbatim
kpeter@3
   110
./configure
kpeter@3
   111
\endverbatim
kpeter@3
   112
This command runs the configure shell script, which does some checks and
kpeter@3
   113
creates the makefiles.
kpeter@3
   114
kpeter@3
   115
\verbatim
kpeter@3
   116
make
kpeter@3
   117
\endverbatim
kpeter@3
   118
This command compiles the non-template part of LEMON into <tt>libemon.a</tt>
kpeter@3
   119
file. It also compiles the programs in the tools and demo subdirectories
kpeter@3
   120
when enabled.
kpeter@3
   121
kpeter@3
   122
\verbatim
kpeter@3
   123
make check
kpeter@3
   124
\endverbatim
kpeter@3
   125
This step is optional, but recommended. It runs the test programs that
kpeter@6
   126
have been developed for LEMON to check whether the library works properly on
kpeter@3
   127
your platform.
kpeter@3
   128
kpeter@3
   129
\verbatim
kpeter@3
   130
make install
kpeter@3
   131
\endverbatim
kpeter@3
   132
This command will copy the directory structure to its final destination
kpeter@3
   133
(e.g. to \c /usr/local) so that your system can access it.
kpeter@3
   134
This command should be issued as "root", unless you provided a
kpeter@3
   135
\c --prefix switch to the \c configure to install the library in
kpeter@3
   136
non-default location.
kpeter@3
   137
kpeter@3
   138
Several other configure flags can be passed to <tt>./configure</tt>.
kpeter@6
   139
For more information see the <b><tt>INSTALL</tt></b> file.
kpeter@3
   140
kpeter@3
   141
\section hg_checkout How to Checkout LEMON from our Mercurial Repository
kpeter@3
   142
kpeter@6
   143
You can obtain the latest (developer) version of LEMON from our Mercurial
kpeter@6
   144
repository. To do this issue the following command.
kpeter@3
   145
\verbatim
kpeter@6
   146
hg clone http://lemon.cs.elte.hu/hg/lemon-main lemon-src
kpeter@3
   147
\endverbatim
kpeter@3
   148
kpeter@3
   149
\section hg_compile How to Compile the Source from the Repository
kpeter@3
   150
kpeter@3
   151
You can compile the code from the repository similarly to the packaged
kpeter@6
   152
version, but you will need to run <b><tt>autoreconf -vif</tt></b>
kpeter@6
   153
(or <b><tt>./bootstrap</tt></b> in some older environment) before
kpeter@3
   154
<tt>./configure</tt>. See <tt>./configure --help</tt> for options.
kpeter@3
   155
For bootstrapping you will need the following tools:
kpeter@3
   156
kpeter@3
   157
 - <a href="http://www.gnu.org/software/automake/">automake</a> (1.7 or newer)
kpeter@3
   158
 - <a href="http://www.gnu.org/software/autoconf/">autoconf</a> (2.59 or newer)
kpeter@3
   159
 - <a href="http://www.gnu.org/software/libtool/">libtool</a>
kpeter@3
   160
 - <a href="http://pkgconfig.freedesktop.org/">pkgconfig</a>
kpeter@3
   161
kpeter@3
   162
To generate the documentation, run <tt>make html</tt>.
kpeter@3
   163
You will need <a href="http://www.doxygen.org/">Doxygen</a> for this.
kpeter@3
   164
kpeter@6
   165
\section hello_lemon Compile Your First Code
kpeter@6
   166
kpeter@6
   167
If you have installed LEMON on your system you can paste the following
kpeter@6
   168
code segment into a file called <tt>hello_lemon.cc</tt> to have a first
kpeter@6
   169
working program that uses LEMON.
kpeter@6
   170
kpeter@6
   171
\dontinclude hello_lemon.cc
kpeter@6
   172
\skip #include
kpeter@6
   173
\until }
kpeter@6
   174
kpeter@6
   175
First let us briefly explain how this example program works.
kpeter@6
   176
(The used notions will be discussed in detail in the following chapter.)
kpeter@6
   177
kpeter@6
   178
After some convenience typedefs we create a directed graph (\e digraph)
kpeter@6
   179
and add some nodes and arcs to it.
kpeter@6
   180
ListDigraph is one of the digraph classes implemented in LEMON.
kpeter@6
   181
It is based on linked lists, therefore iterating through its nodes and
kpeter@6
   182
arcs is fast.
kpeter@6
   183
kpeter@6
   184
Then we iterate through all nodes of the digraph and print their unique
kpeter@6
   185
IDs. We use a constructor of the node iterator to initialize it to the
kpeter@6
   186
first node.
kpeter@6
   187
The <tt>operator++</tt> is used to step to the next node. After the last
kpeter@6
   188
node the iterator becomes invalid (i.e. it is set to \c INVALID).
kpeter@6
   189
This is what we exploit in the stop condition.
kpeter@6
   190
We iterate through all arcs of the digraph very similarly and print the
kpeter@6
   191
IDs of their source (tail) and target (head) nodes using the \c source()
kpeter@6
   192
and \c target() member functions.
kpeter@6
   193
kpeter@6
   194
After that we create an arc map, which is actually a mapping that assigns
kpeter@6
   195
an \c int value (length) to each arc, and we set this value for each arc.
kpeter@6
   196
Finally we iterate through all arcs again and print their lengths.
kpeter@6
   197
kpeter@6
   198
Now let's compile this simple example program.
kpeter@6
   199
kpeter@6
   200
\subsection hello_lemon_system If LEMON is Installed System-Wide
kpeter@6
   201
kpeter@6
   202
If your installation of LEMON into directory \c /usr/local was
kpeter@6
   203
successful, then it is very easy to compile this program with the
kpeter@6
   204
following command (the argument <tt>-lemon</tt> tells the compiler
kpeter@6
   205
that we are using the installed LEMON):
kpeter@6
   206
kpeter@6
   207
\verbatim
kpeter@6
   208
g++ hello_lemon.cc -o hello_lemon -lemon
kpeter@6
   209
\endverbatim
kpeter@6
   210
kpeter@6
   211
As a result you will get the exacutable \c hello_lemon in the current
kpeter@6
   212
directory, which you can run by the following command.
kpeter@6
   213
kpeter@6
   214
\verbatim
kpeter@6
   215
./hello_lemon
kpeter@6
   216
\endverbatim
kpeter@6
   217
kpeter@6
   218
\subsection hello_lemon_user If LEMON is Installed User-Local
kpeter@6
   219
kpeter@6
   220
Compiling the code is a bit more difficult if you installed LEMON
kpeter@6
   221
user-local into a directory (e.g. <tt>~/lemon</tt>) or if you just
kpeter@6
   222
skipped the step <tt>make install</tt>.
kpeter@6
   223
You have to issue a command like this.
kpeter@6
   224
kpeter@6
   225
\verbatim
kpeter@6
   226
g++ -I ~/lemon hello_lemon.cc -o hello_lemon -lemon -L ~/lemon/lemon/.libs
kpeter@6
   227
\endverbatim
kpeter@6
   228
kpeter@6
   229
\subsubsection hello_lemon_pkg_config Use pkg-config
kpeter@6
   230
kpeter@6
   231
\todo Write this sub-subsection (\ref hello_lemon_pkg_config).
kpeter@6
   232
kpeter@6
   233
If everything has gone well, then our program prints out the followings.
kpeter@6
   234
kpeter@6
   235
\verbatim
kpeter@6
   236
Hello World!
kpeter@6
   237
This is LEMON library here. We have a direceted graph.
kpeter@6
   238
kpeter@6
   239
Nodes: 3 2 1 0
kpeter@6
   240
Arcs: (2,3) (1,3) (1,2) (0,2) (0,1)
kpeter@6
   241
kpeter@6
   242
There is a map on the arcs (length):
kpeter@6
   243
kpeter@6
   244
length(2,3)=10
kpeter@6
   245
length(1,3)=25
kpeter@6
   246
length(1,2)=5
kpeter@6
   247
length(0,2)=20
kpeter@6
   248
length(0,1)=10
kpeter@6
   249
\endverbatim
kpeter@6
   250
kpeter@6
   251
You may note that iterating through the nodes and arcs is done in the
kpeter@6
   252
reverse order compared to the creating order (the IDs are in decreasing
kpeter@6
   253
order).
kpeter@6
   254
This is due to implementation aspects, that may differ at other graph
kpeter@6
   255
types, moreover it may be changed in the next releases.
kpeter@6
   256
Thus you should not exploit this method in any way, you should not
kpeter@6
   257
suppose anything about the iteration order.
kpeter@6
   258
kpeter@6
   259
If you managed to compile and run this example code without any problems,
kpeter@6
   260
you can go on reading this tutorial to get to know more features and tools
kpeter@6
   261
of LEMON.
kpeter@6
   262
Otherwise if you encountered problems that you did not manage to solve,
kpeter@6
   263
do not hesitate to
kpeter@6
   264
<a href="mailto:lemon-user@lemon.cs.elte.hu"><b>contact us</b></a>.
kpeter@6
   265
kpeter@3
   266
*/