demo/hello_lemon.cc
author hegyi
Thu, 28 Jul 2005 15:54:00 +0000
changeset 1599 c2f95eac652b
parent 1530 d99c3c84f797
child 1636 260ac104190f
permissions -rw-r--r--
cout->cerr, node radius and edge width is now scaled, maps are editable by clicking on texts.
athos@1583
     1
/* -*- C++ -*-
athos@1583
     2
 * demo/lp_maxflow_demo.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.
athos@1583
    24
klao@1520
    25
#include <iostream>
klao@1520
    26
#include <lemon/list_graph.h>
klao@1520
    27
klao@1520
    28
int main()
klao@1520
    29
{
klao@1520
    30
  typedef lemon::ListGraph Graph;
klao@1520
    31
  typedef Graph::EdgeIt EdgeIt;
athos@1530
    32
  typedef Graph::Edge Edge;
klao@1520
    33
  typedef Graph::NodeIt NodeIt;
athos@1530
    34
  typedef Graph::Node Node;
athos@1530
    35
  typedef Graph::EdgeMap<int> LengthMap;
klao@1520
    36
  using lemon::INVALID;
klao@1520
    37
klao@1520
    38
  Graph g;
klao@1520
    39
  
athos@1530
    40
  Node s=g.addNode();
athos@1530
    41
  Node v2=g.addNode();
athos@1530
    42
  Node v3=g.addNode();
athos@1530
    43
  Node v4=g.addNode();
athos@1530
    44
  Node v5=g.addNode();
athos@1530
    45
  Node t=g.addNode();
athos@1530
    46
athos@1530
    47
  Edge s_v2=g.addEdge(s, v2);
athos@1530
    48
  Edge s_v3=g.addEdge(s, v3);
athos@1530
    49
  Edge v2_v4=g.addEdge(v2, v4);
athos@1530
    50
  Edge v2_v5=g.addEdge(v2, v5);
athos@1530
    51
  Edge v3_v5=g.addEdge(v3, v5);
athos@1530
    52
  Edge v4_t=g.addEdge(v4, t);
athos@1530
    53
  Edge v5_t=g.addEdge(v5, t);
klao@1520
    54
  
athos@1530
    55
  LengthMap length(g);
athos@1530
    56
athos@1530
    57
  length.set(s_v2, 10);
athos@1530
    58
  length.set(s_v3, 10);
athos@1530
    59
  length.set(v2_v4, 5);
athos@1530
    60
  length.set(v2_v5, 8);
athos@1530
    61
  length.set(v3_v5, 5);
athos@1530
    62
  length.set(v4_t, 8);
athos@1530
    63
  length.set(v5_t, 8);
klao@1520
    64
athos@1526
    65
  std::cout << "Hello World!" << std::endl;
athos@1526
    66
  std::cout <<  std::endl;
athos@1526
    67
  std::cout << "This is library LEMON here! We have a graph!" << std::endl;
athos@1526
    68
  std::cout <<  std::endl;
athos@1526
    69
klao@1520
    70
  std::cout << "Nodes:";
klao@1520
    71
  for (NodeIt i(g); i!=INVALID; ++i)
klao@1520
    72
    std::cout << " " << g.id(i);
klao@1520
    73
  std::cout << std::endl;
klao@1520
    74
klao@1520
    75
  std::cout << "Edges:";
klao@1520
    76
  for (EdgeIt i(g); i!=INVALID; ++i)
klao@1520
    77
    std::cout << " (" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")";
klao@1520
    78
  std::cout << std::endl;
athos@1530
    79
  std::cout <<  std::endl;
athos@1530
    80
athos@1530
    81
  std::cout << "There is a map on the edges (length)!" << std::endl;
athos@1530
    82
  std::cout <<  std::endl;
athos@1530
    83
  for (EdgeIt i(g); i!=INVALID; ++i)
athos@1530
    84
    std::cout << "length(" << g.id(g.source(i)) << "," << g.id(g.target(i)) << ")="<<length[i]<<std::endl;
athos@1530
    85
athos@1530
    86
  std::cout << std::endl;
athos@1530
    87
klao@1520
    88
}