001package org.cpsolver.exam.criteria; 002 003import java.util.Set; 004 005import org.cpsolver.exam.model.Exam; 006import org.cpsolver.exam.model.ExamPlacement; 007import org.cpsolver.exam.model.ExamRoomPlacement; 008import org.cpsolver.ifs.assignment.Assignment; 009import org.cpsolver.ifs.util.DataProperties; 010 011 012/** 013 * Room perturbation penalty. I.e., number of assigned rooms different from 014 * initial. Only applicable when {@link PerturbationPenalty#isMPP()} is true (minimal 015 * perturbation problem). 016 * <br><br> 017 * A weight of room perturbations (i.e., a penalty for 018 * an assignment of an exam to a room different from the initial one) can be 019 * set by problem property Exams.RoomPerturbationWeight, or in the input xml 020 * file, property roomPerturbationWeight). 021 * 022 * <br> 023 * 024 * @version ExamTT 1.3 (Examination Timetabling)<br> 025 * Copyright (C) 2008 - 2014 Tomáš Müller<br> 026 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 027 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 028 * <br> 029 * This library is free software; you can redistribute it and/or modify 030 * it under the terms of the GNU Lesser General Public License as 031 * published by the Free Software Foundation; either version 3 of the 032 * License, or (at your option) any later version. <br> 033 * <br> 034 * This library is distributed in the hope that it will be useful, but 035 * WITHOUT ANY WARRANTY; without even the implied warranty of 036 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 037 * Lesser General Public License for more details. <br> 038 * <br> 039 * You should have received a copy of the GNU Lesser General Public 040 * License along with this library; if not see 041 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 042 */ 043public class RoomPerturbationPenalty extends PerturbationPenalty { 044 045 @Override 046 public String getWeightName() { 047 return "Exams.RoomPerturbationWeight"; 048 } 049 050 @Override 051 public String getXmlWeightName() { 052 return "roomPerturbationWeight"; 053 } 054 055 @Override 056 public double getWeightDefault(DataProperties config) { 057 return 0.01; 058 } 059 060 @Override 061 public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) { 062 if (!isMPP()) return 0; 063 Exam exam = value.variable(); 064 ExamPlacement initial = exam.getInitialAssignment(); 065 if (initial == null) return 0; 066 int penalty = 0; 067 if (value.getRoomPlacements() != null) 068 for (ExamRoomPlacement rp : value.getRoomPlacements()) { 069 if (initial.getRoomPlacements() == null || !initial.getRoomPlacements().contains(rp)) 070 penalty++; 071 } 072 return penalty; 073 } 074 075 076 @Override 077 public String toString(Assignment<Exam, ExamPlacement> assignment) { 078 return (isMPP() ? "IRP:" + sDoubleFormat.format(getValue(assignment)) : ""); 079 } 080 081 @Override 082 public boolean isPeriodCriterion() { return false; } 083}