COIN-OR::LEMON - Graph Library

source: lemon-0.x/demo/hello_lemon.cc @ 1928:2e957d67d7b9

Last change on this file since 1928:2e957d67d7b9 was 1928:2e957d67d7b9, checked in by Alpar Juttner, 14 years ago

Use [] instead of set().

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