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