COIN-OR::LEMON - Graph Library

source: lemon-0.x/doc/getstart.dox @ 1514:c9b9bc63db4e

Last change on this file since 1514:c9b9bc63db4e was 1514:c9b9bc63db4e, checked in by athos, 14 years ago

Improved getsart.dox and quicktour.dox

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