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