    001package org.cpsolver.coursett.criteria;
    002
    003import java.util.Collection;
    004import java.util.Set;
    005
    006import org.cpsolver.coursett.model.Lecture;
    007import org.cpsolver.coursett.model.Placement;
    008import org.cpsolver.ifs.assignment.Assignment;
    009import org.cpsolver.ifs.util.DataProperties;
    010
    011
    012
    013/**
    014 * Room preferences. This criterion counts how well the room preferences are met. This is
    015 * a sum of {@link Placement#getRoomPreference()} of the assigned classes.
    016 * <br>
    017 *
    018 * @author  Tomáš Müller
    019 * @version CourseTT 1.3 (University Course Timetabling)<br>
    020 *          Copyright (C) 2006 - 2014 Tomáš Müller<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        return value.getRoomPenalty();
    052    }
    053
    054    @Override
    055    public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    056        if (value.variable().isCommitted()) return 0.0;
    057        double ret = value.variable().getWeight() * preference(value);
    058        if (conflicts != null)
    059            for (Placement conflict: conflicts)
    060                ret -= conflict.variable().getWeight() * preference(conflict);
    061        return ret;
    062    }
    063
    064    @Override
    065    public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    066        double[] bounds = new double[] { 0.0, 0.0 };
    067        for (Lecture lect: variables) {
    068            if (lect.isCommitted()) continue;
    069            int[] p = lect.getMinMaxRoomPreference();
    070            bounds[1] += lect.getWeight() * (p[1] - p[0]);
    071        }
    072        return bounds;
    073    }
    074
    075}