    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 * @version CourseTT 1.3 (University Course Timetabling)<br>
    018 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    019 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    020 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    021 * <br>
    022 *          This library is free software; you can redistribute it and/or modify
    023 *          it under the terms of the GNU Lesser General Public License as
    024 *          published by the Free Software Foundation; either version 3 of the
    025 *          License, or (at your option) any later version. <br>
    026 * <br>
    027 *          This library is distributed in the hope that it will be useful, but
    028 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    029 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    030 *          Lesser General Public License for more details. <br>
    031 * <br>
    032 *          You should have received a copy of the GNU Lesser General Public
    033 *          License along with this library; if not see
    034 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    035 */
    036public class RoomViolations extends TimetablingCriterion {
    037
    038    protected boolean violation(Placement value) {
    039        int pref = value.getRoomPreference();
    040        return pref > Constants.sPreferenceLevelProhibited / 2;
    041    }
    042
    043    @Override
    044    public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    045        if (value.variable().isCommitted()) return 0.0;
    046        double ret = (violation(value) ? 1.0 : 0.0);
    047        if (conflicts != null)
    048            for (Placement conflict: conflicts)
    049                ret -= (violation(conflict) ? 1.0 : 0.0);
    050        return ret;
    051    }
    052
    053    @Override
    054    public double[] getBounds(Assignment<Lecture, Placement> assignment) {
    055        return new double[] { getModel().variables().size(), 0.0 };
    056    }
    057
    058    @Override
    059    public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    060        return new double[] { variables.size(), 0.0 };
    061    }
    062
    063}