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.ifs.assignment.Assignment; 010import org.cpsolver.ifs.util.DataProperties; 011 012 013 014/** 015 * Room preferences. This criterion counts how well the room preferences are met. This is 016 * a sum of {@link Placement#getRoomPreference()} of the assigned classes. 017 * <br> 018 * 019 * @version CourseTT 1.3 (University Course Timetabling)<br> 020 * Copyright (C) 2006 - 2014 Tomas Muller<br> 021 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 022 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 023 * <br> 024 * This library is free software; you can redistribute it and/or modify 025 * it under the terms of the GNU Lesser General Public License as 026 * published by the Free Software Foundation; either version 3 of the 027 * License, or (at your option) any later version. <br> 028 * <br> 029 * This library is distributed in the hope that it will be useful, but 030 * WITHOUT ANY WARRANTY; without even the implied warranty of 031 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 032 * Lesser General Public License for more details. <br> 033 * <br> 034 * You should have received a copy of the GNU Lesser General Public 035 * License along with this library; if not see 036 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 037 */ 038public class RoomPreferences extends TimetablingCriterion { 039 040 @Override 041 public double getWeightDefault(DataProperties config) { 042 return config.getPropertyDouble("Comparator.RoomPreferenceWeight", 1.0); 043 } 044 045 @Override 046 public String getPlacementSelectionWeightName() { 047 return "Placement.RoomPreferenceWeight"; 048 } 049 050 private int preference(Placement value) { 051 int pref = value.getRoomPreference(); 052 if (pref < Constants.sPreferenceLevelRequired / 2) 053 return value.variable().getMinMaxRoomPreference()[0]; 054 else if (pref > Constants.sPreferenceLevelProhibited / 2) 055 return value.variable().getMinMaxRoomPreference()[1]; 056 else 057 return pref; 058 } 059 060 @Override 061 public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) { 062 if (value.variable().isCommitted()) return 0.0; 063 double ret = value.variable().getWeight() * preference(value); 064 if (conflicts != null) 065 for (Placement conflict: conflicts) 066 ret -= conflict.variable().getWeight() * preference(conflict); 067 return ret; 068 } 069 070 @Override 071 public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 072 double[] bounds = new double[] { 0.0, 0.0 }; 073 for (Lecture lect: variables) { 074 if (lect.isCommitted()) continue; 075 int[] p = lect.getMinMaxRoomPreference(); 076 bounds[0] += lect.getWeight() * p[0]; 077 bounds[1] += lect.getWeight() * p[1]; 078 } 079 return bounds; 080 } 081 082}