doc/getting_started.dox
author alpar
Fri, 19 Jan 2007 17:15:15 +0000
changeset 2346 c06a956a92fa
parent 2195 f47faf6913ab
child 2391 14a343be7a5a
permissions -rw-r--r--
elevator.h: A class for handling item labels in push-relabel type algorithms
alpar@2195
     1
/**
alpar@2195
     2
\page getting_started Getting Started
alpar@2195
     3
athos@2288
     4
At the beginning we strongly suggest that you open your favorite text
athos@2288
     5
editor and enter the code simultaneously as you read it. Compiling the
athos@2288
     6
demos is also a good exercise.
alpar@2195
     7
athos@2288
     8
As the first example we show you a lemon style "Hello World"
athos@2288
     9
program. Now we explain almost every line, but later we will skip the
athos@2288
    10
basics and focus on new things.
alpar@2195
    11
alpar@2195
    12
\section hello_world Hello World in LEMON
alpar@2195
    13
alpar@2195
    14
In this little program we give you a taste of the LEMON programming.
alpar@2195
    15
alpar@2195
    16
Let's see the code fragment to fragment!
alpar@2195
    17
alpar@2195
    18
\dontinclude hello_world.cc
alpar@2195
    19
\skip include
alpar@2195
    20
\until iostream
alpar@2195
    21
alpar@2195
    22
We want to use a \c lemon::ListGraph so the include goes like this:
alpar@2195
    23
\skip include
alpar@2195
    24
\until list_graph
alpar@2195
    25
alpar@2195
    26
The next few lines are not necessary but useful shortcuts, if you don't
alpar@2195
    27
want to type \c lemon::ListGraph::Node every time.
alpar@2195
    28
\skip using
alpar@2195
    29
\until Edge
alpar@2195
    30
athos@2288
    31
For this demo we need to declare a ListGraph and a special NodeMap to
athos@2288
    32
store the characters associated to the graph's nodes.  
alpar@2195
    33
\skip main
alpar@2195
    34
\until char_map
alpar@2195
    35
alpar@2195
    36
Adding nodes to the graph is very easy.
alpar@2195
    37
\skip new_node
alpar@2195
    38
\until addNode
alpar@2195
    39
athos@2288
    40
When a new node or edge is added to the graph the assigned maps are automatically resized.
athos@2288
    41
So graphs can be built dynamically. The usage of a map is very natural.
alpar@2195
    42
\skip char_map
alpar@2195
    43
\until char_map
alpar@2195
    44
athos@2288
    45
Notice that no reference or additional assignment is needed to work with nodes.
alpar@2195
    46
They won't become illegal or won't lead to throwing any exceptions.
athos@2288
    47
You can declare and handle a node like every other basic type such as \c int.
alpar@2195
    48
\skip Store
alpar@2195
    49
\until char_map
alpar@2195
    50
alpar@2195
    51
As one expects adding an Edge is similar. You need to define the \b source node
alpar@2195
    52
and the \b destination node. The nodes must belong to the graph of course. The
athos@2288
    53
Edge has the direction from the source to the destination. In some cases you don't
alpar@2195
    54
want the edges to be directed - then you use an undirected graph. For example
alpar@2195
    55
lemon::ListUGraph.
alpar@2195
    56
\skip addEdge
alpar@2195
    57
\until addEdge
alpar@2195
    58
alpar@2195
    59
In the next few lines we add some more nodes and edges and to the graph we need.
alpar@2195
    60
Those lines are not very interesting so we skip them, but you find the whole
alpar@2195
    61
working program in file hello_lemon.cc in the demo section.
alpar@2195
    62
alpar@2195
    63
The next statement must be familiar. But what is that INVALID in the \c while
alpar@2195
    64
test statement? In LEMON we usually use the INVALID to check if an object
alpar@2195
    65
contains valid information.
alpar@2195
    66
\skip current_node
alpar@2195
    67
\until {
alpar@2195
    68
alpar@2195
    69
We take the current node and write out the character assigned to it. Is's easy
alpar@2195
    70
with the \c char_map.
alpar@2195
    71
\skip std
alpar@2195
    72
\until std
alpar@2195
    73
alpar@2195
    74
And here comes the trick. OutEdgeIt iterates on outgoing edges of a given node.
alpar@2195
    75
We pass the current node as argument to it, so the \c edge iterator will stand
alpar@2195
    76
on the first outgoing edge of the current node, or will be INVALID if the node
alpar@2195
    77
has no outgoing edges.
alpar@2195
    78
\skip edge
alpar@2195
    79
\until edge
alpar@2195
    80
alpar@2195
    81
The graph we built before is linear, so we know that it ends, when no more outgoing
alpar@2195
    82
edges found. Otherwise the current node must be the node the edge points to.
alpar@2195
    83
Basic information about an edge can be requested from the graph.
alpar@2195
    84
\skip if
alpar@2195
    85
\until }
alpar@2195
    86
alpar@2195
    87
Finish the code, just to be precise.
alpar@2195
    88
\skip return
alpar@2195
    89
\until }
alpar@2195
    90
alpar@2195
    91
alpar@2195
    92
\section compile_hw Compiling Hello World
alpar@2195
    93
To compile this program all you have to do is type in
alpar@2195
    94
\code g++ -ohw hello_world.cc \endcode
alpar@2195
    95
and press \c Enter! This is the case if you installed LEMON on your system.
alpar@2195
    96
(For more information see the LEMON installation instructions.)
alpar@2195
    97
alpar@2195
    98
This is because LEMON is template library and most of it's code has to be available
alpar@2195
    99
as source code during compilation.
alpar@2195
   100
 
alpar@2195
   101
Most programs using LEMON will compile as easy as this one unless you want to
alpar@2195
   102
use some performance measuring tools LEMON can provide. Then you need to link
alpar@2195
   103
an additional library against your program.
alpar@2195
   104
*/