1 | /* -*- C++ -*- |
---|
2 | * |
---|
3 | * This file is a part of LEMON, a generic C++ optimization library |
---|
4 | * |
---|
5 | * Copyright (C) 2003-2006 |
---|
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 | ///\ingroup demos |
---|
20 | ///\file |
---|
21 | ///\brief LEMON style "Hello World!" program |
---|
22 | /// |
---|
23 | /// This program is intended to be a "Hello World!" program that shows |
---|
24 | /// the very basic notions of the LEMON library: \ref graphs "graphs" and |
---|
25 | /// \ref maps-page "maps". Click on the links to read more about these. |
---|
26 | /// |
---|
27 | /// \include hello_lemon.cc |
---|
28 | |
---|
29 | #include <iostream> |
---|
30 | #include <lemon/list_graph.h> |
---|
31 | |
---|
32 | using namespace lemon; |
---|
33 | |
---|
34 | typedef ListGraph::Node Node; |
---|
35 | typedef ListGraph::Edge Edge; |
---|
36 | |
---|
37 | |
---|
38 | int main() |
---|
39 | { |
---|
40 | // Declare the graph itself and a NodeMap, witch will store the characters |
---|
41 | // assigned to the nodes |
---|
42 | ListGraph graph; |
---|
43 | ListGraph::NodeMap<char> char_map(graph); |
---|
44 | |
---|
45 | // Add nodes |
---|
46 | Node new_node = graph.addNode(); |
---|
47 | char_map[new_node] = 'H'; |
---|
48 | |
---|
49 | // Store the start node |
---|
50 | Node start_node = new_node; |
---|
51 | |
---|
52 | Node from_node = new_node; |
---|
53 | new_node = graph.addNode(); |
---|
54 | char_map[new_node] = 'e'; |
---|
55 | |
---|
56 | // Here we add the first edge... |
---|
57 | graph.addEdge( from_node, new_node ); |
---|
58 | |
---|
59 | // ... and we add some more nodes and edges to the graph |
---|
60 | from_node = new_node; |
---|
61 | new_node = graph.addNode(); |
---|
62 | char_map[new_node] = 'l'; |
---|
63 | graph.addEdge( from_node, new_node ); |
---|
64 | |
---|
65 | from_node = new_node; |
---|
66 | new_node = graph.addNode(); |
---|
67 | char_map[new_node] = 'l'; |
---|
68 | graph.addEdge( from_node, new_node ); |
---|
69 | |
---|
70 | from_node = new_node; |
---|
71 | new_node = graph.addNode(); |
---|
72 | char_map[new_node] = 'o'; |
---|
73 | graph.addEdge( from_node, new_node ); |
---|
74 | |
---|
75 | from_node = new_node; |
---|
76 | new_node = graph.addNode(); |
---|
77 | char_map[new_node] = ' '; |
---|
78 | graph.addEdge( from_node, new_node ); |
---|
79 | |
---|
80 | from_node = new_node; |
---|
81 | new_node = graph.addNode(); |
---|
82 | char_map[new_node] = 'W'; |
---|
83 | graph.addEdge( from_node, new_node ); |
---|
84 | |
---|
85 | from_node = new_node; |
---|
86 | new_node = graph.addNode(); |
---|
87 | char_map[new_node] = 'o'; |
---|
88 | graph.addEdge( from_node, new_node ); |
---|
89 | |
---|
90 | from_node = new_node; |
---|
91 | new_node = graph.addNode(); |
---|
92 | char_map[new_node] = 'r'; |
---|
93 | graph.addEdge( from_node, new_node ); |
---|
94 | |
---|
95 | from_node = new_node; |
---|
96 | new_node = graph.addNode(); |
---|
97 | char_map[new_node] = 'l'; |
---|
98 | graph.addEdge( from_node, new_node ); |
---|
99 | |
---|
100 | from_node = new_node; |
---|
101 | new_node = graph.addNode(); |
---|
102 | char_map[new_node] = 'd'; |
---|
103 | graph.addEdge( from_node, new_node ); |
---|
104 | |
---|
105 | from_node = new_node; |
---|
106 | new_node = graph.addNode(); |
---|
107 | char_map[new_node] = '\n'; |
---|
108 | graph.addEdge( from_node, new_node ); |
---|
109 | |
---|
110 | |
---|
111 | // iterating |
---|
112 | Node current_node = start_node; |
---|
113 | while( current_node != INVALID ) |
---|
114 | { |
---|
115 | std::cout << char_map[current_node] << std::flush; |
---|
116 | |
---|
117 | ListGraph::OutEdgeIt edge(graph, current_node); |
---|
118 | if( edge != INVALID ) |
---|
119 | current_node = graph.target( edge ); |
---|
120 | else |
---|
121 | current_node = INVALID; |
---|
122 | } |
---|
123 | |
---|
124 | return 0; |
---|
125 | } |
---|