beckerjc@150
|
1 |
#include <string>
|
beckerjc@150
|
2 |
#include <iostream>
|
beckerjc@150
|
3 |
#include <map>
|
beckerjc@246
|
4 |
#include <vector>
|
beckerjc@150
|
5 |
|
beckerjc@150
|
6 |
#include <kruskal.h>
|
alpar@737
|
7 |
#include <hugo/list_graph.h>
|
beckerjc@150
|
8 |
|
beckerjc@150
|
9 |
|
beckerjc@150
|
10 |
using namespace std;
|
beckerjc@150
|
11 |
using namespace hugo;
|
beckerjc@150
|
12 |
|
beckerjc@150
|
13 |
class string_int_map : public map<string,int> {
|
beckerjc@150
|
14 |
public:
|
beckerjc@150
|
15 |
int get(const string &s) {
|
beckerjc@150
|
16 |
// Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy
|
beckerjc@150
|
17 |
// hogy is mukodik ez a map :)
|
beckerjc@150
|
18 |
if( count(s) == 0 ) {
|
beckerjc@150
|
19 |
operator[](s) = -1;
|
beckerjc@150
|
20 |
}
|
beckerjc@150
|
21 |
return operator[](s);
|
beckerjc@150
|
22 |
}
|
beckerjc@150
|
23 |
void set(const string &s, int i) {
|
beckerjc@150
|
24 |
operator[](s) = i;
|
beckerjc@150
|
25 |
}
|
beckerjc@150
|
26 |
};
|
beckerjc@150
|
27 |
|
beckerjc@150
|
28 |
|
beckerjc@218
|
29 |
// Egy olyan "map", ami nem tud semmit, csak a typedef-eket.
|
beckerjc@218
|
30 |
// Valami elegansabb megoldas kene a Kruskalban...
|
beckerjc@218
|
31 |
|
beckerjc@218
|
32 |
template <typename K, typename V>
|
beckerjc@218
|
33 |
class DummyMap {
|
beckerjc@218
|
34 |
public:
|
beckerjc@218
|
35 |
typedef K KeyType;
|
beckerjc@218
|
36 |
typedef V ValueType;
|
beckerjc@218
|
37 |
};
|
beckerjc@218
|
38 |
|
beckerjc@150
|
39 |
int main() {
|
beckerjc@150
|
40 |
|
beckerjc@218
|
41 |
typedef ListGraph::Node Node;
|
beckerjc@218
|
42 |
typedef ListGraph::Edge Edge;
|
beckerjc@150
|
43 |
typedef ListGraph::NodeIt NodeIt;
|
beckerjc@150
|
44 |
typedef ListGraph::EdgeIt EdgeIt;
|
beckerjc@150
|
45 |
|
beckerjc@150
|
46 |
ListGraph G;
|
beckerjc@150
|
47 |
|
beckerjc@218
|
48 |
Node s=G.addNode();
|
beckerjc@218
|
49 |
Node v1=G.addNode();
|
beckerjc@218
|
50 |
Node v2=G.addNode();
|
beckerjc@218
|
51 |
Node v3=G.addNode();
|
beckerjc@218
|
52 |
Node v4=G.addNode();
|
beckerjc@218
|
53 |
Node t=G.addNode();
|
beckerjc@150
|
54 |
|
beckerjc@218
|
55 |
Edge e1 = G.addEdge(s, v1);
|
beckerjc@218
|
56 |
Edge e2 = G.addEdge(s, v2);
|
beckerjc@218
|
57 |
Edge e3 = G.addEdge(v1, v2);
|
beckerjc@218
|
58 |
Edge e4 = G.addEdge(v2, v1);
|
beckerjc@218
|
59 |
Edge e5 = G.addEdge(v1, v3);
|
beckerjc@218
|
60 |
Edge e6 = G.addEdge(v3, v2);
|
beckerjc@218
|
61 |
Edge e7 = G.addEdge(v2, v4);
|
beckerjc@218
|
62 |
Edge e8 = G.addEdge(v4, v3);
|
beckerjc@218
|
63 |
Edge e9 = G.addEdge(v3, t);
|
beckerjc@218
|
64 |
Edge e10 = G.addEdge(v4, t);
|
beckerjc@150
|
65 |
|
beckerjc@218
|
66 |
typedef ListGraph::EdgeMap<double> ECostMap;
|
beckerjc@218
|
67 |
typedef ListGraph::EdgeMap<bool> EBoolMap;
|
beckerjc@218
|
68 |
|
beckerjc@218
|
69 |
ECostMap edge_cost_map(G, 2);
|
beckerjc@218
|
70 |
EBoolMap tree_map(G);
|
beckerjc@150
|
71 |
|
beckerjc@150
|
72 |
|
beckerjc@246
|
73 |
cout << "Uniform 2-es koltseggel: "
|
alpar@737
|
74 |
<< kruskalEdgeMap(G, edge_cost_map, tree_map)
|
beckerjc@246
|
75 |
<< endl;
|
beckerjc@218
|
76 |
|
beckerjc@218
|
77 |
|
beckerjc@246
|
78 |
edge_cost_map.set(e1, -10);
|
beckerjc@246
|
79 |
edge_cost_map.set(e2, -9);
|
beckerjc@246
|
80 |
edge_cost_map.set(e3, -8);
|
beckerjc@246
|
81 |
edge_cost_map.set(e4, -7);
|
beckerjc@246
|
82 |
edge_cost_map.set(e5, -6);
|
beckerjc@246
|
83 |
edge_cost_map.set(e6, -5);
|
beckerjc@246
|
84 |
edge_cost_map.set(e7, -4);
|
beckerjc@246
|
85 |
edge_cost_map.set(e8, -3);
|
beckerjc@246
|
86 |
edge_cost_map.set(e9, -2);
|
beckerjc@246
|
87 |
edge_cost_map.set(e10, -1);
|
beckerjc@218
|
88 |
|
beckerjc@246
|
89 |
vector<Edge> tree_edge_vec;
|
beckerjc@246
|
90 |
|
beckerjc@246
|
91 |
cout << "Nemkonst koltseggel (-31): "
|
alpar@737
|
92 |
<< kruskalEdgeMap_IteratorOut(G, edge_cost_map,
|
alpar@737
|
93 |
back_inserter(tree_edge_vec))
|
beckerjc@246
|
94 |
<< endl;
|
beckerjc@246
|
95 |
|
beckerjc@246
|
96 |
int i = 1;
|
beckerjc@246
|
97 |
for(vector<Edge>::iterator e = tree_edge_vec.begin();
|
beckerjc@246
|
98 |
e != tree_edge_vec.end(); ++e, ++i) {
|
alpar@737
|
99 |
cout << i << ". el: " << G.id(*e) << endl;
|
beckerjc@246
|
100 |
}
|
beckerjc@246
|
101 |
|
beckerjc@349
|
102 |
tree_edge_vec.clear();
|
beckerjc@352
|
103 |
// SequenceOutput< back_insert_iterator< vector<Edge> > >
|
beckerjc@352
|
104 |
// vec_filler(back_inserter(tree_edge_vec));
|
beckerjc@352
|
105 |
// cout << "Nemkonst koltseggel tarhatekonyabban: "
|
beckerjc@352
|
106 |
// << Kruskal(G,
|
beckerjc@352
|
107 |
// KruskalMapVec<ECostMap>(G, edge_cost_map),
|
beckerjc@352
|
108 |
// vec_filler)
|
beckerjc@352
|
109 |
// << endl;
|
beckerjc@349
|
110 |
|
alpar@737
|
111 |
// cout << "Nemkonst koltseggel tarhatekonyabban: "
|
alpar@737
|
112 |
// << kruskal(G,
|
alpar@737
|
113 |
// KruskalMapVec<ECostMap>(G, edge_cost_map),
|
alpar@737
|
114 |
// makeSequenceOutput(back_inserter(tree_edge_vec))
|
alpar@737
|
115 |
// )
|
alpar@737
|
116 |
// << endl;
|
beckerjc@349
|
117 |
|
alpar@737
|
118 |
// i = 1;
|
alpar@737
|
119 |
// for(vector<Edge>::iterator e = tree_edge_vec.begin();
|
alpar@737
|
120 |
// e != tree_edge_vec.end(); ++e, ++i) {
|
alpar@737
|
121 |
// cout << i << ". el: " << *e << endl;
|
alpar@737
|
122 |
// }
|
alpar@737
|
123 |
|
alpar@737
|
124 |
// **********************************************************************
|
beckerjc@246
|
125 |
|
beckerjc@246
|
126 |
// typedef MinCostTreeKruskal<ListGraph, ECostMap, EBoolMap> MCTK;
|
beckerjc@246
|
127 |
|
beckerjc@246
|
128 |
// MCTK mctk(G, edge_cost_map, tree_map);
|
beckerjc@246
|
129 |
// double k0lts = mctk.run();
|
beckerjc@246
|
130 |
|
beckerjc@246
|
131 |
// cout << "Uniform 2-es koltseggel: " << k0lts << endl;
|
beckerjc@246
|
132 |
|
beckerjc@246
|
133 |
// // Max koltsegu fa szamitasa elore megrendezett koltseg vektorbol:
|
beckerjc@246
|
134 |
// typedef MinCostTreeKruskal<ListGraph, DummyMap<Edge,int>, EBoolMap> MCTK2;
|
beckerjc@246
|
135 |
// MCTK2 mctk2(G, DummyMap<Edge,int>(), tree_map);
|
beckerjc@246
|
136 |
// MCTK2::EdgeCostVector ecv;
|
beckerjc@246
|
137 |
// ecv.push_back(make_pair(e1, 10));
|
beckerjc@246
|
138 |
// ecv.push_back(make_pair(e2, 9));
|
beckerjc@246
|
139 |
// ecv.push_back(make_pair(e3, 8));
|
beckerjc@246
|
140 |
// ecv.push_back(make_pair(e4, 7));
|
beckerjc@246
|
141 |
// ecv.push_back(make_pair(e5, 6));
|
beckerjc@246
|
142 |
// ecv.push_back(make_pair(e6, 5));
|
beckerjc@246
|
143 |
// ecv.push_back(make_pair(e7, 4));
|
beckerjc@246
|
144 |
// ecv.push_back(make_pair(e8, 3));
|
beckerjc@246
|
145 |
// ecv.push_back(make_pair(e9, 2));
|
beckerjc@246
|
146 |
// ecv.push_back(make_pair(e10, 1));
|
beckerjc@246
|
147 |
|
beckerjc@246
|
148 |
// k0lts = mctk2.run(ecv);
|
beckerjc@246
|
149 |
// cout << "Max koltsegu fa elore megrendezett koltseg vektorbol: 31 = "
|
beckerjc@246
|
150 |
// << k0lts << endl;
|
beckerjc@218
|
151 |
|
beckerjc@150
|
152 |
|
beckerjc@150
|
153 |
return 0;
|
beckerjc@150
|
154 |
}
|