001package org.cpsolver.exam.criteria;
002
003import java.util.Map;
004import java.util.Set;
005
006import org.cpsolver.exam.model.Exam;
007import org.cpsolver.exam.model.ExamInstructor;
008import org.cpsolver.exam.model.ExamPlacement;
009import org.cpsolver.ifs.assignment.Assignment;
010
011
012/**
013 * Number of direct instructor conflicts caused by the fact that an instructor is
014 * not available.
015 * <br><br>
016 * Direct instructor conflict weight can be set by problem property
017 * Exams.InstructorDirectConflictWeight, or in the input xml file, property
018 * instructorDirectConflictWeight.
019 * 
020 * <br>
021 * 
022 * @version ExamTT 1.3 (Examination Timetabling)<br>
023 *          Copyright (C) 2008 - 2014 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 */
041public class InstructorNotAvailableConflicts extends InstructorDirectConflicts {
042
043    @Override
044    public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
045        Exam exam = value.variable();
046        // if (!exam.isAllowDirectConflicts()) return 0;
047        int penalty = 0;
048        for (ExamInstructor s : exam.getInstructors()) {
049            if (!s.isAvailable(value.getPeriod()))
050                penalty++;
051        }
052        return penalty;
053    }
054
055    @Override
056    public String getName() {
057        return "Instructor Not Available Conflicts";
058    }
059    
060    @Override
061    public void getInfo(Assignment<Exam, ExamPlacement> assignment, Map<String, String> info) {
062    }
063
064    @Override
065    public String toString(Assignment<Exam, ExamPlacement> assignment) {
066        return (getValue(assignment) <= 0.0 ? "" : "iNA:" + sDoubleFormat.format(getValue(assignment)));
067    }
068}