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 * @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 DeltaTimePreference extends PlacementSelectionCriterion {
038    private double iLevel1DefaultWeight = 0.0;
039    
040    @Override
041    public void configure(DataProperties properties) {   
042        super.configure(properties);
043        iLevel1DefaultWeight = properties.getPropertyDouble("Comparator.TimePreferenceWeight", 1.0) / 2.0;
044    }
045
046    @Override
047    public String getPlacementSelectionWeightName() {
048        return "Placement.DeltaTimePreferenceWeight";
049    }
050
051    @Override
052    public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
053        double ret = value.variable().getWeight() * (value.getTimeLocation().getNormalizedPreference() - value.variable().getBestTimePreference());
054        if (conflicts != null)
055            for (Placement placement : conflicts) {
056                double timePref = placement.getTimeLocation().getNormalizedPreference();
057                ret -= placement.variable().getWeight() * (timePref - placement.variable().getBestTimePreference());
058            }
059        return ret;
060    }
061
062    @Override
063    public double getPlacementSelectionWeightDefault(int level) {
064        return (level == 0 ? iLevel1DefaultWeight : 0.0);
065    }
066}