How to start using LEMON

In this page we detail how to start using LEMON, from downloading it to your computer, through the steps of installation, to showing a simple "Hello World" type program that already uses LEMON. We assume that you have a basic knowledge of your operating system and C++ programming language. The procedure is pretty straightforward, but if you have any difficulties don't hesitate to ask.

Hardware and software requirements

In LEMON we use C++ templates heavily, thus compilation takes a considerable amount of time and memory. So some decent box would be advantageous. But otherwise there are no special hardware requirements.

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.

LP solver requirements

The LEMON LP solver interface can use the GLPK (GNU Linear Programming Kit) ,CPLEX (was tested with CPLEX 7.5) and SoPlex solver. If you want to use it you will need at least one of these. See Configure flags how to enable these at compile time.

How to download LEMON

You can download LEMON from the LEMON web site: https://lemon.cs.elte.hu/site/products/ . There you will find released versions in form of .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.

How to install LEMON

In order to install LEMON you have to do the following steps.

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
This command untars the tar.gz file into a directory named lemon-0.3.1.

cd lemon-0.3.1
Enters the directory.

./configure
Does some configuration (creates makefiles etc).

make
This command compiles the non-template part of LEMON into libemon.a file. It also compiles some benchmark and demo programs.

make check
This is an optional step: it runs the test programs that we developed for LEMON to check whether the library works properly on your platform.

make install
This will copy the directory structure to its final destination (e.g. to /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 flags

You can pass the following flags to ./configure (see ./configure --help for more):

--with-glpk[=PREFIX]
Enable GLPK support (default). You should specify the prefix too if you installed it to some non-standard location (e.g. your home directory). If GLPK is not found, then GLPK support will be disabled.

--with-glpk-includedir=DIR
The directory where the GLPK header files are located. This is only useful when the GLPK headers and libraries are not under the same prefix (which is unlikely).

--with-glpk-libdir=DIR
The directory where the GLPK libraries are located. This is only useful when the GLPK headers and libraries are not under the same prefix (which is unlikely).

--without-glpk
Disable GLPK support.

--with-cplex[=PREFIX]
Enable CPLEX support (default). You should specify the prefix too if you installed it to some non-standard location (e.g. /opt/ilog/cplex75). If CPLEX is not found, then CPLEX support will be disabled.

--with-cplex-includedir=DIR
The directory where the CPLEX header files are located. This is only useful when the CPLEX headers and libraries are not under the same prefix.

--with-cplex-libdir=DIR
The directory where the CPLEX libraries are located. This is only useful when the CPLEX headers and libraries are not under the same prefix.

--without-cplex
Disable CPLEX support.

--with-soplex[=PREFIX] 
Enable SoPlex support (default). You should specify the prefix too if you installed it to some non-standard location. If SoPlex is not found, then SoPlex support will be disabled.

--with-soplex-includedir=DIR
The directory where the SoPlex header files are located. This is only useful when the SoPlex headers and libraries are not under the same prefix.

--with-soplex-libdir=DIR
The directory where the SoPlex libraries are located. This is only useful when the SoPlex headers and libraries are not under the same prefix.

--without-soplex
Disable SoPlex support.

How to checkout LEMON form our Subversion repository

You can obtain the latest version of LEMON from our Subversion repository. To do this issue the following command:
svn co https://lemon.cs.elte.hu/svn/lemon/trunk lemon-src
Use "lemon" as username, the password is empty.

How to compile the source from the repository

You can compile the code from the repository similarly to the packaged version, but you will need to run 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).

My first program using LEMON

If you have installed LEMON on your system you can paste the following code segment into a file (you can find it as 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!


Generated on Thu Jun 4 04:03:12 2009 for LEMON by  doxygen 1.5.9