    001package org.cpsolver.coursett.criteria.placement;
    002
    003import java.util.Set;
    004
    005import org.cpsolver.coursett.model.Lecture;
    006import org.cpsolver.coursett.model.Placement;
    007import org.cpsolver.ifs.assignment.Assignment;
    008import org.cpsolver.ifs.util.DataProperties;
    009
    010
    011/**
    012 * Difference between proposed and best time assignment. Time assignments
    013 * that are do not maximize time preference are penalized by the difference
    014 * in the preference.
    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 DeltaTimePreference extends PlacementSelectionCriterion {
    037    private double iLevel1DefaultWeight = 0.0;
    038
    039    @Override
    040    public void configure(DataProperties properties) {
    041        super.configure(properties);
    042        iLevel1DefaultWeight = properties.getPropertyDouble("Comparator.TimePreferenceWeight", 1.0) / 2.0;
    043    }
    044
    045    @Override
    046    public String getPlacementSelectionWeightName() {
    047        return "Placement.DeltaTimePreferenceWeight";
    048    }
    049
    050    @Override
    051    public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    052        double ret = value.variable().getWeight() * (value.getTimeLocation().getNormalizedPreference() - value.variable().getBestTimePreference());
    053        if (conflicts != null)
    054            for (Placement placement : conflicts) {
    055                double timePref = placement.getTimeLocation().getNormalizedPreference();
    056                ret -= placement.variable().getWeight() * (timePref - placement.variable().getBestTimePreference());
    057            }
    058        return ret;
    059    }
    060
    061    @Override
    062    public double getPlacementSelectionWeightDefault(int level) {
    063        return (level == 0 ? iLevel1DefaultWeight : 0.0);
    064    }
    065}