001package org.cpsolver.coursett.criteria; 002 003import java.util.Collection; 004import java.util.Set; 005 006import org.cpsolver.coursett.Constants; 007import org.cpsolver.coursett.model.Lecture; 008import org.cpsolver.coursett.model.Placement; 009import org.cpsolver.coursett.model.RoomLocation; 010import org.cpsolver.coursett.preference.PreferenceCombination; 011import org.cpsolver.ifs.assignment.Assignment; 012import org.cpsolver.ifs.util.DataProperties; 013 014 015/** 016 * Too big rooms. This criterion counts cases where a class is placed in a room 017 * that is too big for the class. In general, a room is discouraged (in this 018 * criterion) if it has 25% more space than needed, strongly discouraged 019 * if it has more than 50% space than needed. Needed space is counted as the space 020 * of the smallest room in which a class can take place. 021 * <br> 022 * 023 * @version CourseTT 1.3 (University Course Timetabling)<br> 024 * Copyright (C) 2006 - 2014 Tomas Muller<br> 025 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 026 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 027 * <br> 028 * This library is free software; you can redistribute it and/or modify 029 * it under the terms of the GNU Lesser General Public License as 030 * published by the Free Software Foundation; either version 3 of the 031 * License, or (at your option) any later version. <br> 032 * <br> 033 * This library is distributed in the hope that it will be useful, but 034 * WITHOUT ANY WARRANTY; without even the implied warranty of 035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 036 * Lesser General Public License for more details. <br> 037 * <br> 038 * You should have received a copy of the GNU Lesser General Public 039 * License along with this library; if not see 040 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 041 */ 042public class TooBigRooms extends TimetablingCriterion { 043 044 @Override 045 public double getWeightDefault(DataProperties config) { 046 return config.getPropertyDouble("Comparator.TooBigRoomWeight", 0.1); 047 } 048 049 @Override 050 public String getPlacementSelectionWeightName() { 051 return "Placement.TooBigRoomWeight"; 052 } 053 054 @Override 055 public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) { 056 double ret = getTooBigRoomPreference(value); 057 if (conflicts != null) 058 for (Placement conflict: conflicts) 059 ret -= getTooBigRoomPreference(conflict); 060 return ret; 061 } 062 063 @Override 064 public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 065 double[] bounds = new double[] { 0.0, 0.0 }; 066 for (Lecture lect: variables) { 067 if (lect.getNrRooms() > 0) 068 bounds[0] += Constants.sPreferenceLevelStronglyDiscouraged; 069 } 070 return bounds; 071 } 072 073 public static long getDiscouragedRoomSize(Placement value) { 074 return Math.round(1.25 * value.variable().minRoomSize()); 075 } 076 077 public static long getStronglyDiscouragedRoomSize(Placement value) { 078 return Math.round(1.5 * value.variable().minRoomSize()); 079 } 080 081 public static int getTooBigRoomPreference(Placement value) { 082 if (value.isMultiRoom()) { 083 PreferenceCombination pref = PreferenceCombination.getDefault(); 084 for (RoomLocation r : value.getRoomLocations()) { 085 if (r.getRoomSize() > getStronglyDiscouragedRoomSize(value)) 086 pref.addPreferenceInt(Constants.sPreferenceLevelStronglyDiscouraged); 087 else if (r.getRoomSize() > getDiscouragedRoomSize(value)) 088 pref.addPreferenceInt(Constants.sPreferenceLevelDiscouraged); 089 } 090 return pref.getPreferenceInt(); 091 } else { 092 if (value.getRoomLocation().getRoomSize() > getStronglyDiscouragedRoomSize(value)) 093 return Constants.sPreferenceLevelStronglyDiscouraged; 094 else if (value.getRoomLocation().getRoomSize() > getDiscouragedRoomSize(value)) 095 return Constants.sPreferenceLevelDiscouraged; 096 else 097 return Constants.sPreferenceLevelNeutral; 098 } 099 } 100 101}