hello_world.cc File Reference


Detailed Description

This program is intended to be a "Hello World!" program that shows the very basic notions of the LEMON library: graphs and maps. Click on the links to read more about these.

/* -*- C++ -*-
 *
 * This file is a part of LEMON, a generic C++ optimization library
 *
 * Copyright (C) 2003-2008
 * 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.
 *
 */


#include <iostream>
#include <lemon/list_graph.h>

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>  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;
}
#include <iostream>
#include <lemon/list_graph.h>

Generated on Thu Jun 4 04:03:09 2009 for LEMON by  doxygen 1.5.9