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 Room. This criterion counts how well are the same room preferences that are set on an {@link Instructor} met 015 * (counting {@link Instructor#countSameRooms(Assignment, TeachingAssignment, 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 SameRoom extends InstructorSchedulingCriterion { 038 private double iDiffTypeWeight = 0.5; 039 040 public SameRoom() { 041 setValueUpdateType(ValueUpdateType.NoUpdate); 042 } 043 044 @Override 045 public void configure(DataProperties properties) { 046 super.configure(properties); 047 iDiffTypeWeight = properties.getPropertyDouble("SameRoom.DifferentTypeWeight", 0.5); 048 } 049 050 @Override 051 public double getWeightDefault(DataProperties config) { 052 return 1.0; 053 } 054 055 /** 056 * Different instructional type weight 057 * @return penalty for teaching two same-room that are of different instructional type 058 */ 059 public double getDifferentTypeWeight() { return iDiffTypeWeight; } 060 061 @Override 062 public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) { 063 return value.getInstructor().countSameRooms(assignment, value, iDiffTypeWeight); 064 } 065 066 @Override 067 protected double[] computeBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) { 068 double[] bounds = new double[] { 0.0, 0.0 }; 069 for (Instructor instructor: ((InstructorSchedulingModel)getModel()).getInstructors()) { 070 bounds[1] += Math.abs(instructor.getSameRoomPreference()); 071 } 072 return bounds; 073 } 074 075 @Override 076 public double[] getBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) { 077 double[] bounds = new double[] { 0.0, 0.0 }; 078 for (Instructor instructor: getInstructors(assignment, variables)) { 079 bounds[1] += Math.abs(instructor.getSameRoomPreference()); 080 } 081 return bounds; 082 } 083 084 @Override 085 public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) { 086 double value = 0.0; 087 for (Instructor instructor: getAssignedInstructors(assignment, variables)) 088 value += instructor.getContext(assignment).countSameRoomPreference(iDiffTypeWeight); 089 return value; 090 } 091 092 @Override 093 public String getAbbreviation() { 094 return "SameRoom"; 095 } 096}