Skip to content

Commit ddf4c3e

Browse files
committedMar 25, 2021
Added output file as command line argument and updated README, also added output files
1 parent 6ef9f4e commit ddf4c3e

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed
 

‎Luby.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ private static boolean verifyMIS(int[] ids, Set<Integer> misSet, List<List<Integ
143143

144144
public static void main(String[] args) {
145145

146-
// Pass on input file through command line argument
147-
if(args.length != 1) {
148-
System.err.println("Error: Input file not provided in the argument!");
146+
// Pass on input & output file through command line argument
147+
if(args.length != 2) {
148+
System.err.println("Error: Input and/or output file not provided in the argument!");
149149
System.exit(1);
150150
}
151151

@@ -212,7 +212,7 @@ public static void main(String[] args) {
212212

213213
// Write final output to a file
214214
try {
215-
BufferedWriter output = new BufferedWriter(new FileWriter("output.txt"));
215+
BufferedWriter output = new BufferedWriter(new FileWriter(args[1]));
216216

217217
output.append("Number of rounds (phases): ").append(String.valueOf(rounds));
218218
output.newLine();

‎README

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ To implement the Luby's MIS algorithm, we have created a Luby.java file. To comp
22

33
a) The algorithm will run on csgrads1 server.
44
b) Make sure Java 1.8 or any other higher version is installed on the machine.
5-
c) The code takes one command-line argument i.e. input file. Make sure the input file is in the same directory with the code file.
5+
c) The code takes two command-line arguments i.e., input and output file names. Make sure the input file is in the same directory with the code file or make appropriate changes according to the file path in the command line argument.
66
d) The input file contains 3 lines -
77
1) n, number of vertices in the graph
88
2) id array; a one-dimensional array of size n
99
3) adjacency matrix (which is a symmetric n by n matrix). 1 represents if the nodes are adjacent to each other and 0 otherwise.
1010
e) First, to compile Luby.java use command "javac Luby.java".
1111
f) A Luby.class file will be created in the same directory after compiling the java file.
12-
g) Now, to run the above code, use command "java Luby inputfile" e.g. java Luby input1.txt
13-
h) An output file will be created in the same directory which contains the rounds (rounds took to generate the MIS), resultant MIS set and a verification message whether the generated MIS is correct or not.
12+
g) Now, to run the above code, use command "java Luby inputfile outputfile" e.g. java Luby input1.txt output1.txt
13+
h) An output file will be created which contains the rounds (rounds took to generate the MIS), resultant MIS set and a verification message whether the generated MIS is correct or not.

‎output1.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Number of rounds (phases): 2
2+
MIS has the processes with IDs: 10 15
3+
Verifying the MIS constructed is correct...
4+
Verified that the MIS constructed is indeed correct!

‎output2.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Number of rounds (phases): 1
2+
MIS has the processes with IDs: 1 4
3+
Verifying the MIS constructed is correct...
4+
Verified that the MIS constructed is indeed correct!

‎output3.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Number of rounds (phases): 2
2+
MIS has the processes with IDs: 2 3 6 7 8
3+
Verifying the MIS constructed is correct...
4+
Verified that the MIS constructed is indeed correct!

0 commit comments

Comments
 (0)
Please sign in to comment.