getting_started.dox
author Alpar Juttner <alpar@cs.elte.hu>
Fri, 24 Oct 2008 13:26:15 +0100
changeset 7 934258c64b6b
parent 6 da96f28684f7
child 9 a48bf0d3a790
permissions -rw-r--r--
Rework installation part and move it to the appendix
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@6
    22
\section hello_lemon Compile Your First Code
kpeter@6
    23
kpeter@6
    24
If you have installed LEMON on your system you can paste the following
kpeter@6
    25
code segment into a file called <tt>hello_lemon.cc</tt> to have a first
kpeter@6
    26
working program that uses LEMON.
kpeter@6
    27
kpeter@6
    28
\dontinclude hello_lemon.cc
kpeter@6
    29
\skip #include
kpeter@6
    30
\until }
kpeter@6
    31
kpeter@6
    32
First let us briefly explain how this example program works.
kpeter@6
    33
(The used notions will be discussed in detail in the following chapter.)
kpeter@6
    34
kpeter@6
    35
After some convenience typedefs we create a directed graph (\e digraph)
kpeter@6
    36
and add some nodes and arcs to it.
kpeter@6
    37
ListDigraph is one of the digraph classes implemented in LEMON.
kpeter@6
    38
It is based on linked lists, therefore iterating through its nodes and
kpeter@6
    39
arcs is fast.
kpeter@6
    40
kpeter@6
    41
Then we iterate through all nodes of the digraph and print their unique
kpeter@6
    42
IDs. We use a constructor of the node iterator to initialize it to the
kpeter@6
    43
first node.
kpeter@6
    44
The <tt>operator++</tt> is used to step to the next node. After the last
kpeter@6
    45
node the iterator becomes invalid (i.e. it is set to \c INVALID).
kpeter@6
    46
This is what we exploit in the stop condition.
kpeter@6
    47
We iterate through all arcs of the digraph very similarly and print the
kpeter@6
    48
IDs of their source (tail) and target (head) nodes using the \c source()
kpeter@6
    49
and \c target() member functions.
kpeter@6
    50
kpeter@6
    51
After that we create an arc map, which is actually a mapping that assigns
kpeter@6
    52
an \c int value (length) to each arc, and we set this value for each arc.
kpeter@6
    53
Finally we iterate through all arcs again and print their lengths.
kpeter@6
    54
kpeter@6
    55
Now let's compile this simple example program.
kpeter@6
    56
kpeter@6
    57
\subsection hello_lemon_system If LEMON is Installed System-Wide
kpeter@6
    58
kpeter@6
    59
If your installation of LEMON into directory \c /usr/local was
kpeter@6
    60
successful, then it is very easy to compile this program with the
kpeter@6
    61
following command (the argument <tt>-lemon</tt> tells the compiler
kpeter@6
    62
that we are using the installed LEMON):
kpeter@6
    63
kpeter@6
    64
\verbatim
kpeter@6
    65
g++ hello_lemon.cc -o hello_lemon -lemon
kpeter@6
    66
\endverbatim
kpeter@6
    67
kpeter@6
    68
As a result you will get the exacutable \c hello_lemon in the current
kpeter@6
    69
directory, which you can run by the following command.
kpeter@6
    70
kpeter@6
    71
\verbatim
kpeter@6
    72
./hello_lemon
kpeter@6
    73
\endverbatim
kpeter@6
    74
kpeter@6
    75
\subsection hello_lemon_user If LEMON is Installed User-Local
kpeter@6
    76
kpeter@6
    77
Compiling the code is a bit more difficult if you installed LEMON
kpeter@6
    78
user-local into a directory (e.g. <tt>~/lemon</tt>) or if you just
kpeter@6
    79
skipped the step <tt>make install</tt>.
kpeter@6
    80
You have to issue a command like this.
kpeter@6
    81
kpeter@6
    82
\verbatim
kpeter@6
    83
g++ -I ~/lemon hello_lemon.cc -o hello_lemon -lemon -L ~/lemon/lemon/.libs
kpeter@6
    84
\endverbatim
kpeter@6
    85
kpeter@6
    86
\subsubsection hello_lemon_pkg_config Use pkg-config
kpeter@6
    87
kpeter@6
    88
\todo Write this sub-subsection (\ref hello_lemon_pkg_config).
kpeter@6
    89
kpeter@6
    90
If everything has gone well, then our program prints out the followings.
kpeter@6
    91
kpeter@6
    92
\verbatim
kpeter@6
    93
Hello World!
kpeter@6
    94
This is LEMON library here. We have a direceted graph.
kpeter@6
    95
kpeter@6
    96
Nodes: 3 2 1 0
kpeter@6
    97
Arcs: (2,3) (1,3) (1,2) (0,2) (0,1)
kpeter@6
    98
kpeter@6
    99
There is a map on the arcs (length):
kpeter@6
   100
kpeter@6
   101
length(2,3)=10
kpeter@6
   102
length(1,3)=25
kpeter@6
   103
length(1,2)=5
kpeter@6
   104
length(0,2)=20
kpeter@6
   105
length(0,1)=10
kpeter@6
   106
\endverbatim
kpeter@6
   107
kpeter@6
   108
You may note that iterating through the nodes and arcs is done in the
kpeter@6
   109
reverse order compared to the creating order (the IDs are in decreasing
kpeter@6
   110
order).
kpeter@6
   111
This is due to implementation aspects, that may differ at other graph
kpeter@6
   112
types, moreover it may be changed in the next releases.
kpeter@6
   113
Thus you should not exploit this method in any way, you should not
kpeter@6
   114
suppose anything about the iteration order.
kpeter@6
   115
kpeter@6
   116
If you managed to compile and run this example code without any problems,
kpeter@6
   117
you can go on reading this tutorial to get to know more features and tools
kpeter@6
   118
of LEMON.
kpeter@6
   119
Otherwise if you encountered problems that you did not manage to solve,
kpeter@6
   120
do not hesitate to
kpeter@6
   121
<a href="mailto:lemon-user@lemon.cs.elte.hu"><b>contact us</b></a>.
kpeter@6
   122
kpeter@3
   123
*/