athos@1173
|
1 |
/**
|
athos@1173
|
2 |
\page getstart How to start using LEMON
|
athos@1173
|
3 |
|
athos@1175
|
4 |
In this page we detail how to start using LEMON, from downloading it to
|
athos@1175
|
5 |
your computer, through the steps of installation to showing a simple
|
athos@1514
|
6 |
"Hello World" type program that already uses LEMON. We assume that you have a
|
athos@1514
|
7 |
basic knowledge of your operating system and \c C++ or \c C
|
athos@1514
|
8 |
programming language. If anything is not
|
athos@1175
|
9 |
clear write to our FAQ.
|
athos@1175
|
10 |
|
athos@1175
|
11 |
\todo Is this FAQ thing a good idea here? Is there such a thing? If
|
athos@1175
|
12 |
twice YES then a link comes here.
|
athos@1175
|
13 |
|
athos@1514
|
14 |
\section requirementsLEMON Hardware and software requirements
|
athos@1175
|
15 |
|
athos@1514
|
16 |
Hardware requirements ...
|
athos@1514
|
17 |
|
athos@1514
|
18 |
You will also need a C++ compiler. We mostly used the Gnu C++ Compiler (g++),
|
athos@1514
|
19 |
from version 3.0 upwards. We also checked the Intel C compiler
|
athos@1514
|
20 |
(icc). Unfortunately, Visual C++ compiler knows not enough to compile the
|
athos@1514
|
21 |
library, so if you are using Microsoft Windows, then try to compile under
|
athos@1514
|
22 |
Cygwin.
|
athos@1514
|
23 |
|
athos@1514
|
24 |
Ide kell írni:
|
athos@1514
|
25 |
|
athos@1514
|
26 |
-Hol fordul (Windows-os fordító nem fordítja, unix/linux alatt gcc hanyas verziója kell)
|
athos@1514
|
27 |
-
|
athos@1514
|
28 |
|
athos@1514
|
29 |
In this description we will suppose a linux environment and Gnu C Compiler.
|
athos@1175
|
30 |
|
athos@1173
|
31 |
\section downloadLEMON How to download LEMON
|
athos@1173
|
32 |
|
athos@1511
|
33 |
You can download LEMON from the LEMON web site:
|
athos@1511
|
34 |
http://lemon.cs.elte.hu
|
athos@1514
|
35 |
by following the download link. There you will find the issued distributions
|
athos@1514
|
36 |
in form of <tt> .tar.gz </tt> files. If you want a developer version (for example you want to contribute in developing the library LEMON) then you might want to use our Subversion repository. This case is not detailed here, so from now on we suppose that you downloaded a tar.gz file.
|
athos@1514
|
37 |
|
athos@1175
|
38 |
|
athos@1173
|
39 |
|
athos@1173
|
40 |
\section installLEMON How to install LEMON
|
athos@1173
|
41 |
|
athos@1173
|
42 |
In order to install LEMON you have to do the following
|
athos@1173
|
43 |
|
athos@1514
|
44 |
Download the tarball (named <tt>lemon-x.y.z.tar.gz</tt> where \c x,\c y and \c z are
|
athos@1514
|
45 |
numbers indicating the version of the library: in our example we will have lemon-0.3.1) and issue the following commands:
|
athos@1511
|
46 |
|
athos@1511
|
47 |
\code
|
athos@1511
|
48 |
tar xvzf lemon-0.3.1.tar.gz
|
athos@1511
|
49 |
cd lemon-0.3.1
|
athos@1511
|
50 |
./configure
|
athos@1511
|
51 |
make
|
athos@1511
|
52 |
make check (This is optional, but recomended. It runs a bunch of tests.)
|
athos@1511
|
53 |
make install
|
athos@1511
|
54 |
\endcode
|
athos@1511
|
55 |
|
athos@1514
|
56 |
These commands install LEMON under \c /usr/local (you will probably need \c root
|
athos@1514
|
57 |
privileges to be able to install to that directory). If you want to install it
|
athos@1514
|
58 |
to some other place, then pass the \c --prefix=DIR flag to \c ./configure. In
|
athos@1514
|
59 |
what follows we will assume that you were able to install to directory \c
|
athos@1514
|
60 |
/usr/local, otherwise some extra care is to be taken to use the library.
|
athos@1511
|
61 |
|
athos@1514
|
62 |
We briefly explain these commands below.
|
athos@1514
|
63 |
|
athos@1514
|
64 |
\code
|
athos@1514
|
65 |
tar xvzf lemon-0.3.1.tar.gz
|
athos@1514
|
66 |
\endcode
|
athos@1514
|
67 |
This command untars the <tt>tar.gz</tt> file into a directory named <tt> lemon-0.3.1</tt>.
|
athos@1514
|
68 |
|
athos@1514
|
69 |
\code
|
athos@1514
|
70 |
cd lemon-0.3.1
|
athos@1514
|
71 |
\endcode
|
athos@1514
|
72 |
Enters the directory.
|
athos@1514
|
73 |
|
athos@1514
|
74 |
\code
|
athos@1514
|
75 |
./configure
|
athos@1514
|
76 |
\endcode
|
athos@1514
|
77 |
Does some configuration (creates makefiles etc).
|
athos@1514
|
78 |
|
athos@1514
|
79 |
\code
|
athos@1514
|
80 |
make
|
athos@1514
|
81 |
\endcode
|
athos@1514
|
82 |
This command compiles the <tt> .cc</tt> files of the library package (the
|
athos@1514
|
83 |
implementation of non-template functions and classes and some test and demo
|
athos@1514
|
84 |
programs) and creates the very important <b> libemon.la </b> file. When
|
athos@1514
|
85 |
linking your program that uses LEMON it needs to access this file.
|
athos@1514
|
86 |
|
athos@1514
|
87 |
\code
|
athos@1514
|
88 |
make check (This is optional, but recomended. It runs a bunch of tests.)
|
athos@1514
|
89 |
\endcode
|
athos@1514
|
90 |
This is an optional step: it runs the test programs that we developed for
|
athos@1514
|
91 |
LEMON to check
|
athos@1514
|
92 |
whether the library works properly on your platform.
|
athos@1514
|
93 |
|
athos@1514
|
94 |
\code
|
athos@1514
|
95 |
make install
|
athos@1514
|
96 |
\endcode
|
athos@1514
|
97 |
This will copy the directory structure to its final destination (e.g. to \c
|
athos@1514
|
98 |
/usr/local) so that your system can access it.
|
athos@1175
|
99 |
|
athos@1173
|
100 |
\section helloworld My first program using LEMON
|
athos@1173
|
101 |
|
athos@1514
|
102 |
If you have installed LEMON on your system you
|
athos@1514
|
103 |
can paste the following code
|
athos@1175
|
104 |
segment into a file to have a first working program that uses library LEMON.
|
athos@1173
|
105 |
|
athos@1175
|
106 |
\code
|
athos@1175
|
107 |
#include <iostream>
|
athos@1175
|
108 |
#include <lemon/list_graph.h>
|
athos@1173
|
109 |
|
athos@1175
|
110 |
using namespace lemon;
|
athos@1175
|
111 |
|
athos@1175
|
112 |
int main()
|
athos@1175
|
113 |
{
|
athos@1175
|
114 |
typedef ListGraph Graph;
|
athos@1175
|
115 |
typedef Graph::EdgeIt EdgeIt;
|
athos@1175
|
116 |
typedef Graph::NodeIt NodeIt;
|
athos@1175
|
117 |
|
athos@1175
|
118 |
Graph g;
|
athos@1175
|
119 |
|
athos@1175
|
120 |
for (int i = 0; i < 3; i++)
|
athos@1175
|
121 |
g.addNode();
|
athos@1175
|
122 |
|
athos@1175
|
123 |
for (NodeIt i(g); i!=INVALID; ++i)
|
athos@1175
|
124 |
for (NodeIt j(g); j!=INVALID; ++j)
|
athos@1175
|
125 |
if (i != j) g.addEdge(i, j);
|
athos@1175
|
126 |
|
athos@1175
|
127 |
std::cout << "Nodes:";
|
athos@1175
|
128 |
for (NodeIt i(g); i!=INVALID; ++i)
|
athos@1175
|
129 |
std::cout << " " << g.id(i);
|
athos@1175
|
130 |
std::cout << std::endl;
|
athos@1175
|
131 |
|
athos@1175
|
132 |
std::cout << "Edges:";
|
athos@1175
|
133 |
for (EdgeIt i(g); i!=INVALID; ++i)
|
athos@1175
|
134 |
std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
|
athos@1175
|
135 |
std::cout << std::endl;
|
athos@1175
|
136 |
|
athos@1175
|
137 |
\endcode
|
athos@1175
|
138 |
|
athos@1514
|
139 |
First let us briefly explain how this program works.
|
athos@1175
|
140 |
|
athos@1175
|
141 |
ListGraph is one of LEMON's graph classes. It is based on linked lists,
|
athos@1175
|
142 |
therefore iterating throuh its edges and nodes is fast.
|
athos@1175
|
143 |
|
athos@1175
|
144 |
After some convenient typedefs we create a graph and add three nodes to it.
|
athos@1175
|
145 |
Then we add edges to it to form a complete graph.
|
athos@1175
|
146 |
|
athos@1175
|
147 |
Then we iterate through all nodes of the graph. We use a constructor of the
|
athos@1175
|
148 |
node iterator to initialize it to the first node. The operator++ is used to
|
athos@1175
|
149 |
step to the next node. Using operator++ on the iterator pointing to the last
|
athos@1175
|
150 |
node invalidates the iterator i.e. sets its value to
|
athos@1175
|
151 |
\ref lemon::INVALID "INVALID". This is what we exploit in the stop condition.
|
athos@1175
|
152 |
|
athos@1175
|
153 |
We can also iterate through all edges of the graph very similarly. The
|
athos@1175
|
154 |
\c target and
|
athos@1175
|
155 |
\c source member functions can be used to access the endpoints of an edge.
|
athos@1175
|
156 |
|
athos@1514
|
157 |
If you have saved the preceding code into a file named, say, \c hemon.cc and your installation of LEMON into directory \c /usr/local was
|
athos@1514
|
158 |
successful then it is very easy to compile this program with the following
|
athos@1514
|
159 |
command (the argument <tt>-lemon</tt> tells the compiler that we are using the
|
athos@1514
|
160 |
installed library LEMON):
|
athos@1514
|
161 |
\code
|
athos@1514
|
162 |
g++ hemon.cc -o hemon -lemon
|
athos@1514
|
163 |
\endcode
|
athos@1514
|
164 |
|
athos@1514
|
165 |
As a result you will get the exacutable \c hemon in
|
athos@1514
|
166 |
this directory that you can run by the command
|
athos@1514
|
167 |
\code
|
athos@1514
|
168 |
./hemon
|
athos@1514
|
169 |
\endcode
|
athos@1514
|
170 |
|
athos@1514
|
171 |
|
athos@1514
|
172 |
If everything has gone well then the previous code fragment prints out the following:
|
athos@1175
|
173 |
|
athos@1175
|
174 |
\code
|
athos@1175
|
175 |
Nodes: 2 1 0
|
athos@1175
|
176 |
|
athos@1175
|
177 |
Edges: (0,2) (1,2) (0,1) (2,1) (1,0) (2,0)
|
athos@1175
|
178 |
\endcode
|
athos@1175
|
179 |
|
athos@1514
|
180 |
Congratulations!
|
athos@1175
|
181 |
|
athos@1175
|
182 |
If you want to see more features, go to the \ref quicktour "Quick Tour to
|
athos@1175
|
183 |
LEMON", if you want to see see some demo programs then go to our
|
athos@1175
|
184 |
\ref demoprograms "Demo Programs" page!
|
athos@1175
|
185 |
|
athos@1175
|
186 |
|
athos@1175
|
187 |
*/
|