COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/deba/iterator_test.cpp @ 1272:17be4c5bc6c6

Last change on this file since 1272:17be4c5bc6c6 was 1267:a93f94dbe3d3, checked in by Balazs Dezso, 20 years ago

First version of iterable maps.

File size: 2.6 KB
Line 
1#include <iostream>
2#include <algorithm>
3#include <iterator>
4#include <functional>
5#include <lemon/list_graph.h>
6#include <lemon/map_iterator.h>
7#include <lemon/graph_reader.h>
8#include <lemon/maps.h>
9
10using namespace std;
11using namespace lemon;
12
13template <typename F, typename G>
14struct unary_compose {
15  typedef typename G::argument_type argument_type;
16  typedef typename F::result_type result_type;
17 
18  unary_compose(const F& _f, const G& _g) : f(_f), g(_g) {}
19
20  result_type operator()(const argument_type& x) {
21    return f(g(x));
22  }
23
24private:
25  F f;
26  G g;
27};
28
29template <typename F, typename G>
30unary_compose<F, G> compose1(const F& f, const G& g) {
31  return unary_compose<F, G>(f, g);
32}
33
34
35
36
37template <typename T>
38struct Second {
39  typedef T argument_type;
40  typedef typename T::second_type result_type;
41
42  typename T::second_type operator()(const T& t) const {
43    return t.second;
44  }
45};
46
47template <typename T>
48struct First {
49  typedef T argument_type;
50  typedef typename T::first_type result_type;
51  typename T::first_type operator()(const T& t) const {
52    return t.first;
53  }
54};
55
56
57int main() {
58
59  typedef ListGraph Graph;
60
61  typedef Graph::Edge Edge;
62  typedef Graph::Node Node;
63  typedef Graph::EdgeIt EdgeIt;
64  typedef Graph::NodeIt NodeIt;
65  typedef Graph::EdgeMap<int> LengthMap;
66
67  typedef IdMap<Graph, Edge> EdgeIdMap;
68
69  Graph graph;
70  LengthMap length(graph);
71
72  readGraph(std::cin, graph, length);
73
74  const LengthMap& constLength = length;
75
76  copy(length.valueSet().begin(), length.valueSet().end(),
77       ostream_iterator<int>(cout, " "));
78  cout << endl;
79
80
81  copy(constLength.valueSet().begin(), constLength.valueSet().end(),
82       ostream_iterator<int>(cout, " "));
83  cout << endl;
84
85
86  transform(constLength.keySet().begin(), constLength.keySet().end(),
87            ostream_iterator<int>(cout, " "),
88            MapFunctor<EdgeIdMap>(EdgeIdMap(graph)));
89  cout << endl;
90
91
92  transform(constLength.mapSet().begin(), constLength.mapSet().end(),
93            ostream_iterator<int>(cout, " "),
94            Second<LengthMap::MapSet::Value>());
95  cout << endl;
96
97  transform(constLength.mapSet().begin(), constLength.mapSet().end(),
98            ostream_iterator<int>(cout, " "),
99            compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)),
100                     First<LengthMap::MapSet::Value>() ));
101  cout << endl;
102
103  transform(length.mapSet().begin(), length.mapSet().end(),
104            ostream_iterator<int>(cout, " "),
105            Second<LengthMap::MapSet::Value>());
106  cout << endl;
107
108  transform(length.mapSet().begin(), length.mapSet().end(),
109            ostream_iterator<int>(cout, " "),
110            compose1(MapFunctor<EdgeIdMap>(EdgeIdMap(graph)),
111                     First<LengthMap::MapSet::Value>() ));
112  cout << endl;
113
114  return 0;
115}
Note: See TracBrowser for help on using the repository browser.