author | jacint |
Tue, 09 Mar 2004 15:53:19 +0000 | |
changeset 160 | f1a7005e9dff |
child 218 | 5964f1c64ca1 |
permissions | -rw-r--r-- |
1 #include <string>
2 #include <iostream>
3 #include <map>
5 #include <kruskal.h>
6 #include <list_graph.hh>
9 using namespace std;
10 using namespace hugo;
12 class string_int_map : public map<string,int> {
13 public:
14 int get(const string &s) {
15 // Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy
16 // hogy is mukodik ez a map :)
17 if( count(s) == 0 ) {
18 operator[](s) = -1;
19 }
20 return operator[](s);
21 }
22 void set(const string &s, int i) {
23 operator[](s) = i;
24 }
25 };
28 int main() {
30 typedef ListGraph::NodeIt NodeIt;
31 typedef ListGraph::EdgeIt EdgeIt;
32 typedef ListGraph::EachNodeIt EachNodeIt;
33 typedef ListGraph::EachEdgeIt EachEdgeIt;
35 ListGraph G;
37 NodeIt s=G.addNode();
38 NodeIt v1=G.addNode();
39 NodeIt v2=G.addNode();
40 NodeIt v3=G.addNode();
41 NodeIt v4=G.addNode();
42 NodeIt t=G.addNode();
44 G.addEdge(s, v1);
45 G.addEdge(s, v2);
46 G.addEdge(v1, v2);
47 G.addEdge(v2, v1);
48 G.addEdge(v1, v3);
49 G.addEdge(v3, v2);
50 G.addEdge(v2, v4);
51 G.addEdge(v4, v3);
52 G.addEdge(v3, t);
53 G.addEdge(v4, t);
55 ListGraph::EdgeMap<double> edge_cost_map(G, 2);
56 ListGraph::EdgeMap<bool> tree_map(G);
58 double k0lts = MinCostTreeKruskal(G, edge_cost_map, tree_map);
60 cout << k0lts << endl;
62 return 0;
63 }