001 package net.sf.cpsolver.coursett.criteria;
002
003 import java.util.Collection;
004 import java.util.HashSet;
005 import java.util.Set;
006
007 import net.sf.cpsolver.coursett.Constants;
008 import net.sf.cpsolver.coursett.constraint.InstructorConstraint;
009 import net.sf.cpsolver.coursett.model.Lecture;
010 import net.sf.cpsolver.coursett.model.Placement;
011 import net.sf.cpsolver.coursett.model.TimetableModel;
012
013 import net.sf.cpsolver.ifs.util.DataProperties;
014
015 /**
016 * Bact-to-back instructor preferences. This criterion counts cases when an instructor
017 * has to teach two classes in two rooms that are too far a part. This objective
018 * is counter by the {@link InstructorConstraint}
019 * (see {@link InstructorConstraint#getDistancePreference(Placement, Placement)}).
020 * <br>
021 *
022 * @version CourseTT 1.2 (University Course Timetabling)<br>
023 * Copyright (C) 2006 - 2011 Tomas Muller<br>
024 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
025 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
026 * <br>
027 * This library is free software; you can redistribute it and/or modify
028 * it under the terms of the GNU Lesser General Public License as
029 * published by the Free Software Foundation; either version 3 of the
030 * License, or (at your option) any later version. <br>
031 * <br>
032 * This library is distributed in the hope that it will be useful, but
033 * WITHOUT ANY WARRANTY; without even the implied warranty of
034 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
035 * Lesser General Public License for more details. <br>
036 * <br>
037 * You should have received a copy of the GNU Lesser General Public
038 * License along with this library; if not see
039 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
040 */
041 public class BackToBackInstructorPreferences extends TimetablingCriterion {
042
043 public BackToBackInstructorPreferences() {
044 iValueUpdateType = ValueUpdateType.NoUpdate;
045 }
046
047 @Override
048 public double getWeightDefault(DataProperties config) {
049 return Constants.sPreferenceLevelDiscouraged * config.getPropertyDouble("Comparator.DistanceInstructorPreferenceWeight", 1.0);
050 }
051
052 @Override
053 public String getPlacementSelectionWeightName() {
054 return "Placement.DistanceInstructorPreferenceWeight";
055 }
056
057 protected int penalty(Placement value) {
058 int ret = 0;
059 for (InstructorConstraint ic: value.variable().getInstructorConstraints()) {
060 ret += ic.getPreference(value);
061 }
062 return ret;
063 }
064
065 @Override
066 public double getValue(Placement value, Set<Placement> conflicts) {
067 double ret = penalty(value);
068 if (conflicts != null)
069 for (Placement conflict: conflicts)
070 ret -= penalty(conflict);
071 return ret;
072 }
073
074 @Override
075 public double getValue(Collection<Lecture> variables) {
076 double ret = 0;
077 Set<InstructorConstraint> constraints = new HashSet<InstructorConstraint>();
078 for (Lecture lect: variables) {
079 for (InstructorConstraint ic: lect.getInstructorConstraints()) {
080 if (!constraints.add(ic)) continue;
081 ret += ic.getPreference();
082 }
083 }
084 return ret;
085 }
086
087 @Override
088 protected double[] computeBounds() {
089 double[] bounds = new double[] { 0.0, 0.0 };
090 for (InstructorConstraint ic: ((TimetableModel)getModel()).getInstructorConstraints())
091 bounds[1] += ic.getWorstPreference();
092 return bounds;
093 }
094
095 @Override
096 public double[] getBounds(Collection<Lecture> variables) {
097 double[] bounds = new double[] { 0.0, 0.0 };
098 Set<InstructorConstraint> constraints = new HashSet<InstructorConstraint>();
099 for (Lecture lect: variables) {
100 for (InstructorConstraint ic: lect.getInstructorConstraints()) {
101 if (!constraints.add(ic)) continue;
102 bounds[1] += ic.getWorstPreference();
103 }
104 }
105 return bounds;
106 }
107 }