-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
112 lines (80 loc) · 4.29 KB
/
Main.java
File metadata and controls
112 lines (80 loc) · 4.29 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
public class Main {
// 测试我们实现的两种Prim算法的性能差距
// 可以看出这一节使用索引堆实现的Prim算法优于上一小节的Lazy Prim算法
public static void main(String[] args) {
String filename1 = "testG1.txt";
int V1 = 8;
String filename2 = "testG2.txt";
int V2 = 250;
String filename3 = "testG3.txt";
int V3 = 1000;
String filename4 = "testG4.txt";
int V4 = 10000;
//String filename5 = "testG5.txt";
//int V5 = 1000000;
// 文件读取
SparseWeightedGraph<Double> g1 = new SparseWeightedGraph<Double>(V1, false);
ReadWeightedGraph readGraph1 = new ReadWeightedGraph(g1, filename1);
System.out.println( filename1 + " load successfully.");
SparseWeightedGraph<Double> g2 = new SparseWeightedGraph<Double>(V2, false);
ReadWeightedGraph readGraph2 = new ReadWeightedGraph(g2, filename2);
System.out.println( filename2 + " load successfully.");
SparseWeightedGraph<Double> g3 = new SparseWeightedGraph<Double>(V3, false);
ReadWeightedGraph readGraph3 = new ReadWeightedGraph(g3, filename3);
System.out.println( filename3 + " load successfully.");
SparseWeightedGraph<Double> g4 = new SparseWeightedGraph<Double>(V4, false);
ReadWeightedGraph readGraph4 = new ReadWeightedGraph(g4, filename4);
System.out.println( filename4 + " load successfully.");
// SparseWeightedGraph<Double> g5 = new SparseWeightedGraph<Double>(V5, false);
// ReadWeightedGraph readGraph5 = new ReadWeightedGraph(g5, filename5);
// System.out.println( filename5 + " load successfully.");
System.out.println();
long startTime, endTime;
// Test Lazy Prim MST
System.out.println("Test Lazy Prim MST:");
startTime = System.currentTimeMillis();
LazyPrimMST<Double> lazyPrimMST1 = new LazyPrimMST<Double>(g1);
endTime = System.currentTimeMillis();
System.out.println("Test for G1: " + (endTime-startTime) + "ms.");
startTime = System.currentTimeMillis();
LazyPrimMST<Double> lazyPrimMST2 = new LazyPrimMST<Double>(g2);
endTime = System.currentTimeMillis();
System.out.println("Test for G2: " + (endTime-startTime) + "ms.");
startTime = System.currentTimeMillis();
LazyPrimMST<Double> lazyPrimMST3 = new LazyPrimMST<Double>(g3);
endTime = System.currentTimeMillis();
System.out.println("Test for G3: " + (endTime-startTime) + "ms.");
startTime = System.currentTimeMillis();
LazyPrimMST<Double> lazyPrimMST4 = new LazyPrimMST<Double>(g4);
endTime = System.currentTimeMillis();
System.out.println("Test for G4: " + (endTime-startTime) + "ms.");
// startTime = System.currentTimeMillis();
// LazyPrimMST<Double> lazyPrimMST5 = new LazyPrimMST<Double>(g5);
// endTime = System.currentTimeMillis();
// System.out.println("Test for G5: " + (endTime-startTime) + "ms.");
System.out.println();
// Test Prim MST
System.out.println("Test Prim MST:");
startTime = System.currentTimeMillis();
PrimMST<Double> primMST1 = new PrimMST<Double>(g1);
endTime = System.currentTimeMillis();
System.out.println("Test for G1: " + (endTime-startTime) + "ms.");
startTime = System.currentTimeMillis();
PrimMST<Double> primMST2 = new PrimMST<Double>(g2);
endTime = System.currentTimeMillis();
System.out.println("Test for G2: " + (endTime-startTime) + "ms.");
startTime = System.currentTimeMillis();
PrimMST<Double> primMST3 = new PrimMST<Double>(g3);
endTime = System.currentTimeMillis();
System.out.println("Test for G3: " + (endTime-startTime) + "ms.");
startTime = System.currentTimeMillis();
PrimMST<Double> primMST4 = new PrimMST<Double>(g4);
endTime = System.currentTimeMillis();
System.out.println("Test for G4: " + (endTime-startTime) + "ms.");
// startTime = System.currentTimeMillis();
// PrimMST<Double> primMST5 = new PrimMST<Double>(g5);
// endTime = System.currentTimeMillis();
// System.out.println("Test for G5: " + (endTime-startTime) + "ms.");
System.out.println();
}
}