COIN-OR::LEMON - Graph Library

source: lemon-0.x/doc/getting_started.dox @ 2196:09af6d2b683b

Last change on this file since 2196:09af6d2b683b was 2195:f47faf6913ab, checked in by Alpar Juttner, 18 years ago

Tutorial improvements by Mark (mqrelly)

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