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