001package org.cpsolver.studentsct.reservation;
002
003import org.cpsolver.studentsct.model.Course;
004import org.cpsolver.studentsct.model.CourseRequest;
005import org.cpsolver.studentsct.model.Request;
006import org.cpsolver.studentsct.model.Student;
007
008/**
009 * Course reservation. Students are matched based on their course requests.  
010 * 
011 * <br>
012 * <br>
013 * 
014 * @author  Tomáš Müller
015 * @version StudentSct 1.3 (Student Sectioning)<br>
016 *          Copyright (C) 2007 - 2014 Tomáš Müller<br>
017 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
018 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
019 * <br>
020 *          This library is free software; you can redistribute it and/or modify
021 *          it under the terms of the GNU Lesser General Public License as
022 *          published by the Free Software Foundation; either version 3 of the
023 *          License, or (at your option) any later version. <br>
024 * <br>
025 *          This library is distributed in the hope that it will be useful, but
026 *          WITHOUT ANY WARRANTY; without even the implied warranty of
027 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
028 *          Lesser General Public License for more details. <br>
029 * <br>
030 *          You should have received a copy of the GNU Lesser General Public
031 *          License along with this library; if not see
032 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
033 */
034public class CourseReservation extends Reservation {
035    private Course iCourse;
036    
037    /**
038     * Reservation priority (lower than individual and group reservations)
039     */
040    public static final int DEFAULT_PRIORITY = 400;
041    /**
042     * Course reservation does not need to be used
043     */
044    public static final boolean DEFAULT_MUST_BE_USED = false;
045    /**
046     * Course reservations can not assign over the limit.
047     */
048    public static final boolean DEFAULT_CAN_ASSIGN_OVER_LIMIT = false;
049    /**
050     * Overlaps are not allowed for course reservations. 
051     */
052    public static final boolean DEFAULT_ALLOW_OVERLAP = false;
053    
054    /**
055     * Constructor
056     * @param id unique id
057     * @param course course offering on which the reservation is set
058     */
059    public CourseReservation(long id, Course course) {
060        super(id, course.getOffering(), DEFAULT_PRIORITY, DEFAULT_MUST_BE_USED, DEFAULT_CAN_ASSIGN_OVER_LIMIT, DEFAULT_ALLOW_OVERLAP);
061        iCourse = course;
062    }
063
064    /**
065     * Reservation limit (-1 for unlimited)
066     */
067    @Override
068    public double getReservationLimit() {
069        return iCourse.getLimit();
070    }
071    
072    /**
073     * Course offering
074     * @return course offering
075     */
076    public Course getCourse() {
077        return iCourse;
078    }
079    
080    /**
081     * Check the area, classifications and majors
082     */
083    @Override
084    public boolean isApplicable(Student student) {
085        for (Request r: student.getRequests()) {
086            if (r instanceof CourseRequest) {
087                for (Course course: ((CourseRequest) r).getCourses()) {
088                    if (course.equals(getCourse())) return true;
089                }
090            }
091        }
092        return false;
093    }
094}