001 package net.sf.cpsolver.studentsct.reservation;
002
003 import java.util.Collection;
004 import java.util.HashSet;
005 import java.util.Set;
006
007 import net.sf.cpsolver.studentsct.model.AcademicAreaCode;
008 import net.sf.cpsolver.studentsct.model.Offering;
009 import net.sf.cpsolver.studentsct.model.Student;
010
011 /**
012 * Curriculum reservation. Students are matched based on their academic area.
013 * If classifications and/or majors are included, student must match on them as well.
014 *
015 * <br>
016 * <br>
017 *
018 * @version StudentSct 1.2 (Student Sectioning)<br>
019 * Copyright (C) 2007 - 2010 Tomas Muller<br>
020 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
021 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
022 * <br>
023 * This library is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU Lesser General Public License as
025 * published by the Free Software Foundation; either version 3 of the
026 * License, or (at your option) any later version. <br>
027 * <br>
028 * This library is distributed in the hope that it will be useful, but
029 * WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
031 * Lesser General Public License for more details. <br>
032 * <br>
033 * You should have received a copy of the GNU Lesser General Public
034 * License along with this library; if not see
035 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
036 */
037 public class CurriculumReservation extends Reservation {
038 private double iLimit;
039 private String iAcadArea;
040 private Set<String> iClassifications = new HashSet<String>();
041 private Set<String> iMajors = new HashSet<String>();
042
043 /**
044 * Constructor
045 * @param id unique id
046 * @param limit reservation limit (-1 for unlimited)
047 * @param offering instructional offering on which the reservation is set
048 * @param acadArea academic area
049 * @param classifications zero or more classifications (classifications must match if not empty)
050 * @param majors zero or more majors (majors must match if not empty)
051 */
052 public CurriculumReservation(long id, double limit, Offering offering, String acadArea, Collection<String> classifications, Collection<String> majors) {
053 super(id, offering);
054 iLimit = limit;
055 iAcadArea = acadArea;
056 if (classifications != null)
057 iClassifications.addAll(classifications);
058 if (majors != null)
059 iMajors.addAll(majors);
060 }
061
062 /**
063 * Curriculum reservation cannot go over the limit
064 */
065 @Override
066 public boolean canAssignOverLimit() {
067 return false;
068 }
069
070 /**
071 * Curriculum reservation do not need to be used
072 */
073 @Override
074 public boolean mustBeUsed() {
075 return false;
076 }
077
078 /**
079 * Reservation limit (-1 for unlimited)
080 */
081 @Override
082 public double getReservationLimit() {
083 return iLimit;
084 }
085
086 /**
087 * Set reservation limit (-1 for unlimited)
088 */
089 public void setReservationLimit(double limit) {
090 iLimit = limit;
091 }
092
093 /**
094 * Reservation priority (lower than individual and group reservations)
095 */
096 @Override
097 public int getPriority() {
098 return 3;
099 }
100
101 /**
102 * Academic area
103 */
104 public String getAcademicArea() {
105 return iAcadArea;
106 }
107
108 /**
109 * Majors
110 */
111 public Set<String> getMajors() {
112 return iMajors;
113 }
114
115 /**
116 * Academic classifications
117 */
118 public Set<String> getClassifications() {
119 return iClassifications;
120 }
121
122 /**
123 * Check the area, classifications and majors
124 */
125 @Override
126 public boolean isApplicable(Student student) {
127 boolean match = false;
128 if (student.getAcademicAreaClasiffications() == null) return false;
129 for (AcademicAreaCode aac: student.getAcademicAreaClasiffications()) {
130 if (getAcademicArea().equals(aac.getArea())) {
131 if (getClassifications().isEmpty() || getClassifications().contains(aac.getCode())) {
132 match = true; break;
133 }
134 }
135 }
136 if (!match) return false;
137 for (AcademicAreaCode aac: student.getMajors()) {
138 if (getAcademicArea().equals(aac.getArea())) {
139 if (getMajors().isEmpty() || getMajors().contains(aac.getCode()))
140 return true;
141 }
142 }
143 return getMajors().isEmpty();
144 }
145
146
147 }