demo/hello_lemon.cc
author deba
Fri, 14 Oct 2005 10:52:15 +0000
changeset 1721 c0f5e8401373
parent 1636 260ac104190f
child 1875 98698b69a902
permissions -rw-r--r--
Named parameter for heap and cross ref
It needs some redesign
athos@1583
     1
/* -*- C++ -*-
ladanyi@1636
     2
 * demo/hello_lemon.cc - Part of LEMON, a generic C++ optimization library
athos@1583
     3
 *
athos@1583
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
athos@1583
     5
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
athos@1583
     6
 *
athos@1583
     7
 * Permission to use, modify and distribute this software is granted
athos@1583
     8
 * provided that this copyright notice appears in all copies. For
athos@1583
     9
 * precise terms see the accompanying LICENSE file.
athos@1583
    10
 *
athos@1583
    11
 * This software is provided "AS IS" with no warranty of any kind,
athos@1583
    12
 * express or implied, and with no claim as to its suitability for any
athos@1583
    13
 * purpose.
athos@1583
    14
 *
athos@1583
    15
 */
athos@1583
    16
athos@1583
    17
///\ingroup demos
athos@1583
    18
///\file
athos@1583
    19
///\brief LEMON style "Hello World!" program
athos@1583
    20
///
athos@1583
    21
/// This program is intended to be a "Hello World!" program that shows
athos@1583
    22
/// the very basic notions of the LEMON library: \ref graphs "graphs" and
athos@1583
    23
/// \ref maps-page "maps". Click on the links to read more about these.
alpar@1641
    24
///
alpar@1641
    25
/// \include hello_lemon.cc
athos@1583
    26
klao@1520
    27
#include <iostream>
klao@1520
    28
#include <lemon/list_graph.h>
klao@1520
    29
klao@1520
    30
int main()
klao@1520
    31
{
klao@1520
    32
  typedef lemon::ListGraph Graph;
klao@1520
    33
  typedef Graph::EdgeIt EdgeIt;
athos@1530
    34
  typedef Graph::Edge Edge;
klao@1520
    35
  typedef Graph::NodeIt NodeIt;
athos@1530
    36
  typedef Graph::Node Node;
athos@1530
    37
  typedef Graph::EdgeMap<int> LengthMap;
klao@1520
    38
  using lemon::INVALID;
klao@1520
    39
klao@1520
    40
  Graph g;
klao@1520
    41
  
athos@1530
    42
  Node s=g.addNode();
athos@1530
    43
  Node v2=g.addNode();
athos@1530
    44
  Node v3=g.addNode();
athos@1530
    45
  Node v4=g.addNode();
athos@1530
    46
  Node v5=g.addNode();
athos@1530
    47
  Node t=g.addNode();
athos@1530
    48
athos@1530
    49
  Edge s_v2=g.addEdge(s, v2);
athos@1530
    50
  Edge s_v3=g.addEdge(s, v3);
athos@1530
    51
  Edge v2_v4=g.addEdge(v2, v4);
athos@1530
    52
  Edge v2_v5=g.addEdge(v2, v5);
athos@1530
    53
  Edge v3_v5=g.addEdge(v3, v5);
athos@1530
    54
  Edge v4_t=g.addEdge(v4, t);
athos@1530
    55
  Edge v5_t=g.addEdge(v5, t);
klao@1520
    56
  
athos@1530
    57
  LengthMap length(g);
athos@1530
    58
athos@1530
    59
  length.set(s_v2, 10);
athos@1530
    60
  length.set(s_v3, 10);
athos@1530
    61
  length.set(v2_v4, 5);
athos@1530
    62
  length.set(v2_v5, 8);
athos@1530
    63
  length.set(v3_v5, 5);
athos@1530
    64
  length.set(v4_t, 8);
athos@1530
    65
  length.set(v5_t, 8);
klao@1520
    66
athos@1526
    67
  std::cout << "Hello World!" << std::endl;
athos@1526
    68
  std::cout <<  std::endl;
athos@1526
    69
  std::cout << "This is library LEMON here! We have a graph!" << std::endl;
athos@1526
    70
  std::cout <<  std::endl;
athos@1526
    71
klao@1520
    72
  std::cout << "Nodes:";
klao@1520
    73
  for (NodeIt i(g); i!=INVALID; ++i)
klao@1520
    74
    std::cout << " " << g.id(i);
klao@1520
    75
  std::cout << std::endl;
klao@1520
    76
klao@1520
    77
  std::cout << "Edges:";
klao@1520
    78
  for (EdgeIt i(g); i!=INVALID; ++i)
klao@1520
    79
    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
klao@1520
    80
  std::cout << std::endl;
athos@1530
    81
  std::cout <<  std::endl;
athos@1530
    82
athos@1530
    83
  std::cout << "There is a map on the edges (length)!" << std::endl;
athos@1530
    84
  std::cout <<  std::endl;
athos@1530
    85
  for (EdgeIt i(g); i!=INVALID; ++i)
alpar@1641
    86
    std::cout << "length(" << g.id(g.source(i)) << ","
alpar@1641
    87
	      << g.id(g.target(i)) << ")="<<length[i]<<std::endl;
athos@1530
    88
athos@1530
    89
  std::cout << std::endl;
athos@1530
    90
klao@1520
    91
}