27 |
27 |
28 \dontinclude hello_lemon.cc |
28 \dontinclude hello_lemon.cc |
29 \skip #include |
29 \skip #include |
30 \until } |
30 \until } |
31 |
31 |
32 First let us briefly explain how this example program works. |
32 In this small example a directed graph is created with two nodes and |
33 (The used notions will be discussed in detail in the following sections.) |
33 an arc added to it. |
34 |
34 |
35 After some convenience typedefs we create a directed graph (\e digraph) |
35 Now let us compile this code. |
36 and add some nodes and arcs to it. |
36 (We suppose that you have it in a file called <tt>hello_lemon.cc</tt>.) |
37 ListDigraph is one of the digraph classes implemented in LEMON. |
|
38 It is based on linked lists, therefore iterating through its nodes and |
|
39 arcs is fast. |
|
40 |
37 |
41 Then we iterate through all nodes of the digraph and print their unique |
38 If LEMON is installed <b>system-wide</b> (into directory \c /usr/local), |
42 IDs. We use a constructor of the node iterator to initialize it to the |
|
43 first node. |
|
44 The <tt>operator++</tt> is used to step to the next node. After the last |
|
45 node the iterator becomes invalid (i.e. it is set to \c INVALID). |
|
46 This is what we exploit in the stop condition. |
|
47 We iterate through all arcs of the digraph very similarly and print the |
|
48 IDs of their source (tail) and target (head) nodes using the \c source() |
|
49 and \c target() member functions. |
|
50 |
|
51 After that we create an arc map, which is actually a mapping that assigns |
|
52 an \c int value (length) to each arc, and we set this value for each arc. |
|
53 Finally we iterate through all arcs again and print their lengths. |
|
54 |
|
55 Now let us compile this simple example program. |
|
56 |
|
57 [SEC]hello_lemon_system[SEC] If LEMON is Installed System-Wide |
|
58 |
|
59 If LEMON is installed system-wide (into directory \c /usr/local), |
|
60 then it is very easy to compile this program with the |
39 then it is very easy to compile this program with the |
61 following command (the argument <tt>-lemon</tt> tells the compiler |
40 following command (the argument <tt>-lemon</tt> tells the compiler |
62 that we are using the installed LEMON): |
41 that we are using the installed LEMON). |
63 |
42 |
64 \verbatim |
43 \verbatim |
65 g++ -lemon hello_lemon.cc -o hello_lemon |
44 g++ -lemon hello_lemon.cc -o hello_lemon |
66 \endverbatim |
45 \endverbatim |
67 |
46 |
70 |
49 |
71 \verbatim |
50 \verbatim |
72 ./hello_lemon |
51 ./hello_lemon |
73 \endverbatim |
52 \endverbatim |
74 |
53 |
75 [SEC]hello_lemon_user[SEC] If LEMON is Installed User-Local |
54 If LEMON is installed <b>user-local</b> into a directory |
76 |
55 (e.g. <tt>~/lemon</tt>) or if you just skipped the step |
77 Compiling the code is a bit more difficult if you installed LEMON |
56 <tt>make install</tt>, then compiling the code is a bit more difficult. |
78 user-local into a directory (e.g. <tt>~/lemon</tt>) or if you just |
|
79 skipped the step <tt>make install</tt>. |
|
80 You have to issue a command like this. |
57 You have to issue a command like this. |
81 |
58 |
82 \verbatim |
59 \verbatim |
83 g++ -lemon -I ~/lemon -L ~/lemon/lemon/.libs hello_lemon.cc -o hello_lemon |
60 g++ -lemon -I ~/lemon -L ~/lemon/lemon/.libs hello_lemon.cc -o hello_lemon |
84 \endverbatim |
61 \endverbatim |
85 |
62 |
86 If everything has gone well, then our program prints out the followings. |
63 If everything has gone well, then our program prints out the followings. |
87 |
64 |
88 \verbatim |
65 \verbatim |
89 Hello World! |
66 Hello World! This is LEMON library here. |
90 This is LEMON library here. We have a direceted graph. |
67 We have a directed graph with 2 nodes and 1 arc. |
91 |
|
92 Nodes: 3 2 1 0 |
|
93 Arcs: (2,3) (1,3) (1,2) (0,2) (0,1) |
|
94 |
|
95 There is a map on the arcs (length): |
|
96 |
|
97 length(2,3)=10 |
|
98 length(1,3)=25 |
|
99 length(1,2)=5 |
|
100 length(0,2)=20 |
|
101 length(0,1)=10 |
|
102 \endverbatim |
68 \endverbatim |
103 |
69 |
104 You may note that iterating through the nodes and arcs is done in the |
|
105 reverse order compared to the creating order (the IDs are in decreasing |
|
106 order). |
|
107 This is due to implementation aspects, that may differ at other graph |
|
108 types, moreover it may be changed in the next releases. |
|
109 Thus you should not exploit this method in any way, you should not |
|
110 suppose anything about the iteration order. |
|
111 |
|
112 If you managed to compile and run this example code without any problems, |
70 If you managed to compile and run this example code without any problems, |
113 you can go on reading this tutorial to get to know more features and tools |
71 you may go on reading this tutorial to get to know the basic notions, |
114 of LEMON. |
72 features and tools of LEMON. However if you encountered problems that |
115 Otherwise if you encountered problems that you did not manage to solve, |
73 you did not manage to solve, do not hesitate to |
116 do not hesitate to |
|
117 <a href="mailto:lemon-user@lemon.cs.elte.hu"><b>contact us</b></a>. |
74 <a href="mailto:lemon-user@lemon.cs.elte.hu"><b>contact us</b></a>. |
118 |
75 |
119 [TRAILER] |
76 [TRAILER] |
120 */ |
77 */ |
121 } |
78 } |