| 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 | |
|---|
| 30 | int 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.set(s_v2, 10); |
|---|
| 60 | length.set(s_v3, 10); |
|---|
| 61 | length.set(v2_v4, 5); |
|---|
| 62 | length.set(v2_v5, 8); |
|---|
| 63 | length.set(v3_v5, 5); |
|---|
| 64 | length.set(v4_t, 8); |
|---|
| 65 | length.set(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 | } |
|---|