-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSimpleGraph.java
57 lines (52 loc) · 1.5 KB
/
TestSimpleGraph.java
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
import java.util.*;
import java.io.*;
import graph.*;
public class TestSimpleGraph{
private static UndirectedGraph G;
public static void main(String args[]){
initGraph();
// initTestGraph2();
// G.displayGraph();
int nCut = G.computeMinCut();
System.out.format("%d cuts \n", nCut);
// G.displayGraph();
}
private static void initTestGraph() {
G = new UndirectedGraph(10);
G.addEdge(0,1);
G.addEdge(1,2);
G.addEdge(2,3);
G.addEdge(0,2);
G.addEdge(0,3);
}
private static void initTestGraph2() {
G = new UndirectedGraph(5);
G.addEdge(0,1);
G.addEdge(1,2);
G.addEdge(2,3);
G.addEdge(3,4);
G.addEdge(0,4);
G.addEdge(0,3);
G.addEdge(1,3);
}
private static void initGraph() {
G = new UndirectedGraph(200);
String fname = "kargerMinCut.txt";
// String fname = "kargerMinCutSimple.txt";
Scanner sc = null;
try {
sc = new Scanner(new File(fname));
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
while (sc.hasNextLine()) {
String line = sc.nextLine();
String[] nodes = line.split("\\s");
int tail = Integer.parseInt(nodes[0]) - 1;
for (int i = 1; i < nodes.length; i++) {
int head = Integer.parseInt(nodes[i]) - 1;
G.addEdge(tail,head);
}
}
}
}