001package org.cpsolver.coursett.criteria.additional;
002
003import java.util.Collection;
004import java.util.Map;
005
006import org.cpsolver.coursett.constraint.JenrlConstraint;
007import org.cpsolver.coursett.model.Lecture;
008import org.cpsolver.coursett.model.Placement;
009import org.cpsolver.coursett.model.Student;
010import org.cpsolver.ifs.assignment.Assignment;
011import org.cpsolver.ifs.util.DataProperties;
012
013
014/**
015 * Instructor student conflicts. This criterion penalizes cases when an instructor (of a class) is attending some 
016 * other class as a student and there is a conflict between the two classes. Also, there is no alternative for the
017 * student class (the conflict cannot be sectioned away).
018 * <br>
019 * To enable instructor student conflicts, set solver parameter Global.LoadStudentInstructorConflicts to true. Also
020 * student course requests should be used in this case (to be able to match an instructor external id to a student 
021 * external id).
022 * <br>
023 * Hard instructor student conflicts are weighted by Comparator.InstructorHardStudentConflictWeight.
024 * <br>
025 * 
026 * @version CourseTT 1.3 (University Course Timetabling)<br>
027 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
028 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
029 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
030 * <br>
031 *          This library is free software; you can redistribute it and/or modify
032 *          it under the terms of the GNU Lesser General Public License as
033 *          published by the Free Software Foundation; either version 3 of the
034 *          License, or (at your option) any later version. <br>
035 * <br>
036 *          This library is distributed in the hope that it will be useful, but
037 *          WITHOUT ANY WARRANTY; without even the implied warranty of
038 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
039 *          Lesser General Public License for more details. <br>
040 * <br>
041 *          You should have received a copy of the GNU Lesser General Public
042 *          License along with this library; if not see
043 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
044 */
045public class InstructorStudentHardConflict extends InstructorStudentConflict {
046    
047    @Override
048    public boolean isApplicable(Lecture l1, Lecture l2) {
049        return super.isApplicable(l1, l2) && oneInstructorOtherHard(l1, l2);
050    }
051    
052    /**
053     * One of the lectures is hard, there is a joint enrollment constraint between them, and 
054     * there is at least one student that is instructor for one lecture and the other lecture
055     * is singleton.
056     * @param l1 first placement
057     * @param l2 second placement
058     * @return true if there is at least one student of one class teaching the other class, and there are no possibility to move the student into an alternative class
059     */
060    public static boolean oneInstructorOtherHard(Lecture l1, Lecture l2) {
061        if (!hard(l1, l2)) return false;
062        JenrlConstraint jenrl = l1.jenrlConstraint(l2);
063        if (jenrl == null) return false;
064        for (Student student: jenrl.getInstructors()) {
065            if ((l1.isSingleSection() || student.getInstructor().variables().contains(jenrl.second())) &&
066                (l2.isSingleSection() || student.getInstructor().variables().contains(jenrl.first())))
067                return true;
068        }
069        return false;
070    }
071
072    @Override
073    public double getWeightDefault(DataProperties config) {
074        return config.getPropertyDouble("Comparator.InstructorHardStudentConflictWeight", 10.0 * config.getPropertyDouble("Comparator.HardStudentConflictWeight", 5.0));
075    }
076    
077    @Override
078    public String getPlacementSelectionWeightName() {
079        return "Placement.NrInstructorHardStudConfsWeight";
080    }
081    
082    @Override
083    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) {
084    }
085    
086    @Override
087    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info, Collection<Lecture> variables) {
088    }
089
090}