Пример #1
10
  public void createRandomIndividuals(int numIndividuals, KTH kth) {
    Map<Integer, Room> rooms = kth.getRooms();
    int numRooms = kth.getRooms().size();

    for (int i = 0; i < numIndividuals; i++) {
      // register all available timeslots
      ArrayList<TimeSlot> availableTimeSlots = new ArrayList<TimeSlot>();
      for (int roomId : rooms.keySet()) {
        for (int d = 0; d < RoomTimeTable.NUM_DAYS; d++) {
          for (int t = 0; t < RoomTimeTable.NUM_TIMESLOTS; t++) {
            availableTimeSlots.add(new TimeSlot(roomId, d, t));
          }
        }
      }

      TimeTable tt = new TimeTable(numRooms);
      for (int roomId : rooms.keySet()) {
        Room room = rooms.get(roomId);
        RoomTimeTable rtt = new RoomTimeTable(room);
        tt.putRoomTimeTable(roomId, rtt);
      }

      // index variables
      int rttId = 0;
      int day = 0;
      int timeSlot = 0;

      // assign all event to any randomly selected available timeslot
      Random rand = new Random(System.currentTimeMillis());
      for (Event e : kth.getEvents().values()) {
        TimeSlot availableTimeSlot =
            availableTimeSlots.get(rand.nextInt(availableTimeSlots.size()));
        RoomTimeTable rtt = tt.getRoomTimeTables()[availableTimeSlot.roomId];
        rtt.setEvent(availableTimeSlot.day, availableTimeSlot.timeSlot, e.getId());
        availableTimeSlots.remove(availableTimeSlot);
        /* DEBUG
        System.out.println("==============");
        System.out.println("ROOM TIME TABLE ID: " + rtt.getRoom().getName());
        System.out.println("Day: " + availableTimeSlot.day + " Timeslot: " + availableTimeSlot.timeSlot + " Event ID: " + e.getId());
        */
      }
      individuals.add(tt);
      availableTimeSlots.clear();
    }
  }
Пример #2
-7
  public void addIndividualSorted(TimeTable tt) {
    ListIterator<TimeTable> it = individuals.listIterator();
    ListIterator<TimeTable> it2 = individuals.listIterator();

    while (it.hasNext()) {
      if (it.next().getFitness() < tt.getFitness()) {
        it2.add(tt);
        break;
      }

      it2.next();
    }
  }
Пример #3
-9
  // This overrides the original method in the Object class.
  // This is a method that would convert all information of a Student object into a presentable
  // String.
  // It takes in no parameters and returns a String.
  @Override
  public String toString() {
    // This initializes an empty String that would be used to store all information about a Teacher
    // object.
    String info = "";

    // This stores all the information related to a Student object into the empty string.
    info = info + "Student Name: \n" + name.toString();
    info = info + "Student Number: " + studentNum;
    info = info + "\nTime Table Chosen:\n" + schedule.toString();

    return info;
  }
Пример #4
-47
  // This method adds a chosen course to the existing student's schedule if there is an empty space.
  // It takes in a Course object for the corresponding course and returns no value.
  // It outputs an error message if there is no empty spaces left in the student's schedule.
  public void addChosenCourse(Course newCourse) {
    // This finds the student's current schedule size.
    int scheduleSize = schedule.getCourseChosen().size();

    // This checks if the course is already selected by the student.
    boolean chosen = false;

    for (int i = 0; i < scheduleSize && !chosen; i++) {
      if (schedule.getCourseChosen().get(i).compareToCourseCode(newCourse) == 0) {
        chosen = true;
      }
    }

    // This checks the capacity of the student's schedule.
    // It adds the course if the schedule has 3 or fewer courses and outputs an error message if the
    // schedule has 4 courses.
    if (scheduleSize < MAX_SCHEDULE && !chosen) {
      schedule.getCourseChosen().add(scheduleSize, newCourse);
      System.out.println("The course is add from the student's schedule.");
    } else {
      // This outputs an error message if the entire schedule if full.
      System.out.println(
          "Sorry. The student's schedule is full or the course is already in the student's time table.");
      System.out.println("No new courses can be added.");
    }
  }
Пример #5
-48
  // This method deletes a chosen course from the existing student's schedule if such a course can
  // be found.
  // It takes in a Course object for the corresponding course and returns no value.
  // It outputs an error message if there is no such course found in the student's existing
  // schedule.
  public void deleteChosenCourse(Course deletedCourse) {
    // This initializes a boolean to be false to assume that there is such a course yet to be found
    // in the student's
    // existing schedule.
    boolean found = false;

    // This loops through the student's existing schedule to find the course.
    for (int i = 0; i < schedule.getCourseChosen().size() && !found; i++) {
      Course temCourse = schedule.getCourseChosen().get(i);
      if (temCourse.getCourseCode() == deletedCourse.getCourseCode()) {
        found = true;
        // This deletes the selected course by issuing the value of the course to be null.
        schedule.getCourseChosen().remove(i);
        System.out.println("The course is removed from the student's schedule.");
      }
    }

    // This outputs an error message if there is no such a course in the student's existing
    // schedule.
    if (!found) {
      System.out.println("Sorry. The student did not select this course.");
      System.out.println("No courses can be deleted.");
    }
  }