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.constraint.DepartmentSpreadConstraint;
008 import net.sf.cpsolver.coursett.model.Lecture;
009 import net.sf.cpsolver.coursett.model.Placement;
010 import net.sf.cpsolver.ifs.util.DataProperties;
011
012 /**
013 * Department balancing penalty. This criterion tries to balance classes of each
014 * department evenly. This means that for instance each department gets a fair
015 * amount of unpopular times like early morning or late afternoon. This criterion
016 * is counted by {@link DepartmentSpreadConstraint}.
017 * <br>
018 *
019 * @version CourseTT 1.2 (University Course Timetabling)<br>
020 * Copyright (C) 2006 - 2011 Tomas Muller<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 */
038 public class DepartmentBalancingPenalty extends SameSubpartBalancingPenalty {
039
040 @Override
041 public double getWeightDefault(DataProperties config) {
042 return 12.0 * config.getPropertyDouble("Comparator.DeptSpreadPenaltyWeight", 1.0);
043 }
044
045 @Override
046 public String getPlacementSelectionWeightName() {
047 return "Placement.DeptSpreadPenaltyWeight";
048 }
049
050 @Override
051 public double getValue(Placement value, Set<Placement> conflicts) {
052 return (value.variable().getDeptSpreadConstraint() == null ? 0.0 : value.variable().getDeptSpreadConstraint().getPenalty(value)) / 12.0;
053 }
054
055 @Override
056 public double getValue(Collection<Lecture> variables) {
057 double ret = 0;
058 Set<DepartmentSpreadConstraint> constraints = new HashSet<DepartmentSpreadConstraint>();
059 for (Lecture lect: variables)
060 if (lect.getDeptSpreadConstraint() != null && constraints.add(lect.getDeptSpreadConstraint()))
061 ret += lect.getDeptSpreadConstraint().getPenalty();
062 return ret / 12.0;
063 }
064 }