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