コード例 #1
0
ファイル: Scheduler.java プロジェクト: shahdk/SchoolBud
 public static void printSchedules(ArrayList<ArrayList<SchedulerCourse>> schedules) {
   int count = 0;
   for (ArrayList<SchedulerCourse> schedule : schedules) {
     System.out.println();
     System.out.println(
         "#" + count + "-------------------------------------------------------------------");
     count++;
     System.out.println();
     for (SchedulerCourse course : schedule) {
       System.out.println();
       System.out.println();
       System.out.println("COURSE");
       System.out.println(course.getName());
       for (ClassSection section : course.getSections()) {
         for (ClassDay day : section.getClassDays()) {
           System.out.println();
           System.out.print("DAY:");
           for (Integer hour : day.getHourSlots()) {
             System.out.print(section.getTeacher() + hour + ", ");
           }
         }
       }
     }
   }
 }
コード例 #2
0
ファイル: Scheduler.java プロジェクト: shahdk/SchoolBud
  // ===========================================================================================
  //
  //
  // Flattens our a single schedule (or list of scheduler classes with 1
  // section each)
  // so that it returns an ArrayList of 7 days, with all the hours
  // respectively put into each day
  public ArrayList<ArrayList<Integer>> flattenScheduleDays(ArrayList<SchedulerCourse> courses) {
    ArrayList<ArrayList<Integer>> week = new ArrayList<ArrayList<Integer>>();
    // create seven days of the week
    for (int i = 0; i < 7; i++) {
      week.add(new ArrayList<Integer>());
    }

    // go through each course
    for (SchedulerCourse course : courses) {
      // get that courses 1 section
      ClassSection section = course.getSections().get(0);

      // go through days of that 1 section
      for (int d = 0; d < 7; d++) {

        // append each days hours onto the respective day
        week.get(d).addAll(section.getClassDays().get(d).getHourSlots());
      }
    }

    // sort each days hours
    for (ArrayList<Integer> day : week) {
      java.util.Collections.sort(day);
    }
    return week;
  }
コード例 #3
0
ファイル: Scheduler.java プロジェクト: shahdk/SchoolBud
 private boolean containsAllClasses(ArrayList<SchedulerCourse> classes) {
   int total = this.nonOptionalClasses.size();
   int count = 0;
   for (SchedulerCourse course : classes) {
     if (!course.isOptional()) {
       count++;
     }
   }
   return (count == total);
 }
コード例 #4
0
ファイル: Scheduler.java プロジェクト: shahdk/SchoolBud
  // ===========================================================================================
  //
  // completely flattens out a list of schedules to an ArrayList of Integers
  public static ArrayList<Integer> getDayHoursLists(
      ArrayList<ArrayList<SchedulerCourse>> schedules) {

    ArrayList<Integer> hours = new ArrayList<Integer>();

    for (ArrayList<SchedulerCourse> schedule : schedules) {
      for (SchedulerCourse course : schedule) {
        for (ClassSection section : course.getSections()) {
          for (ClassDay day : section.getClassDays()) {
            for (Integer hour : day.getHourSlots()) {
              hours.add(hour);
            }
          }
        }
      }
    }

    return hours;
  }
コード例 #5
0
ファイル: Scheduler.java プロジェクト: shahdk/SchoolBud
  public void findMatchingCoursesWithSections(
      ArrayList<SchedulerCourse> currSectionCourses, ArrayList<SchedulerCourse> coursesToCheck) {

    // Base case - when you run out of classes to check against
    if (coursesToCheck.size() == 0) {
      if (this.containsAllClasses(currSectionCourses)) {
        this.schedules.add(currSectionCourses);
        this.filteredSchedules.add(currSectionCourses);
      }
    } else {
      // go through JUST next course to check against
      ArrayList<SchedulerCourse> tempCoursesToCheck = this.cloneSchedulerCoursList(coursesToCheck);
      SchedulerCourse course = tempCoursesToCheck.get(0);
      ArrayList<ClassSection> sections = course.getSections();
      tempCoursesToCheck.remove(0);
      boolean notAlreadyFound = true;
      // compile all sections of all current
      // built up classes for later comparison
      // compare ALL sections to current built up list
      ArrayList<ClassSection> currClassSections = new ArrayList<ClassSection>();
      for (SchedulerCourse currCourse : currSectionCourses) {
        for (ClassSection classSect : currCourse.getSections()) {
          currClassSections.add(classSect);
        }
      }

      // check for optional classes
      if (course.isOptional()) {
        notAlreadyFound = false;
        this.findMatchingCoursesWithSections(currSectionCourses, tempCoursesToCheck);
      }

      // go through each course section of JUST this course
      for (ClassSection section : sections) {

        if (!isSectionEmpty(section)) {
          if (!this.sectionsOverlapWithnewSection(currClassSections, section)) {

            ArrayList<ClassSection> newClassSections = new ArrayList<ClassSection>();
            newClassSections.add(section);
            SchedulerCourse newCourse =
                new SchedulerCourse(course.getCourseName(), newClassSections, course.isOptional());
            ArrayList<SchedulerCourse> newCourses =
                this.cloneSchedulerCoursList(currSectionCourses);
            newCourses.add(newCourse);

            this.findMatchingCoursesWithSections(newCourses, tempCoursesToCheck);
          }
        }
      }
    }
  }
コード例 #6
0
ファイル: Scheduler.java プロジェクト: shahdk/SchoolBud
  public ArrayList<ArrayList<SchedulerCourse>> permutateSchedules() {

    // reset instance variables
    this.schedules.clear();
    this.filteredSchedules.clear();
    this.nonOptionalClasses.clear();

    if (this.classes == null || this.classes.size() == 0) {
      return this.schedules;
    }

    // find NON-optional classes
    for (SchedulerCourse course : this.classes) {
      if (!course.isOptional()) {
        this.nonOptionalClasses.add(course);
      }
    }

    // fixate one course to create branches from
    SchedulerCourse course = this.classes.get(0);
    ArrayList<ClassSection> sections = course.getSections();

    // go through each section
    for (ClassSection section : sections) {

      if (!isSectionEmpty(section)) {

        ArrayList<ClassSection> sectionList = new ArrayList<ClassSection>();
        sectionList.add(section);
        SchedulerCourse cour =
            new SchedulerCourse(course.getCourseName(), sectionList, course.isOptional());
        ArrayList<SchedulerCourse> courses = new ArrayList<SchedulerCourse>();
        courses.add(cour);

        // deep clone classes list
        ArrayList<SchedulerCourse> coursesToCheck = this.cloneSchedulerCoursList(this.classes);

        // remove courses not to check
        int index = this.classes.indexOf(course);
        for (int i = 0; i <= index; i++) {
          coursesToCheck.remove(i);
        }
        this.findMatchingCoursesWithSections(courses, coursesToCheck);
      }
    }

    return this.schedules;
  }