-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRLFTester.java
More file actions
130 lines (97 loc) · 3.33 KB
/
RLFTester.java
File metadata and controls
130 lines (97 loc) · 3.33 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
import java.io.*;
import java.util.*;
class ColEdge
{
int u;
int v;
}
public class RLFTester
{
public final static boolean DEBUG = false;
public final static String COMMENT = "//";
public static void main( String args[] )
{
if( args.length < 1 )
{
System.out.println("Error! No filename specified.");
System.exit(0);
}
String inputfile = args[0];
boolean seen[] = null;
//! n is the number of vertices in the graph
int n = -1;
//! m is the number of edges in the graph
int m = -1;
//! e will contain the edges of the graph
ColEdge e[] = null;
try {
FileReader fr = new FileReader(inputfile);
BufferedReader br = new BufferedReader(fr);
String record = new String();
//! THe first few lines of the file are allowed to be comments, staring with a // symbol.
//! These comments are only allowed at the top of the file.
//! -----------------------------------------
while ((record = br.readLine()) != null)
{
if( record.startsWith("//") ) continue;
break; // Saw a line that did not start with a comment -- time to start reading the data in!
}
if( record.startsWith("VERTICES = ") )
{
n = Integer.parseInt( record.substring(11) );
if(DEBUG) System.out.println(COMMENT + " Number of vertices = "+n);
}
seen = new boolean[n+1];
record = br.readLine();
if( record.startsWith("EDGES = ") )
{
m = Integer.parseInt( record.substring(8) );
if(DEBUG) System.out.println(COMMENT + " Expected number of edges = "+m);
}
e = new ColEdge[m];
for( int d=0; d<m; d++)
{
if(DEBUG) System.out.println(COMMENT + " Reading edge "+(d+1));
record = br.readLine();
String data[] = record.split(" ");
if( data.length != 2 )
{
System.out.println("Error! Malformed edge line: "+record);
System.exit(0);
}
e[d] = new ColEdge();
e[d].u = Integer.parseInt(data[0]);
e[d].v = Integer.parseInt(data[1]);
seen[ e[d].u ] = true;
seen[ e[d].v ] = true;
if(DEBUG) System.out.println(COMMENT + " Edge: "+ e[d].u +" "+e[d].v);
}
String surplus = br.readLine();
if( surplus != null )
{
if( surplus.length() >= 2 ) if(DEBUG) System.out.println(COMMENT + " Warning: there appeared to be data in your file after the last edge: '"+surplus+"'");
}
}
catch (IOException ex)
{
// catch possible io errors from readLine()
System.out.println("Error! Problem reading file "+inputfile);
System.exit(0);
}
for( int x=1; x<=n; x++ )
{
if( seen[x] == false )
{
if(DEBUG) System.out.println(COMMENT + " Warning: vertex "+x+" didn't appear in any edge : it will be considered a disconnected vertex on its own.");
}
}
//! At this point e[0] will be the first edge, with e[0].u referring to one endpoint and e[0].v to the other
//! e[1] will be the second edge...
//! (and so on)
//! e[m-1] will be the last edge
//!
//! there will be n vertices in the graph, numbered 1 to n
//! INSERT YOUR CODE HERE!
GreedyRLF rlf = new GreedyRLF(e);
}
}