001 package net.sf.cpsolver.exam.criteria; 002 003 import java.util.Set; 004 005 import net.sf.cpsolver.exam.model.Exam; 006 import net.sf.cpsolver.exam.model.ExamPeriodPlacement; 007 import net.sf.cpsolver.exam.model.ExamPlacement; 008 import net.sf.cpsolver.ifs.util.DataProperties; 009 010 /** 011 * Cost for using a period. See {@link ExamPeriodPlacement#getPenalty()} for more details. 012 * <br><br> 013 * A weight for period penalty can be set by problem property 014 * Exams.PeriodWeight, or in the input xml file, property periodWeight. 015 * 016 * <br> 017 * 018 * @version ExamTT 1.2 (Examination Timetabling)<br> 019 * Copyright (C) 2008 - 2012 Tomas Muller<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 */ 037 public class PeriodPenalty extends ExamCriterion { 038 039 @Override 040 public String getWeightName() { 041 return "Exams.PeriodWeight"; 042 } 043 044 @Override 045 public String getXmlWeightName() { 046 return "periodWeight"; 047 } 048 049 @Override 050 public double getWeightDefault(DataProperties config) { 051 return 1.0; 052 } 053 054 @Override 055 public double getValue(ExamPlacement value, Set<ExamPlacement> conflicts) { 056 return value.getPeriodPlacement().getPenalty(); 057 } 058 059 @Override 060 protected void computeBounds() { 061 iBounds = new double[] { 0.0, 0.0 }; 062 for (Exam exam : getModel().variables()) { 063 if (!exam.getPeriodPlacements().isEmpty()) { 064 int minPenalty = Integer.MAX_VALUE, maxPenalty = Integer.MIN_VALUE; 065 for (ExamPeriodPlacement periodPlacement : exam.getPeriodPlacements()) { 066 minPenalty = Math.min(minPenalty, periodPlacement.getPenalty()); 067 maxPenalty = Math.max(maxPenalty, periodPlacement.getPenalty()); 068 } 069 iBounds[0] += minPenalty; 070 iBounds[1] += maxPenalty; 071 } 072 } 073 } 074 075 @Override 076 public String toString() { 077 return "PP:" + sDoubleFormat.format(getWeightedValue()); 078 } 079 }