forked from ISCASTEAM/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinTree_test.cpp
More file actions
51 lines (41 loc) · 1.31 KB
/
MinTree_test.cpp
File metadata and controls
51 lines (41 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include"EdgeWeightedGraph.h"
#include"LazyPrimMST.h"
#include"PrimMST.h"
#include"KruskalMST.h"
int main(){
EdgeWeightedGraph* G = new EdgeWeightedGraph("./data/tinyEWG.txt"); //tinyDAG无环有向图
//基础测试
cout<<G->getE()<<endl;
cout<<G->getV()<<endl;
cout<<G->degree(0)<<endl;
//最小生成树测试
//1.延时删除Prim算法
cout<<endl;
LazyPrimMST* mst = new LazyPrimMST(G);
queue<Edge> res = mst->getMST(G);
while(!res.empty()){
Edge e = res.front();
res.pop();
cout<<e.either()<<"-"<<e.other(e.either())<<" "<<e.getWeight()<<endl;
}
cout<<"min total_weight = "<<mst->getWeight()<<endl;
cout<<endl;
//2.即时删除Prim算法
PrimMST* pmst = new PrimMST(G);
vector<Edge> res2 = pmst->getMST(G);
for(Edge e:res2){
cout<<e.either()<<"-"<<e.other(e.either())<<" "<<e.getWeight()<<endl;
}
cout<<"min total_weight = "<<pmst->getWeight()<<endl;
cout<<endl;
//3.克鲁斯卡尔算法
KruskalMST* kmst = new KruskalMST(G);
queue<Edge> res3 = kmst->getRes();
while(!res3.empty()){
Edge e = res3.front();
res3.pop();
cout<<e.either()<<"-"<<e.other(e.either())<<" "<<e.getWeight()<<endl;
}
cout<<"min total_weight = "<<kmst->getWeight()<<endl;
return 0;
}