Guest User

Untitled

a guest
Jun 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class ExamSchedule {
  4. // Variable declaration that will satisfy the exam schedule
  5. int[][] adjacency_matrix;
  6. int[] exam_days, degrs;
  7. int num_courses, Days;
  8. ArrayList exam_schedule = new ArrayList();
  9.  
  10. // Array is initialized
  11. public ExamSchedule(int size, int[][] adjacency_matrix) {
  12. this.num_courses = size;
  13. this.exam_days = new int[size];
  14. this.degrs = new int [size];
  15. this.adjacency_matrix = new int [size][size];
  16. this.adjacency_matrix = adjacency_matrix;
  17.  
  18. for (int i = 0; i < size;i++){
  19. degrs[i] = 0;
  20. for (int j = 0; j < size;j++){
  21. degrs[i] = degrs[i] + adjacency_matrix[i][j];
  22. }
  23. }
  24. }
  25. // Method to generate exam schedule, and save everything into designated variable
  26. public void CreateSchedule() {
  27. boolean[] done = new boolean[num_courses];
  28. boolean no_con = false;
  29. int days = 0;
  30. int size;
  31. for (int i = 0; i < num_courses; i++) {
  32. done[i] = false;
  33. }
  34. // Counted for loop that will add to the array list with exam info
  35. for (int i = 0; i < num_courses; i++) {
  36. if (!done[i]) {
  37. days++;
  38. exam_schedule.add(new ArrayList());
  39. ((ArrayList) exam_schedule.get(days - 1)).add(i);
  40. exam_days[i] = days;
  41. done[i] = true;
  42. }
  43. for (int j = 0; j < num_courses; j++) {
  44. no_con = true;
  45. size = ((ArrayList) exam_schedule.get(days - 1)).size();
  46. if (adjacency_matrix[i][j] == 0) {
  47. if (size >= 1) {
  48. // This for loop will go through the exams and check for conflicts
  49. for (int k = 1; k < size; k++) {
  50. if ((adjacency_matrix[((Integer) ((ArrayList) (exam_schedule
  51. .get(days - 1))).get(k))][j]) == 1) {
  52. no_con = false;
  53. }
  54. }
  55. // if no conflicts are found then this selection statement will run
  56. if (no_con) {
  57. ((ArrayList) exam_schedule.get(days - 1)).add(j);
  58. done[j] = true;
  59. exam_days[j] = days;
  60. }
  61. }
  62. }
  63. }
  64. // Resizes adjacency matrix
  65. for (int j = 0; j < ((ArrayList) exam_schedule.get(days - 1)).size(); j++) {
  66. // Convert all 0's to 1's for rows and columns of used exams.
  67. for (int k = 0; k < num_courses; k++) {
  68. adjacency_matrix[(Integer) (((ArrayList) exam_schedule.get(days - 1))
  69. .get(j))][k] = 1;
  70. adjacency_matrix[k][(Integer) (((ArrayList) exam_schedule.get(days - 1))
  71. .get(j))] = 1;
  72. }
  73. }
  74. }
  75. //Includes left over exams on their own days.
  76. for (int i = 0; i < num_courses; i++) {
  77. if (!done[i]) {
  78. days++;
  79. exam_schedule.add(new ArrayList());
  80. ((ArrayList) exam_schedule.get(days - 1)).add(i);
  81. }
  82. }
  83. //Stores the total number of days used.
  84. Days = days;
  85. }
  86. //Gives the number of days of exams
  87. public int howManyDays() {
  88. return Days;
  89. }
  90. //Exam schedule is returned based on the course
  91. public int[] whatDays() {
  92. return exam_days;
  93. }
  94. //The exam schedule is returned based on days
  95. public ArrayList whatDays2() {
  96. return exam_schedule;
  97. }
  98. }
Add Comment
Please, Sign In to add comment