001package org.cpsolver.coursett.criteria; 002 003import java.util.Collection; 004import java.util.HashSet; 005import java.util.Set; 006 007import org.cpsolver.coursett.constraint.SpreadConstraint; 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/** 016 * Same subpart balancing penalty. This criterion tries to spread classes of each 017 * scheduling subpart in time. It also includes all other spread in time distribution 018 * constraints. This criterion is counted by {@link SpreadConstraint}. 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 SameSubpartBalancingPenalty extends TimetablingCriterion { 042 043 public SameSubpartBalancingPenalty() { 044 setValueUpdateType(ValueUpdateType.NoUpdate); 045 } 046 047 @Override 048 public double getWeightDefault(DataProperties config) { 049 return 12.0 * config.getPropertyDouble("Comparator.SpreadPenaltyWeight", 1.0); 050 } 051 052 @Override 053 public String getPlacementSelectionWeightName() { 054 return "Placement.SpreadPenaltyWeight"; 055 } 056 057 @Override 058 public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) { 059 double ret = 0.0; 060 for (SpreadConstraint sc: value.variable().getSpreadConstraints()) 061 ret += sc.getPenalty(assignment, value); 062 return ret / 12.0; 063 } 064 065 @Override 066 public double getValue(Assignment<Lecture, Placement> assignment) { 067 return super.getValue(assignment) / 12.0; 068 } 069 070 @Override 071 public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 072 double ret = 0; 073 Set<SpreadConstraint> constraints = new HashSet<SpreadConstraint>(); 074 for (Lecture lect: variables) { 075 for (SpreadConstraint sc: lect.getSpreadConstraints()) { 076 if (!constraints.add(sc)) continue; 077 ret += sc.getPenalty(assignment); 078 } 079 } 080 return ret / 12.0; 081 } 082 083 @Override 084 public double[] getBounds(Assignment<Lecture, Placement> assignment) { 085 return new double[] { 0.0, 0.0 }; 086 } 087 088 @Override 089 public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 090 return new double[] { 0.0, 0.0 }; 091 } 092}