COIN-OR::LEMON - Graph Library

source: lemon-tutorial/getting_started.dox @ 7:934258c64b6b

Last change on this file since 7:934258c64b6b was 7:934258c64b6b, checked in by Alpar Juttner <alpar@…>, 12 years ago

Rework installation part and move it to the appendix

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