001 package net.sf.cpsolver.exam.criteria; 002 003 import java.util.Set; 004 005 import net.sf.cpsolver.exam.model.ExamPlacement; 006 import net.sf.cpsolver.ifs.util.DataProperties; 007 008 /** 009 * Rotation penalty. I.e., an exam that has been in later period last times tries 010 * to be in an earlier period. 011 * <br><br> 012 * A weight for exam rotation penalty can be set by problem property 013 * Exams.RotationWeight, or in the input xml file, property examRotationWeight. 014 * 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 ExamRotationPenalty extends ExamCriterion { 038 039 @Override 040 public String getWeightName() { 041 return "Exams.RotationWeight"; 042 } 043 044 @Override 045 public String getXmlWeightName() { 046 return "examRotationWeight"; 047 } 048 049 @Override 050 public double getWeightDefault(DataProperties config) { 051 return 0.001; 052 } 053 054 @Override 055 public double getValue(ExamPlacement value, Set<ExamPlacement> conflicts) { 056 if (value.variable().getAveragePeriod() < 0) return 0; 057 return (1 + value.getPeriod().getIndex()) * (1 + value.variable().getAveragePeriod()); 058 } 059 060 @Override 061 public String toString() { 062 return "@P:" + sDoubleFormat.format(getWeightedValue()); 063 } 064 }