001 package net.sf.cpsolver.coursett.criteria;
002
003 import java.util.Collection;
004 import java.util.Set;
005
006 import net.sf.cpsolver.coursett.Constants;
007 import net.sf.cpsolver.coursett.model.Lecture;
008 import net.sf.cpsolver.coursett.model.Placement;
009
010 /**
011 * Room violations. This criterion counts how many times a prohibited room is assigned
012 * to a class in interactive timetabling.
013 * <br>
014 *
015 * @version CourseTT 1.2 (University Course Timetabling)<br>
016 * Copyright (C) 2006 - 2011 Tomas Muller<br>
017 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
018 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
019 * <br>
020 * This library is free software; you can redistribute it and/or modify
021 * it under the terms of the GNU Lesser General Public License as
022 * published by the Free Software Foundation; either version 3 of the
023 * License, or (at your option) any later version. <br>
024 * <br>
025 * This library is distributed in the hope that it will be useful, but
026 * WITHOUT ANY WARRANTY; without even the implied warranty of
027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
028 * Lesser General Public License for more details. <br>
029 * <br>
030 * You should have received a copy of the GNU Lesser General Public
031 * License along with this library; if not see
032 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
033 */
034 public class RoomViolations extends TimetablingCriterion {
035
036 protected boolean violation(Placement value) {
037 int pref = value.getRoomPreference();
038 return pref > Constants.sPreferenceLevelProhibited / 2;
039 }
040
041 @Override
042 public double getValue(Placement value, Set<Placement> conflicts) {
043 if (value.variable().isCommitted()) return 0.0;
044 double ret = (violation(value) ? 1.0 : 0.0);
045 if (conflicts != null)
046 for (Placement conflict: conflicts)
047 ret -= (violation(conflict) ? 1.0 : 0.0);
048 return ret;
049 }
050
051 @Override
052 public double[] getBounds() {
053 return new double[] { getModel().variables().size(), 0.0 };
054 }
055
056 @Override
057 public double[] getBounds(Collection<Lecture> variables) {
058 return new double[] { variables.size(), 0.0 };
059 }
060
061 }