/* -*- C++ -*- * * This file is a part of LEMON, a generic C++ optimization library * * Copyright (C) 2003-2006 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * * Permission to use, modify and distribute this software is granted * provided that this copyright notice appears in all copies. For * precise terms see the accompanying LICENSE file. * * This software is provided "AS IS" with no warranty of any kind, * express or implied, and with no claim as to its suitability for any * purpose. * */ ///\ingroup demos ///\file ///\brief LEMON style "Hello World!" program /// /// This program is intended to be a "Hello World!" program that shows /// the very basic notions of the LEMON library: \ref graphs "graphs" and /// \ref maps-page "maps". Click on the links to read more about these. /// /// \include hello_lemon.cc #include #include using namespace lemon; typedef ListGraph::Node Node; typedef ListGraph::Edge Edge; int main() { // Declare the graph itself and a NodeMap, witch will store the characters // assigned to the nodes ListGraph graph; ListGraph::NodeMap char_map(graph); // Add nodes Node new_node = graph.addNode(); char_map[new_node] = 'H'; // Store the start node Node start_node = new_node; Node from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'e'; // Here we add the first edge... graph.addEdge( from_node, new_node ); // ... and we add some more nodes and edges to the graph from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'l'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'l'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'o'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = ' '; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'W'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'o'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'r'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'l'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = 'd'; graph.addEdge( from_node, new_node ); from_node = new_node; new_node = graph.addNode(); char_map[new_node] = '\n'; graph.addEdge( from_node, new_node ); // iterating Node current_node = start_node; while( current_node != INVALID ) { std::cout << char_map[current_node] << std::flush; ListGraph::OutEdgeIt edge(graph, current_node); if( edge != INVALID ) current_node = graph.target( edge ); else current_node = INVALID; } return 0; }