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.coursett.model.TimeLocation; 009import org.cpsolver.ifs.assignment.Assignment; 010import org.cpsolver.ifs.util.DataProperties; 011 012 013/** 014 * Time preferences. This criterion counts how well the time preferences are met. This is 015 * a sum of {@link TimeLocation#getNormalizedPreference()} of the assigned classes. 016 * <br> 017 * 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 TimePreferences extends TimetablingCriterion { 038 039 @Override 040 public double getWeightDefault(DataProperties config) { 041 return config.getPropertyDouble("Comparator.TimePreferenceWeight", 1.0); 042 } 043 044 @Override 045 public String getPlacementSelectionWeightName() { 046 return "Placement.TimePreferenceWeight"; 047 } 048 049 private double preference(Placement value) { 050 return value.getTimePenalty(); 051 } 052 053 @Override 054 public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) { 055 if (value.variable().isCommitted()) return 0.0; 056 double ret = value.variable().getWeight() * preference(value); 057 if (conflicts != null) 058 for (Placement conflict: conflicts) 059 ret -= conflict.variable().getWeight() * preference(conflict); 060 return ret; 061 } 062 063 @Override 064 public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 065 double[] bounds = new double[] { 0.0, 0.0 }; 066 for (Lecture lect: variables) { 067 if (lect.isCommitted()) continue; 068 double[] p = lect.getMinMaxTimePreference(); 069 bounds[1] += lect.getWeight() * (p[1] - p[0]); 070 } 071 return bounds; 072 } 073 074}