COIN-OR::LEMON - Graph Library

source: lemon-0.x/doc/getting_started.dox @ 2449:1d685ac667ec

Last change on this file since 2449:1d685ac667ec was 2449:1d685ac667ec, checked in by Alpar Juttner, 12 years ago

Minor improvement in Tutorial

File size: 4.1 KB
Line 
1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
5 * Copyright (C) 2003-2007
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19/**
20\page getting_started Getting Started
21
22At the beginning we strongly suggest that you open your favorite text
23editor and enter the code simultaneously as you read it. Compiling the
24demos is also a good exercise.
25
26As the first example we show you a lemon style "Hello World"
27program. Now we explain almost every line, but later we will skip the
28basics and focus on new things.
29
30\section hello_world Hello World in LEMON
31
32In this little program we give you a taste of the LEMON programming.
33
34Let's see the code fragment to fragment!
35
36\dontinclude hello_world.cc
37\skip include
38\until iostream
39
40We want to use a \c lemon::ListGraph so the include goes like this:
41\skip include
42\until list_graph
43
44The next few lines are not necessary but useful shortcuts, if you don't
45want to type \c lemon::ListGraph::Node every time.
46\skip using
47\until Edge
48
49For this demo we need to declare a ListGraph and a special NodeMap to
50store the characters associated to the graph's nodes. 
51\skip main
52\until char_map
53
54Adding nodes to the graph is very easy.
55\skip new_node
56\until addNode
57
58When a new node or edge is added to the graph the assigned maps are automatically resized.
59So graphs can be built dynamically. The usage of a map is very natural.
60\skip char_map
61\until char_map
62
63Notice that no reference or additional assignment is needed to work with nodes.
64They won't become illegal or won't lead to throwing any exceptions.
65You can declare and handle a node like every other basic type such as \c int.
66\skip Store
67\until char_map
68
69As one expects adding an Edge is similar. You need to define the \b source node
70and the \b destination node. The nodes must belong to the graph of course. The
71Edge has the direction from the source to the destination. In some cases you don't
72want the edges to be directed - then you use an undirected graph. For example
73lemon::ListUGraph.
74\skip addEdge
75\until addEdge
76
77In the next few lines we add some more nodes and edges and to the graph we need.
78Those lines are not very interesting so we skip them, but you find the whole
79working program in file hello_world.cc in the demo section.
80
81The next statement must be familiar. But what is that INVALID in the \c while
82test statement? In LEMON we usually use the INVALID to check if an object
83contains valid information.
84\skip current_node
85\until {
86
87We take the current node and write out the character assigned to it. Is's easy
88with the \c char_map.
89\skip std
90\until std
91
92And here comes the trick. OutEdgeIt iterates on outgoing edges of a given node.
93We pass the current node as argument to it, so the \c edge iterator will stand
94on the first outgoing edge of the current node, or will be INVALID if the node
95has no outgoing edges.
96\skip edge
97\until edge
98
99The graph we built before is linear, so we know that it ends, when no more outgoing
100edges found. Otherwise the current node must be the node the edge points to.
101Basic information about an edge can be requested from the graph.
102\skip if
103\until }
104
105Finish the code, just to be precise.
106\skip return
107\until }
108
109
110\section compile_hw Compiling Hello World
111To compile this program all you have to do is type in
112\code g++ -ohello_world hello_world.cc \endcode
113and press \c Enter! This is the case if you installed LEMON on your system.
114(For more information see the LEMON installation instructions.)
115
116This is because LEMON is template library and most of it's code has to be available
117as source code during compilation.
118 
119Most programs using LEMON will compile as easy as this one unless you want to
120use some performance measuring tools LEMON can provide. Then you need to link
121an additional library against your program.
122*/
Note: See TracBrowser for help on using the repository browser.