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