$39.99
Important Notes:
1. The assignment is an individual project, to be finished on one’s own effort.
4. THERE IS NO LATE SUBMISSION OR RESUBMISSION FOR THIS ASSIGNMENT!
Marking Criterion:
1. The full score of the assignment is 100 marks.
2. There are three tests. Test A is 30 marks; test B is 30 marks; test C is 40 marks. A submission gets the corresponding scores if it passed each test.
3. Test A will use matrices of the size 100 by 50. Test B will use matrices of the size 1000 by 500. Test C will use matrices of the size 10000 by 5000.
Running Environment:
1. The submissions will be evaluated in Java environment under Linux platform.
2. The submission is acceptable if it runs in any of recent versions of Java SDK environment. These versions include from Java SE 8 to the most recent Java SE 17.
3. The submission is only allowed to import three packages of (java.lang.*; java.util.*; java.io.*) included in Java SDK. No other packages are allowed.
4. In the test, each program is required to finish within 30 seconds of time, with no more than 128MB memory. This is a strict requirement measured in the server environment!
5. Each student is free to test his/her program in the evaluation platform before the submission.
Submission Guidelines:
1. Detailed submission guideline will be given in a separate manual around Dec. 13.
2. Inconsistency with or violation from the guideline leads to marks deduction.
Problem Description:
Write a program to read two sparse matrices from two input files, add the two matrices, and write the result matrix into the output file. The input and output files have the following formats.
3, 2
1 1:7 2:9 2 :
3 2:-5
Here is an illustration of the file.
• The first line of the file (“3, 2”) represents the size of the matrix is 3 rows and 2 columns.
• The second line starts with 1, which means the 1st row of the matrix. “1:7” means the 1st column of the row is 7; “2:9” means the 2nd column of the row is 9.
• The third line starts with “2”, which means the 2nd row of the matrix. There are no other elements except a “:”, which means all the columns of the row are “0”.
• The fourth line starts with “3”, which means the 3rd row of the matrix. “2:-5” means the 2nd column of the row is -5.
• All elements that are not listed in the file are treated as 0.
Therefore, the file represents the following matrix:
7 9
0 0
0 −5
Functional Requirement
Write a program called AddSparseMatrix.java that reads two matrices from two input files, add the two matrices, and write the result into the output file.
Note that in our tests, the input matrices are sparse. Most matrix elements (around 95% in tests A and B, around 99% in test C) are zero. All non-zero elements are integers.
java AddSparseMatrix input1.txt input2.txt output.txt
In this specific example, the arguments “input1.txt” and “input2.txt” denotes two files that give the two input matrices. You can assume the two input matrices are always of the same size. The argument “output.txt” denotes the name of the file to write the result matrix.
Program Template:
There is no program template for this assignment.
Appendix
1. input1.txt
2. input2.txt
3. output.txt