1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/demo/hello_world.cc Mon Sep 04 19:48:09 2006 +0000
1.3 @@ -0,0 +1,125 @@
1.4 +/* -*- C++ -*-
1.5 + *
1.6 + * This file is a part of LEMON, a generic C++ optimization library
1.7 + *
1.8 + * Copyright (C) 2003-2006
1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
1.11 + *
1.12 + * Permission to use, modify and distribute this software is granted
1.13 + * provided that this copyright notice appears in all copies. For
1.14 + * precise terms see the accompanying LICENSE file.
1.15 + *
1.16 + * This software is provided "AS IS" with no warranty of any kind,
1.17 + * express or implied, and with no claim as to its suitability for any
1.18 + * purpose.
1.19 + *
1.20 + */
1.21 +
1.22 +///\ingroup demos
1.23 +///\file
1.24 +///\brief LEMON style "Hello World!" program
1.25 +///
1.26 +/// This program is intended to be a "Hello World!" program that shows
1.27 +/// the very basic notions of the LEMON library: \ref graphs "graphs" and
1.28 +/// \ref maps-page "maps". Click on the links to read more about these.
1.29 +///
1.30 +/// \include hello_lemon.cc
1.31 +
1.32 +#include <iostream>
1.33 +#include <lemon/list_graph.h>
1.34 +
1.35 +using namespace lemon;
1.36 +
1.37 +typedef ListGraph::Node Node;
1.38 +typedef ListGraph::Edge Edge;
1.39 +
1.40 +
1.41 +int main( int argc, char *argv[] )
1.42 +{
1.43 + // Declare the graph itself and a NodeMap, witch will store the characters
1.44 + // assigned to the nodes
1.45 + ListGraph graph;
1.46 + ListGraph::NodeMap<char> char_map(graph);
1.47 +
1.48 + // Add nodes
1.49 + Node new_node = graph.addNode();
1.50 + char_map[new_node] = 'H';
1.51 +
1.52 + // Store the start node
1.53 + Node start_node = new_node;
1.54 +
1.55 + Node from_node = new_node;
1.56 + new_node = graph.addNode();
1.57 + char_map[new_node] = 'e';
1.58 +
1.59 + // Here we add the first edge...
1.60 + graph.addEdge( from_node, new_node );
1.61 +
1.62 + // ... and we add some more nodes and edges to the graph
1.63 + from_node = new_node;
1.64 + new_node = graph.addNode();
1.65 + char_map[new_node] = 'l';
1.66 + graph.addEdge( from_node, new_node );
1.67 +
1.68 + from_node = new_node;
1.69 + new_node = graph.addNode();
1.70 + char_map[new_node] = 'l';
1.71 + graph.addEdge( from_node, new_node );
1.72 +
1.73 + from_node = new_node;
1.74 + new_node = graph.addNode();
1.75 + char_map[new_node] = 'o';
1.76 + graph.addEdge( from_node, new_node );
1.77 +
1.78 + from_node = new_node;
1.79 + new_node = graph.addNode();
1.80 + char_map[new_node] = ' ';
1.81 + graph.addEdge( from_node, new_node );
1.82 +
1.83 + from_node = new_node;
1.84 + new_node = graph.addNode();
1.85 + char_map[new_node] = 'W';
1.86 + graph.addEdge( from_node, new_node );
1.87 +
1.88 + from_node = new_node;
1.89 + new_node = graph.addNode();
1.90 + char_map[new_node] = 'o';
1.91 + graph.addEdge( from_node, new_node );
1.92 +
1.93 + from_node = new_node;
1.94 + new_node = graph.addNode();
1.95 + char_map[new_node] = 'r';
1.96 + graph.addEdge( from_node, new_node );
1.97 +
1.98 + from_node = new_node;
1.99 + new_node = graph.addNode();
1.100 + char_map[new_node] = 'l';
1.101 + graph.addEdge( from_node, new_node );
1.102 +
1.103 + from_node = new_node;
1.104 + new_node = graph.addNode();
1.105 + char_map[new_node] = 'd';
1.106 + graph.addEdge( from_node, new_node );
1.107 +
1.108 + from_node = new_node;
1.109 + new_node = graph.addNode();
1.110 + char_map[new_node] = '\n';
1.111 + graph.addEdge( from_node, new_node );
1.112 +
1.113 +
1.114 + // iterating
1.115 + Node current_node = start_node;
1.116 + while( current_node != INVALID )
1.117 + {
1.118 + std::cout << char_map[current_node] << std::flush;
1.119 +
1.120 + ListGraph::OutEdgeIt edge(graph, current_node);
1.121 + if( edge != INVALID )
1.122 + current_node = graph.target( edge );
1.123 + else
1.124 + current_node = INVALID;
1.125 + }
1.126 +
1.127 + return 0;
1.128 +}