COIN-OR::LEMON - Graph Library

source: lemon-tutorial/getting_started.dox @ 10:55e2f7712e87

Last change on this file since 10:55e2f7712e87 was 10:55e2f7712e87, checked in by Alpar Juttner <alpar@…>, 16 years ago

TOC and section numbering are generated from toc.txt

File size: 3.9 KB
Line 
1/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library.
4 *
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19/**
20[PAGE]hello_lemon[PAGE] Compile Your First Code
21
22If you have installed LEMON on your system you can paste the following
23code segment into a file called <tt>hello_lemon.cc</tt> to have a first
24working program that uses LEMON.
25
26\dontinclude hello_lemon.cc
27\skip #include
28\until }
29
30First let us briefly explain how this example program works.
31(The used notions will be discussed in detail in the following sections.)
32
33After some convenience typedefs we create a directed graph (\e digraph)
34and add some nodes and arcs to it.
35ListDigraph is one of the digraph classes implemented in LEMON.
36It is based on linked lists, therefore iterating through its nodes and
37arcs is fast.
38
39Then we iterate through all nodes of the digraph and print their unique
40IDs. We use a constructor of the node iterator to initialize it to the
41first node.
42The <tt>operator++</tt> is used to step to the next node. After the last
43node the iterator becomes invalid (i.e. it is set to \c INVALID).
44This is what we exploit in the stop condition.
45We iterate through all arcs of the digraph very similarly and print the
46IDs of their source (tail) and target (head) nodes using the \c source()
47and \c target() member functions.
48
49After that we create an arc map, which is actually a mapping that assigns
50an \c int value (length) to each arc, and we set this value for each arc.
51Finally we iterate through all arcs again and print their lengths.
52
53Now let us compile this simple example program.
54
55[SEC]hello_lemon_system[SEC] If LEMON is Installed System-Wide
56
57If LEMON is installed system-wide (into directory \c /usr/local),
58then it is very easy to compile this program with the
59following command (the argument <tt>-lemon</tt> tells the compiler
60that we are using the installed LEMON):
61
62\verbatim
63g++ -lemon hello_lemon.cc -o hello_lemon
64\endverbatim
65
66As a result you will get the exacutable \c hello_lemon in the current
67directory, which you can run by the following command.
68
69\verbatim
70./hello_lemon
71\endverbatim
72
73[SEC]hello_lemon_user[SEC] If LEMON is Installed User-Local
74
75Compiling the code is a bit more difficult if you installed LEMON
76user-local into a directory (e.g. <tt>~/lemon</tt>) or if you just
77skipped the step <tt>make install</tt>.
78You have to issue a command like this.
79
80\verbatim
81g++ -lemon -I ~/lemon -L ~/lemon/lemon/.libs hello_lemon.cc -o hello_lemon
82\endverbatim
83
84If everything has gone well, then our program prints out the followings.
85
86\verbatim
87Hello World!
88This is LEMON library here. We have a direceted graph.
89
90Nodes: 3 2 1 0
91Arcs: (2,3) (1,3) (1,2) (0,2) (0,1)
92
93There is a map on the arcs (length):
94
95length(2,3)=10
96length(1,3)=25
97length(1,2)=5
98length(0,2)=20
99length(0,1)=10
100\endverbatim
101
102You may note that iterating through the nodes and arcs is done in the
103reverse order compared to the creating order (the IDs are in decreasing
104order).
105This is due to implementation aspects, that may differ at other graph
106types, moreover it may be changed in the next releases.
107Thus you should not exploit this method in any way, you should not
108suppose anything about the iteration order.
109
110If you managed to compile and run this example code without any problems,
111you can go on reading this tutorial to get to know more features and tools
112of LEMON.
113Otherwise if you encountered problems that you did not manage to solve,
114do not hesitate to
115<a href="mailto:lemon-user@lemon.cs.elte.hu"><b>contact us</b></a>.
116
117[TRAILER]
118*/
Note: See TracBrowser for help on using the repository browser.