Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class ExamSchedule {
- // Variable declaration that will satisfy the exam schedule
- int[][] adjacency_matrix;
- int[] exam_days, degrs;
- int num_courses, Days;
- ArrayList exam_schedule = new ArrayList();
- // Array is initialized
- public ExamSchedule(int size, int[][] adjacency_matrix) {
- this.num_courses = size;
- this.exam_days = new int[size];
- this.degrs = new int [size];
- this.adjacency_matrix = new int [size][size];
- this.adjacency_matrix = adjacency_matrix;
- for (int i = 0; i < size;i++){
- degrs[i] = 0;
- for (int j = 0; j < size;j++){
- degrs[i] = degrs[i] + adjacency_matrix[i][j];
- }
- }
- }
- // Method to generate exam schedule, and save everything into designated variable
- public void CreateSchedule() {
- boolean[] done = new boolean[num_courses];
- boolean no_con = false;
- int days = 0;
- int size;
- for (int i = 0; i < num_courses; i++) {
- done[i] = false;
- }
- // Counted for loop that will add to the array list with exam info
- for (int i = 0; i < num_courses; i++) {
- if (!done[i]) {
- days++;
- exam_schedule.add(new ArrayList());
- ((ArrayList) exam_schedule.get(days - 1)).add(i);
- exam_days[i] = days;
- done[i] = true;
- }
- for (int j = 0; j < num_courses; j++) {
- no_con = true;
- size = ((ArrayList) exam_schedule.get(days - 1)).size();
- if (adjacency_matrix[i][j] == 0) {
- if (size >= 1) {
- // This for loop will go through the exams and check for conflicts
- for (int k = 1; k < size; k++) {
- if ((adjacency_matrix[((Integer) ((ArrayList) (exam_schedule
- .get(days - 1))).get(k))][j]) == 1) {
- no_con = false;
- }
- }
- // if no conflicts are found then this selection statement will run
- if (no_con) {
- ((ArrayList) exam_schedule.get(days - 1)).add(j);
- done[j] = true;
- exam_days[j] = days;
- }
- }
- }
- }
- // Resizes adjacency matrix
- for (int j = 0; j < ((ArrayList) exam_schedule.get(days - 1)).size(); j++) {
- // Convert all 0's to 1's for rows and columns of used exams.
- for (int k = 0; k < num_courses; k++) {
- adjacency_matrix[(Integer) (((ArrayList) exam_schedule.get(days - 1))
- .get(j))][k] = 1;
- adjacency_matrix[k][(Integer) (((ArrayList) exam_schedule.get(days - 1))
- .get(j))] = 1;
- }
- }
- }
- //Includes left over exams on their own days.
- for (int i = 0; i < num_courses; i++) {
- if (!done[i]) {
- days++;
- exam_schedule.add(new ArrayList());
- ((ArrayList) exam_schedule.get(days - 1)).add(i);
- }
- }
- //Stores the total number of days used.
- Days = days;
- }
- //Gives the number of days of exams
- public int howManyDays() {
- return Days;
- }
- //Exam schedule is returned based on the course
- public int[] whatDays() {
- return exam_days;
- }
- //The exam schedule is returned based on days
- public ArrayList whatDays2() {
- return exam_schedule;
- }
- }
Add Comment
Please, Sign In to add comment