alpar@2195
|
1 |
/* -*- C++ -*-
|
alpar@2195
|
2 |
*
|
alpar@2195
|
3 |
* This file is a part of LEMON, a generic C++ optimization library
|
alpar@2195
|
4 |
*
|
alpar@2553
|
5 |
* Copyright (C) 2003-2008
|
alpar@2195
|
6 |
* Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
|
alpar@2195
|
7 |
* (Egervary Research Group on Combinatorial Optimization, EGRES).
|
alpar@2195
|
8 |
*
|
alpar@2195
|
9 |
* Permission to use, modify and distribute this software is granted
|
alpar@2195
|
10 |
* provided that this copyright notice appears in all copies. For
|
alpar@2195
|
11 |
* precise terms see the accompanying LICENSE file.
|
alpar@2195
|
12 |
*
|
alpar@2195
|
13 |
* This software is provided "AS IS" with no warranty of any kind,
|
alpar@2195
|
14 |
* express or implied, and with no claim as to its suitability for any
|
alpar@2195
|
15 |
* purpose.
|
alpar@2195
|
16 |
*
|
alpar@2195
|
17 |
*/
|
alpar@2195
|
18 |
|
alpar@2195
|
19 |
///\ingroup demos
|
alpar@2195
|
20 |
///\file
|
alpar@2195
|
21 |
///\brief LEMON style "Hello World!" program
|
alpar@2195
|
22 |
///
|
alpar@2195
|
23 |
/// This program is intended to be a "Hello World!" program that shows
|
alpar@2195
|
24 |
/// the very basic notions of the LEMON library: \ref graphs "graphs" and
|
alpar@2195
|
25 |
/// \ref maps-page "maps". Click on the links to read more about these.
|
alpar@2195
|
26 |
///
|
alpar@2408
|
27 |
/// \include hello_world.cc
|
alpar@2195
|
28 |
|
alpar@2195
|
29 |
#include <iostream>
|
alpar@2195
|
30 |
#include <lemon/list_graph.h>
|
alpar@2195
|
31 |
|
alpar@2195
|
32 |
using namespace lemon;
|
alpar@2195
|
33 |
|
alpar@2195
|
34 |
typedef ListGraph::Node Node;
|
alpar@2195
|
35 |
typedef ListGraph::Edge Edge;
|
alpar@2195
|
36 |
|
alpar@2195
|
37 |
|
alpar@2209
|
38 |
int main()
|
alpar@2195
|
39 |
{
|
alpar@2195
|
40 |
// Declare the graph itself and a NodeMap, witch will store the characters
|
alpar@2195
|
41 |
// assigned to the nodes
|
alpar@2195
|
42 |
ListGraph graph;
|
alpar@2195
|
43 |
ListGraph::NodeMap<char> char_map(graph);
|
alpar@2195
|
44 |
|
alpar@2195
|
45 |
// Add nodes
|
alpar@2195
|
46 |
Node new_node = graph.addNode();
|
alpar@2195
|
47 |
char_map[new_node] = 'H';
|
alpar@2195
|
48 |
|
alpar@2195
|
49 |
// Store the start node
|
alpar@2195
|
50 |
Node start_node = new_node;
|
alpar@2195
|
51 |
|
alpar@2195
|
52 |
Node from_node = new_node;
|
alpar@2195
|
53 |
new_node = graph.addNode();
|
alpar@2195
|
54 |
char_map[new_node] = 'e';
|
alpar@2195
|
55 |
|
alpar@2195
|
56 |
// Here we add the first edge...
|
alpar@2195
|
57 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
58 |
|
alpar@2195
|
59 |
// ... and we add some more nodes and edges to the graph
|
alpar@2195
|
60 |
from_node = new_node;
|
alpar@2195
|
61 |
new_node = graph.addNode();
|
alpar@2195
|
62 |
char_map[new_node] = 'l';
|
alpar@2195
|
63 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
64 |
|
alpar@2195
|
65 |
from_node = new_node;
|
alpar@2195
|
66 |
new_node = graph.addNode();
|
alpar@2195
|
67 |
char_map[new_node] = 'l';
|
alpar@2195
|
68 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
69 |
|
alpar@2195
|
70 |
from_node = new_node;
|
alpar@2195
|
71 |
new_node = graph.addNode();
|
alpar@2195
|
72 |
char_map[new_node] = 'o';
|
alpar@2195
|
73 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
74 |
|
alpar@2195
|
75 |
from_node = new_node;
|
alpar@2195
|
76 |
new_node = graph.addNode();
|
alpar@2195
|
77 |
char_map[new_node] = ' ';
|
alpar@2195
|
78 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
79 |
|
alpar@2195
|
80 |
from_node = new_node;
|
alpar@2195
|
81 |
new_node = graph.addNode();
|
alpar@2195
|
82 |
char_map[new_node] = 'W';
|
alpar@2195
|
83 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
84 |
|
alpar@2195
|
85 |
from_node = new_node;
|
alpar@2195
|
86 |
new_node = graph.addNode();
|
alpar@2195
|
87 |
char_map[new_node] = 'o';
|
alpar@2195
|
88 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
89 |
|
alpar@2195
|
90 |
from_node = new_node;
|
alpar@2195
|
91 |
new_node = graph.addNode();
|
alpar@2195
|
92 |
char_map[new_node] = 'r';
|
alpar@2195
|
93 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
94 |
|
alpar@2195
|
95 |
from_node = new_node;
|
alpar@2195
|
96 |
new_node = graph.addNode();
|
alpar@2195
|
97 |
char_map[new_node] = 'l';
|
alpar@2195
|
98 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
99 |
|
alpar@2195
|
100 |
from_node = new_node;
|
alpar@2195
|
101 |
new_node = graph.addNode();
|
alpar@2195
|
102 |
char_map[new_node] = 'd';
|
alpar@2195
|
103 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
104 |
|
alpar@2195
|
105 |
from_node = new_node;
|
alpar@2195
|
106 |
new_node = graph.addNode();
|
alpar@2195
|
107 |
char_map[new_node] = '\n';
|
alpar@2195
|
108 |
graph.addEdge( from_node, new_node );
|
alpar@2195
|
109 |
|
alpar@2195
|
110 |
|
alpar@2195
|
111 |
// iterating
|
alpar@2195
|
112 |
Node current_node = start_node;
|
alpar@2195
|
113 |
while( current_node != INVALID )
|
alpar@2195
|
114 |
{
|
alpar@2195
|
115 |
std::cout << char_map[current_node] << std::flush;
|
alpar@2195
|
116 |
|
alpar@2195
|
117 |
ListGraph::OutEdgeIt edge(graph, current_node);
|
alpar@2195
|
118 |
if( edge != INVALID )
|
alpar@2195
|
119 |
current_node = graph.target( edge );
|
alpar@2195
|
120 |
else
|
alpar@2195
|
121 |
current_node = INVALID;
|
alpar@2195
|
122 |
}
|
alpar@2195
|
123 |
|
alpar@2195
|
124 |
return 0;
|
alpar@2195
|
125 |
}
|