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.ExamPlacement;
007 import net.sf.cpsolver.exam.model.ExamRoomPlacement;
008 import net.sf.cpsolver.ifs.util.DataProperties;
009
010 /**
011 * Room perturbation penalty. I.e., number of assigned rooms different from
012 * initial. Only applicable when {@link PerturbationPenalty#isMPP()} is true (minimal
013 * perturbation problem).
014 * <br><br>
015 * A weight of room perturbations (i.e., a penalty for
016 * an assignment of an exam to a room different from the initial one) can be
017 * set by problem property Exams.RoomPerturbationWeight, or in the input xml
018 * file, property roomPerturbationWeight).
019 *
020 * <br>
021 *
022 * @version ExamTT 1.2 (Examination Timetabling)<br>
023 * Copyright (C) 2008 - 2012 Tomas Muller<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 */
041 public class RoomPerturbationPenalty extends PerturbationPenalty {
042
043 @Override
044 public String getWeightName() {
045 return "Exams.RoomPerturbationWeight";
046 }
047
048 @Override
049 public String getXmlWeightName() {
050 return "roomPerturbationWeight";
051 }
052
053 @Override
054 public double getWeightDefault(DataProperties config) {
055 return 0.01;
056 }
057
058 @Override
059 public double getValue(ExamPlacement value, Set<ExamPlacement> conflicts) {
060 if (!isMPP()) return 0;
061 Exam exam = value.variable();
062 ExamPlacement initial = exam.getInitialAssignment();
063 if (initial == null) return 0;
064 int penalty = 0;
065 if (value.getRoomPlacements() != null)
066 for (ExamRoomPlacement rp : value.getRoomPlacements()) {
067 if (initial.getRoomPlacements() == null || !initial.getRoomPlacements().contains(rp))
068 penalty++;
069 }
070 return penalty;
071 }
072
073
074 @Override
075 public String toString() {
076 return (isMPP() ? "IRP:" + sDoubleFormat.format(getValue()) : "");
077 }
078
079 @Override
080 public boolean isPeriodCriterion() { return false; }
081 }