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