/* -*- mode: C++; indent-tabs-mode: nil; -*- * * This file is a part of LEMON, a generic C++ optimization library. * * Copyright (C) 2003-2008 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For * precise terms see the accompanying LICENSE file. * * This software is provided "AS IS" with no warranty of any kind, * express or implied, and with no claim as to its suitability for any * purpose. * */ /** [PAGE]hello_lemon[PAGE] Compile Your First Code If you have installed LEMON on your system you can paste the following code segment into a file called hello_lemon.cc to have a first working program that uses LEMON. \dontinclude hello_lemon.cc \skip #include \until } First let us briefly explain how this example program works. (The used notions will be discussed in detail in the following sections.) After some convenience typedefs we create a directed graph (\e digraph) and add some nodes and arcs to it. ListDigraph is one of the digraph classes implemented in LEMON. It is based on linked lists, therefore iterating through its nodes and arcs is fast. Then we iterate through all nodes of the digraph and print their unique IDs. 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. After the last node the iterator becomes invalid (i.e. it is set to \c INVALID). This is what we exploit in the stop condition. We iterate through all arcs of the digraph very similarly and print the IDs of their source (tail) and target (head) nodes using the \c source() and \c target() member functions. After that we create an arc map, which is actually a mapping that assigns an \c int value (length) to each arc, and we set this value for each arc. Finally we iterate through all arcs again and print their lengths. Now let us compile this simple example program. [SEC]hello_lemon_system[SEC] If LEMON is Installed System-Wide If LEMON is installed system-wide (into directory \c /usr/local), 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 LEMON): \verbatim g++ -lemon hello_lemon.cc -o hello_lemon \endverbatim As a result you will get the exacutable \c hello_lemon in the current directory, which you can run by the following command. \verbatim ./hello_lemon \endverbatim [SEC]hello_lemon_user[SEC] If LEMON is Installed User-Local Compiling the code is a bit more difficult if you installed LEMON user-local into a directory (e.g. ~/lemon) or if you just skipped the step make install. You have to issue a command like this. \verbatim g++ -lemon -I ~/lemon -L ~/lemon/lemon/.libs hello_lemon.cc -o hello_lemon \endverbatim If everything has gone well, then our program prints out the followings. \verbatim Hello World! This is LEMON library here. We have a direceted graph. Nodes: 3 2 1 0 Arcs: (2,3) (1,3) (1,2) (0,2) (0,1) There is a map on the arcs (length): length(2,3)=10 length(1,3)=25 length(1,2)=5 length(0,2)=20 length(0,1)=10 \endverbatim You may note that iterating through the nodes and arcs is done in the reverse order compared to the creating order (the IDs are in decreasing order). This is due to implementation aspects, that may differ at other graph types, moreover it may be changed in the next releases. Thus you should not exploit this method in any way, you should not suppose anything about the iteration order. If you managed to compile and run this example code without any problems, you can go on reading this tutorial to get to know more features and tools of LEMON. Otherwise if you encountered problems that you did not manage to solve, do not hesitate to contact us. [TRAILER] */