Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

hello_lemon.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++ -*-
 * demo/hello_lemon.cc - Part of LEMON, a generic C++ optimization library
 *
 * Copyright (C) 2005 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>

int main()
{
  typedef lemon::ListGraph Graph;
  typedef Graph::EdgeIt EdgeIt;
  typedef Graph::Edge Edge;
  typedef Graph::NodeIt NodeIt;
  typedef Graph::Node Node;
  typedef Graph::EdgeMap<int> LengthMap;
  using lemon::INVALID;

  Graph g;
  
  Node s=g.addNode();
  Node v2=g.addNode();
  Node v3=g.addNode();
  Node v4=g.addNode();
  Node v5=g.addNode();
  Node t=g.addNode();

  Edge s_v2=g.addEdge(s, v2);
  Edge s_v3=g.addEdge(s, v3);
  Edge v2_v4=g.addEdge(v2, v4);
  Edge v2_v5=g.addEdge(v2, v5);
  Edge v3_v5=g.addEdge(v3, v5);
  Edge v4_t=g.addEdge(v4, t);
  Edge v5_t=g.addEdge(v5, t);
  
  LengthMap length(g);

  length.set(s_v2, 10);
  length.set(s_v3, 10);
  length.set(v2_v4, 5);
  length.set(v2_v5, 8);
  length.set(v3_v5, 5);
  length.set(v4_t, 8);
  length.set(v5_t, 8);

  std::cout << "Hello World!" << std::endl;
  std::cout <<  std::endl;
  std::cout << "This is library LEMON here! We have a graph!" << std::endl;
  std::cout <<  std::endl;

  std::cout << "Nodes:";
  for (NodeIt i(g); i!=INVALID; ++i)
    std::cout << " " << g.id(i);
  std::cout << std::endl;

  std::cout << "Edges:";
  for (EdgeIt i(g); i!=INVALID; ++i)
    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
  std::cout << std::endl;
  std::cout <<  std::endl;

  std::cout << "There is a map on the edges (length)!" << std::endl;
  std::cout <<  std::endl;
  for (EdgeIt i(g); i!=INVALID; ++i)
    std::cout << "length(" << g.id(g.source(i)) << ","
              << g.id(g.target(i)) << ")="<<length[i]<<std::endl;

  std::cout << std::endl;

}

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


Generated on Sat Aug 27 14:14:55 2005 for LEMON by  doxygen 1.4.4