001package org.cpsolver.instructor.criteria; 002 003import java.util.Collection; 004import java.util.Set; 005 006import org.cpsolver.ifs.assignment.Assignment; 007import org.cpsolver.ifs.util.DataProperties; 008import org.cpsolver.instructor.model.Instructor; 009import org.cpsolver.instructor.model.InstructorSchedulingModel; 010import org.cpsolver.instructor.model.TeachingAssignment; 011import org.cpsolver.instructor.model.TeachingRequest; 012 013/** 014 * Back to Back. This criterion counts how well are the back-to-back preferences that are set on an {@link Instructor} met 015 * (counting {@link Instructor#countBackToBacks(Assignment, TeachingAssignment, double, double)}). 016 * 017 * @author Tomáš Müller 018 * @version IFS 1.3 (Instructor Sectioning)<br> 019 * Copyright (C) 2016 Tomáš Müller<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 */ 037public class BackToBack extends InstructorSchedulingCriterion { 038 private double iDiffRoomWeight = 0.8, iDiffTypeWeight = 0.5; 039 040 public BackToBack() { 041 setValueUpdateType(ValueUpdateType.NoUpdate); 042 } 043 044 @Override 045 public void configure(DataProperties properties) { 046 super.configure(properties); 047 iDiffRoomWeight = properties.getPropertyDouble("BackToBack.DifferentRoomWeight", 0.8); 048 iDiffTypeWeight = properties.getPropertyDouble("BackToBack.DifferentTypeWeight", 0.5); 049 } 050 051 @Override 052 public double getWeightDefault(DataProperties config) { 053 return 1.0; 054 } 055 056 /** 057 * Different room weight 058 * @return penalty for teaching two back-to-back that are in different rooms 059 */ 060 public double getDifferentRoomWeight() { return iDiffRoomWeight; } 061 062 /** 063 * Different instructional type weight 064 * @return penalty for teaching two back-to-back that are of different instructional type 065 */ 066 public double getDifferentTypeWeight() { return iDiffTypeWeight; } 067 068 @Override 069 public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) { 070 return value.getInstructor().countBackToBacks(assignment, value, iDiffRoomWeight, iDiffTypeWeight); 071 } 072 073 @Override 074 protected double[] computeBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) { 075 double[] bounds = new double[] { 0.0, 0.0 }; 076 for (Instructor instructor: ((InstructorSchedulingModel)getModel()).getInstructors()) { 077 bounds[1] += Math.abs(instructor.getBackToBackPreference()); 078 } 079 return bounds; 080 } 081 082 @Override 083 public double[] getBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) { 084 double[] bounds = new double[] { 0.0, 0.0 }; 085 for (Instructor instructor: getInstructors(assignment, variables)) { 086 bounds[1] += Math.abs(instructor.getBackToBackPreference()); 087 } 088 return bounds; 089 } 090 091 @Override 092 public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) { 093 double value = 0.0; 094 for (Instructor instructor: getAssignedInstructors(assignment, variables)) 095 value += instructor.getContext(assignment).countBackToBackPreference(iDiffRoomWeight, iDiffTypeWeight); 096 return value; 097 } 098 099 @Override 100 public String getAbbreviation() { 101 return "Back2Back"; 102 } 103}