-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphTester.java
More file actions
145 lines (106 loc) · 3.96 KB
/
GraphTester.java
File metadata and controls
145 lines (106 loc) · 3.96 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//package Graphs;
import java.util.ArrayList;
public class GraphTester {
public static Graph getTestGraphMST1() {
Graph myGraph = (Graph)(new GraphAL (10));
myGraph.addVertex("Andrea");
myGraph.addVertex("Basilio");
myGraph.addVertex("Chris");
myGraph.addVertex("David");
myGraph.addVertex("Eleni");
myGraph.addVertex("Frank");
myGraph.addBidirectionalEdge("Andrea", "David",11.0);
myGraph.addBidirectionalEdge("Basilio", "Andrea",7.0);
myGraph.addBidirectionalEdge("Basilio", "Chris",3.0);
myGraph.addBidirectionalEdge("Basilio", "Eleni",15.0);
myGraph.addBidirectionalEdge("Basilio", "Frank",10.0);
myGraph.addBidirectionalEdge("Chris", "Frank",7.0);
myGraph.addBidirectionalEdge("David", "Eleni",2.0);
myGraph.addBidirectionalEdge("David", "Frank",4.0);
myGraph.addBidirectionalEdge("Eleni", "Frank",2.0);
return myGraph;
}
public static Graph getTestGraph1() {
Graph myGraph = (new GraphAL(10));
myGraph.addVertex("Andrea");
myGraph.addVertex("Basilio");
myGraph.addVertex("Chris");
myGraph.addVertex("David");
myGraph.addVertex("Eleni");
myGraph.addVertex("Frank");
myGraph.addEdge("Andrea", "David",1.0);
myGraph.addEdge("Basilio", "Andrea",23.0);
myGraph.addEdge("Basilio", "Chris",12.0);
myGraph.addEdge("Basilio", "Eleni",12.0);
myGraph.addEdge("Basilio", "Frank",12.0);
myGraph.addEdge("Chris", "Frank",12.0);
myGraph.addEdge("David", "Eleni",12.0);
myGraph.addEdge("Eleni", "Andrea",12.0);
myGraph.addEdge("Eleni", "Frank",12.0);
return myGraph;
}
public static Graph getTestGraph2() {
Graph myGraph = (new GraphAM(10));
myGraph.addVertex("Andrea");
myGraph.addVertex("Basilio");
myGraph.addVertex("Chris");
myGraph.addVertex("David");
myGraph.addVertex("Eleni");
myGraph.addVertex("Frank");
myGraph.addEdge("Andrea", "David",1.0);
myGraph.addEdge("Basilio", "Andrea",23.0);
myGraph.addEdge("Basilio", "Chris",12.0);
myGraph.addEdge("Basilio", "Eleni",12.0);
myGraph.addEdge("Basilio", "Frank",12.0);
myGraph.addEdge("Chris", "Frank",12.0);
myGraph.addEdge("David", "Eleni",12.0);
myGraph.addEdge("Eleni", "Andrea",12.0);
myGraph.addEdge("Eleni", "Frank",12.0);
return myGraph;
}
public static void testCreateGraph1() {
Graph myGraph = getTestGraph1(); // Get a graph, implemented as an Ajd List
System.out.println("This is the AL graph implementation");
myGraph.print();
//
// Calling DFS operator
//
System.out.println("This is the DFS traversal of the Graph");
GraphSearchOperator operatorDFS = new DFSearch();
ArrayList<Vertex> walkedPath = operatorDFS.traverse((GraphAL) myGraph);
for (Vertex vx : walkedPath) {
System.out.print(vx.name + "->");
}
System.out.println("End of DFS traversal");
//
// Calling BFS operator
//
System.out.println("This is the BFS traversal of the Graph");
GraphSearchOperator operatorBFS = new BFSearch();
Queue<Vertex> walkedPathBFS = operatorBFS.traverse1((GraphAL) myGraph);
for (Vertex vx : walkedPathBFS)
{
System.out.print(vx.name + "->");
}
System.out.println("End of BFS traversal");
}
public static void testMST1() {
Graph myGraph = getTestGraphMST1();
System.out.println("This is the AL bidirectional graph implementation");
myGraph.print();
System.out.println("Prim MST");
GraphMstPrimOperator operatorMST = new GraphMstPrimOperator();
Graph mstPrim = operatorMST.getMSTree(myGraph);
mstPrim.print();
//System.out.println("Kruskal MST");
//GraphMstKruskalOperator operatorMST1 = new GraphMstKruskalOperator();
//Graph mstKruskal = operatorMST1.getMSTree(myGraph);
//mstKruskal.print();
}
public static void main(String[] args) {
testCreateGraph1();
//testCreateGraph2();
testMST1();
//testMST2();
}
}