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