-
Notifications
You must be signed in to change notification settings - Fork 0
/
GraphReader.java
48 lines (42 loc) · 1.34 KB
/
GraphReader.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
import java.util.*;
import java.io.*;
/**
* Read the graph from Constants.FILE
* See the following URL for instances:
* http://www.nlsde.buaa.edu.cn/~kexu/benchmarks/graph-benchmarks.htm
*
* @author Shalin Shah
* Email: [email protected]
*/
public class GraphReader {
/** Creates a new instance of GraphReader */
public GraphReader() {
}
public static Graph readGraph() throws Exception
{
BufferedReader reader = new BufferedReader(new FileReader(new File(Constants.FILE)));
String line = reader.readLine();
while(line.charAt(0) == 'c')
{
line = reader.readLine();
}
StringTokenizer token = new StringTokenizer(line, " ");
token.nextToken();
token.nextToken();
Constants.NUMBER_NODES = Integer.parseInt(token.nextToken().trim());
Graph graph = new Graph();
line = reader.readLine();
while(line != null)
{
token = new StringTokenizer(line, " ");
token.nextToken();
int sv = Integer.parseInt(token.nextToken().trim());
int ev = Integer.parseInt(token.nextToken().trim());
sv--;
ev--;
graph.addEdge(sv, ev);
line = reader.readLine();
}
return graph;
}
}