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 * Same Days. This criterion counts how well are the same days preferences that are set on an {@link Instructor} met 015 * (counting {@link Instructor#countSameDays(Assignment, TeachingAssignment, double, double)}). 016 * 017 * @version IFS 1.3 (Instructor Sectioning)<br> 018 * Copyright (C) 2016 Tomáš Müller<br> 019 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 020 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 021 * <br> 022 * This library is free software; you can redistribute it and/or modify 023 * it under the terms of the GNU Lesser General Public License as 024 * published by the Free Software Foundation; either version 3 of the 025 * License, or (at your option) any later version. <br> 026 * <br> 027 * This library is distributed in the hope that it will be useful, but 028 * WITHOUT ANY WARRANTY; without even the implied warranty of 029 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 030 * Lesser General Public License for more details. <br> 031 * <br> 032 * You should have received a copy of the GNU Lesser General Public 033 * License along with this library; if not see 034 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 035 */ 036public class SameDays extends InstructorSchedulingCriterion { 037 private double iDiffRoomWeight = 0.8, iDiffTypeWeight = 0.5; 038 039 public SameDays() { 040 setValueUpdateType(ValueUpdateType.NoUpdate); 041 } 042 043 @Override 044 public void configure(DataProperties properties) { 045 super.configure(properties); 046 iDiffRoomWeight = properties.getPropertyDouble("SameDays.DifferentRoomWeight", 1.0); 047 iDiffTypeWeight = properties.getPropertyDouble("SameDays.DifferentTypeWeight", 0.5); 048 } 049 050 @Override 051 public double getWeightDefault(DataProperties config) { 052 return 1.0; 053 } 054 055 /** 056 * Different room weight 057 * @return penalty for teaching two same-days that are in different rooms 058 */ 059 public double getDifferentRoomWeight() { return iDiffRoomWeight; } 060 061 /** 062 * Different instructional type weight 063 * @return penalty for teaching two same-days that are of different instructional type 064 */ 065 public double getDifferentTypeWeight() { return iDiffTypeWeight; } 066 067 @Override 068 public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) { 069 return value.getInstructor().countSameDays(assignment, value, iDiffRoomWeight, iDiffTypeWeight); 070 } 071 072 @Override 073 protected double[] computeBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) { 074 double[] bounds = new double[] { 0.0, 0.0 }; 075 for (Instructor instructor: ((InstructorSchedulingModel)getModel()).getInstructors()) { 076 bounds[1] += Math.abs(instructor.getSameDaysPreference()); 077 } 078 return bounds; 079 } 080 081 @Override 082 public double[] getBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) { 083 double[] bounds = new double[] { 0.0, 0.0 }; 084 for (Instructor instructor: getInstructors(assignment, variables)) { 085 bounds[1] += Math.abs(instructor.getSameDaysPreference()); 086 } 087 return bounds; 088 } 089 090 @Override 091 public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) { 092 double value = 0.0; 093 for (Instructor instructor: getAssignedInstructors(assignment, variables)) 094 value += instructor.getContext(assignment).countSameDaysPreference(iDiffRoomWeight, iDiffTypeWeight); 095 return value; 096 } 097 098 @Override 099 public String getAbbreviation() { 100 return "SameDays"; 101 } 102}