C++
programming language. The procedure is pretty straightforward, but if you have any difficulties don't hesitate to ask.You will need a recent C++ compiler. Our primary target is the GNU C++ Compiler (g++), from version 3.3 upwards. We also checked the Intel C++ Compiler (icc). Microsoft Visual C++ .NET 2003 was also reported to work (but not the earlier versions). If you want to develop with LEMON under Windows you could consider using Cygwin.
In this description we will suppose a Linux environment and GNU C++ Compiler.
.tar.gz
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 detailed later, so from now on we suppose that you downloaded a .tar.gz
file.
Download the tarball (named lemon-x.y.z.tar.gz
where x
,y
and z
are numbers indicating the version of the library: in our example we will have lemon-0.3.1.tar.gz
) and issue the following commands:
tar xvzf lemon-0.3.1.tar.gz cd lemon-0.3.1 ./configure make make check #(This is optional, but recommended. It runs a bunch of tests.) make install
These commands install LEMON under /usr/local
(you will need root privileges to be able to install to that directory). If you want to install it to some other place, then pass the --prefix=DIRECTORY
flag to ./configure
, for example:
./configure --prefix=/home/username/lemon
In what follows we will assume that you were able to install to directory /usr/local
, otherwise some extra care is to be taken to use the library.
We briefly explain these commands below.
tar xvzf lemon-0.3.1.tar.gz
tar.gz
file into a directory named lemon-0.3.1
.
cd lemon-0.3.1
./configure
make
make check
make install
/usr/local
) so that your system can access it. This command should be issued as "root", unless you provided a --prefix
switch to the configure
to install the library in non-default location../configure
(see ./configure
--help for more):
--with-glpk[=PREFIX]
--with-glpk-includedir=DIR
--with-glpk-libdir=DIR
--without-glpk
--with-cplex[=PREFIX]
/opt/ilog/cplex75
). If CPLEX is not found, then CPLEX support will be disabled.
--with-cplex-includedir=DIR
--with-cplex-libdir=DIR
--without-cplex
--with-soplex[=PREFIX]
--with-soplex-includedir=DIR
--with-soplex-libdir=DIR
--without-soplex
svn co https://lemon.cs.elte.hu/svn/lemon/trunk lemon-src
autoreconf
-vi
or ./bootstrap
in some older environment before ./configure
. See
./configure --help
for options. For bootstrapping you will need the following tools:
To generate the documentation, run make
doc
. You will need Doxygen for this.
You can pass the --enable-doc=full
flag to ./configure
to generate the internal documentation too.
If you pass the --disable-doc
flag to ./configure
then the documentation won't be installed, when you run make
install
(this speeds things up a bit).
demo/hello_lemon.cc
in the LEMON package) to have a first working program that uses library LEMON.
#include <iostream> #include <lemon/list_graph.h> int main() { typedef lemon::ListGraph Graph; typedef Graph::EdgeIt EdgeIt; typedef Graph::Edge Edge; typedef Graph::NodeIt NodeIt; typedef Graph::Node Node; typedef Graph::EdgeMap<int> LengthMap; using lemon::INVALID; Graph g; Node s=g.addNode(); Node v2=g.addNode(); Node v3=g.addNode(); Node v4=g.addNode(); Node v5=g.addNode(); Node t=g.addNode(); Edge s_v2=g.addEdge(s, v2); Edge s_v3=g.addEdge(s, v3); Edge v2_v4=g.addEdge(v2, v4); Edge v2_v5=g.addEdge(v2, v5); Edge v3_v5=g.addEdge(v3, v5); Edge v4_t=g.addEdge(v4, t); Edge v5_t=g.addEdge(v5, t); LengthMap length(g); length[s_v2]=10; length[s_v3]=10; length[v2_v4]=5; length[v2_v5]=8; length[v3_v5]=5; length[v4_t]=8; length[v5_t]=8; std::cout << "Hello World!" << std::endl; std::cout << std::endl; std::cout << "This is library LEMON here! We have a graph!" << std::endl; std::cout << std::endl; std::cout << "Nodes:"; for (NodeIt i(g); i!=INVALID; ++i) std::cout << " " << g.id(i); std::cout << std::endl; std::cout << "Edges:"; for (EdgeIt i(g); i!=INVALID; ++i) std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")"; std::cout << std::endl; std::cout << std::endl; std::cout << "There is a map on the edges (length)!" << std::endl; std::cout << std::endl; for (EdgeIt i(g); i!=INVALID; ++i) std::cout << "length(" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")="<<length[i]<<std::endl; std::cout << std::endl; }
First let us briefly explain how this program works.
ListGraph is one of LEMON's graph classes. It is based on linked lists, therefore iterating throuh its edges and nodes is fast.
After some convenience typedefs we create a graph and add three nodes to it. Then we add edges to it to form a complete graph.
Then we iterate through all nodes of the graph. We use a constructor of the node iterator to initialize it to the first node. The operator++ is used to step to the next node. Using operator++ on the iterator pointing to the last node invalidates the iterator i.e. sets its value to INVALID. This is what we exploit in the stop condition.
We can also iterate through all edges of the graph very similarly. The target
and source
member functions can be used to access the endpoints of an edge.
If your installation of LEMON into directory /usr/local
was successful, then it is very easy to compile this program with the following command (the argument -lemon
tells the compiler that we are using the installed library LEMON):
g++ hello_lemon.cc -o hello_lemon -lemon
As a result you will get the exacutable hello_lemon
in this directory that you can run by the command
./hello_lemon
If everything has gone well then the previous code fragment prints out the following:
Nodes: 2 1 0 Edges: (0,2) (1,2) (0,1) (2,1) (1,0) (2,0)
Congratulations!
If you want to see more features, go to the Quick Tour to LEMON, if you want to see some demo programs then go to our Demo Programs page!