001package org.cpsolver.instructor.model; 002 003import org.cpsolver.ifs.assignment.Assignment; 004import org.cpsolver.ifs.criteria.Criterion; 005import org.cpsolver.ifs.model.Value; 006 007/** 008 * Teaching assignment. An assignment of an instructor to a teaching request (a set of sections of a course). 009 * A teaching assignment also contains the value of attribute, instructor, course, and time preferences. 010 * 011 * @author Tomáš Müller 012 * @version IFS 1.3 (Instructor Sectioning)<br> 013 * Copyright (C) 2016 Tomáš Müller<br> 014 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 015 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 016 * <br> 017 * This library is free software; you can redistribute it and/or modify 018 * it under the terms of the GNU Lesser General Public License as 019 * published by the Free Software Foundation; either version 3 of the 020 * License, or (at your option) any later version. <br> 021 * <br> 022 * This library is distributed in the hope that it will be useful, but 023 * WITHOUT ANY WARRANTY; without even the implied warranty of 024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 025 * Lesser General Public License for more details. <br> 026 * <br> 027 * You should have received a copy of the GNU Lesser General Public 028 * License along with this library; if not see 029 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 030 */ 031public class TeachingAssignment extends Value<TeachingRequest.Variable, TeachingAssignment> { 032 private Instructor iInstructor; 033 private int iHashCode; 034 private int iAttributePreference, iInstructorPreference, iCoursePreference, iTimePreference; 035 036 /** 037 * Constructor 038 * @param variable teaching request variable 039 * @param instructor instructor (it is expected that {@link Instructor#canTeach(TeachingRequest)} is true and that {@link TeachingRequest#getAttributePreference(Instructor)} is not prohibited) 040 * @param attributePreference attribute preference (value of {@link TeachingRequest#getAttributePreference(Instructor)}) 041 */ 042 public TeachingAssignment(TeachingRequest.Variable variable, Instructor instructor, int attributePreference) { 043 super(variable); 044 iInstructor = instructor; 045 iHashCode = variable.hashCode() ^ instructor.hashCode(); 046 iTimePreference = instructor.getTimePreference(variable.getRequest()).getPreferenceInt(); 047 iCoursePreference = instructor.getCoursePreference(variable.getCourse()).getPreference(); 048 iInstructorPreference = variable.getRequest().getInstructorPreference(instructor).getPreference(); 049 iAttributePreference = attributePreference; 050 } 051 052 /** 053 * Constructor 054 * @param variable teaching request variable 055 * @param instructor instructor (it is expected that {@link Instructor#canTeach(TeachingRequest)} is true and that {@link TeachingRequest#getAttributePreference(Instructor)} is not prohibited) 056 */ 057 public TeachingAssignment(TeachingRequest.Variable variable, Instructor instructor) { 058 this(variable, instructor, variable.getRequest().getAttributePreference(instructor).getPreferenceInt()); 059 } 060 061 /** 062 * Assigned instructor 063 * @return assigned instructor 064 */ 065 public Instructor getInstructor() { 066 return iInstructor; 067 } 068 069 @Override 070 public double toDouble(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) { 071 double ret = 0.0; 072 for (Criterion<TeachingRequest.Variable, TeachingAssignment> criterion : variable().getModel().getCriteria()) 073 ret += criterion.getWeightedValue(assignment, this, null); 074 return ret; 075 } 076 077 @Override 078 public boolean equals(Object o) { 079 if (o == null || !(o instanceof TeachingAssignment)) 080 return false; 081 TeachingAssignment a = (TeachingAssignment) o; 082 return variable().equals(a.variable()) && getInstructor().equals(a.getInstructor()); 083 } 084 085 /** 086 * Attribute preference 087 * @return {@link TeachingRequest#getAttributePreference(Instructor)} 088 */ 089 public int getAttributePreference() { 090 return iAttributePreference; 091 } 092 093 /** 094 * Time preference 095 * @return {@link Instructor#getTimePreference(TeachingRequest)} 096 */ 097 public int getTimePreference() { 098 return iTimePreference; 099 } 100 101 /** 102 * Instructor preference 103 * @return {@link TeachingRequest#getInstructorPreference(Instructor) } 104 */ 105 public int getInstructorPreference() { 106 return iInstructorPreference; 107 } 108 109 /** 110 * Course preference 111 * @return {@link Instructor#getCoursePreference(Course)} for {@link TeachingRequest#getCourse()} 112 */ 113 public int getCoursePreference() { 114 return iCoursePreference; 115 } 116 117 @Override 118 public int hashCode() { 119 return iHashCode; 120 } 121 122 @Override 123 public String toString() { 124 return variable().getName() + ": " + getInstructor().getName(); 125 } 126 127 @Override 128 public String getName() { 129 return (getInstructor().hasName() ? getInstructor().getName() + (getInstructor().hasExternalId() ? " (" + getInstructor().getExternalId() + ")" : "") : getInstructor().getName()); 130 } 131}