001package net.sf.cpsolver.exam.criteria;
002
003import java.util.Map;
004import java.util.Set;
005
006import net.sf.cpsolver.exam.model.Exam;
007import net.sf.cpsolver.exam.model.ExamInstructor;
008import net.sf.cpsolver.exam.model.ExamPlacement;
009import net.sf.cpsolver.ifs.util.DataProperties;
010
011/**
012 * Number of direct instructor conflicts. I.e., number of cases when an
013 * exam is attended by an instructor that attends some other exam at the
014 * same period.
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.2 (Examination Timetabling)<br>
023 *          Copyright (C) 2008 - 2012 Tomáš Müller<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 InstructorDirectConflicts extends StudentDirectConflicts {
042
043    @Override
044    public String getWeightName() {
045        return "Exams.InstructorDirectConflictWeight";
046    }
047    
048    @Override
049    public String getXmlWeightName() {
050        return "instructorDirectConflictWeight";
051    }
052
053    @Override
054    public double getWeightDefault(DataProperties config) {
055        return 1000.0;
056    }
057
058    @Override
059    public double getValue(ExamPlacement value, Set<ExamPlacement> conflicts) {
060        Exam exam = value.variable();
061        int penalty = 0;
062        for (ExamInstructor s : exam.getInstructors()) {
063            Set<Exam> exams = s.getExams(value.getPeriod());
064            int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
065            if (nrExams > 1)
066                penalty++;
067        }
068        return penalty;
069    }
070
071    @Override
072    public String getName() {
073        return "Instructor Direct Conflicts";
074    }
075    
076    @Override
077    public void getInfo(Map<String, String> info) {
078        InstructorNotAvailableConflicts na = (InstructorNotAvailableConflicts)getModel().getCriterion(InstructorNotAvailableConflicts.class);
079        if (getValue() != 0.0 || (na != null && na.getValue() != 0.0))
080            info.put(getName(), sDoubleFormat.format(getValue() + (na == null ? 0.0 : na.getValue())) +
081                    (na == null || na.getValue() == 0.0 ? "" : " (" + sDoubleFormat.format(na.getValue()) + " N/A)"));
082    }
083    
084    @Override
085    public String toString() {
086        return "iDC:" + sDoubleFormat.format(getValue());
087    }
088}