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 * @author Tomáš Müller 027 * @version CourseTT 1.3 (University Course Timetabling)<br> 028 * Copyright (C) 2006 - 2014 Tomáš Müller<br> 029 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 030 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 031 * <br> 032 * This library is free software; you can redistribute it and/or modify 033 * it under the terms of the GNU Lesser General Public License as 034 * published by the Free Software Foundation; either version 3 of the 035 * License, or (at your option) any later version. <br> 036 * <br> 037 * This library is distributed in the hope that it will be useful, but 038 * WITHOUT ANY WARRANTY; without even the implied warranty of 039 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 040 * Lesser General Public License for more details. <br> 041 * <br> 042 * You should have received a copy of the GNU Lesser General Public 043 * License along with this library; if not see 044 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 045 */ 046public class InstructorStudentHardConflict extends InstructorStudentConflict { 047 048 @Override 049 public boolean isApplicable(Lecture l1, Lecture l2) { 050 return super.isApplicable(l1, l2) && oneInstructorOtherHard(l1, l2); 051 } 052 053 /** 054 * One of the lectures is hard, there is a joint enrollment constraint between them, and 055 * there is at least one student that is instructor for one lecture and the other lecture 056 * is singleton. 057 * @param l1 first placement 058 * @param l2 second placement 059 * @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 060 */ 061 public static boolean oneInstructorOtherHard(Lecture l1, Lecture l2) { 062 if (!hard(l1, l2)) return false; 063 JenrlConstraint jenrl = l1.jenrlConstraint(l2); 064 if (jenrl == null) return false; 065 for (Student student: jenrl.getInstructors()) { 066 if ((l1.isSingleSection() || student.getInstructor().variables().contains(jenrl.second())) && 067 (l2.isSingleSection() || student.getInstructor().variables().contains(jenrl.first()))) 068 return true; 069 } 070 return false; 071 } 072 073 @Override 074 public double getWeightDefault(DataProperties config) { 075 return config.getPropertyDouble("Comparator.InstructorHardStudentConflictWeight", 10.0 * config.getPropertyDouble("Comparator.HardStudentConflictWeight", 5.0)); 076 } 077 078 @Override 079 public String getPlacementSelectionWeightName() { 080 return "Placement.NrInstructorHardStudConfsWeight"; 081 } 082 083 @Override 084 public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) { 085 } 086 087 @Override 088 public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info, Collection<Lecture> variables) { 089 } 090 091}