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; 010 011 012/** 013 * Room violations. This criterion counts how many times a prohibited room is assigned 014 * to a class in interactive timetabling. 015 * <br> 016 * 017 * @author Tomáš Müller 018 * @version CourseTT 1.3 (University Course Timetabling)<br> 019 * Copyright (C) 2006 - 2014 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 RoomViolations extends TimetablingCriterion { 038 039 protected boolean violation(Placement value) { 040 int pref = value.getRoomPreference(); 041 return pref > Constants.sPreferenceLevelProhibited / 2; 042 } 043 044 @Override 045 public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) { 046 if (value.variable().isCommitted()) return 0.0; 047 double ret = (violation(value) ? 1.0 : 0.0); 048 if (conflicts != null) 049 for (Placement conflict: conflicts) 050 ret -= (violation(conflict) ? 1.0 : 0.0); 051 return ret; 052 } 053 054 @Override 055 public double[] getBounds(Assignment<Lecture, Placement> assignment) { 056 return new double[] { getModel().variables().size(), 0.0 }; 057 } 058 059 @Override 060 public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 061 return new double[] { variables.size(), 0.0 }; 062 } 063 064}