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.ExamModel;
009import org.cpsolver.exam.model.ExamPlacement;
010import org.cpsolver.ifs.assignment.Assignment;
011import org.cpsolver.ifs.util.DataProperties;
012
013
014/**
015 * Number of more than two exams a day instructor conflicts. I.e., when an
016 * exam is attended by an instructor student that attends two or more other
017 * exams at the same day.
018 * <br><br>
019 * More than two exams a day instructor conflict weight can be set by
020 * problem property Exams.InstructorMoreThanTwoADayWeight, or in the input
021 * xml file, property instructorMoreThanTwoADayWeight.
022 * 
023 * <br>
024 * 
025 * @version ExamTT 1.3 (Examination Timetabling)<br>
026 *          Copyright (C) 2008 - 2014 Tomas Muller<br>
027 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
028 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
029 * <br>
030 *          This library is free software; you can redistribute it and/or modify
031 *          it under the terms of the GNU Lesser General Public License as
032 *          published by the Free Software Foundation; either version 3 of the
033 *          License, or (at your option) any later version. <br>
034 * <br>
035 *          This library is distributed in the hope that it will be useful, but
036 *          WITHOUT ANY WARRANTY; without even the implied warranty of
037 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
038 *          Lesser General Public License for more details. <br>
039 * <br>
040 *          You should have received a copy of the GNU Lesser General Public
041 *          License along with this library; if not see
042 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
043 */
044public class InstructorMoreThan2ADayConflicts extends StudentMoreThan2ADayConflicts {
045
046    @Override
047    public String getWeightName() {
048        return "Exams.InstructorMoreThanTwoADayWeight";
049    }
050    
051    @Override
052    public String getXmlWeightName() {
053        return "instructorMoreThanTwoADayWeight";
054    }
055
056    @Override
057    public double getWeightDefault(DataProperties config) {
058        return 100.0;
059    }
060
061    @Override
062    public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
063        Exam exam = value.variable();
064        int penalty = 0;
065        Map<ExamInstructor, Set<Exam>> instructors = ((ExamModel)getModel()).getInstructorsOfDay(assignment, value.getPeriod());
066        for (ExamInstructor s : exam.getInstructors()) {
067            Set<Exam> exams = instructors.get(s);
068            if (exams == null || exams.size() < 2) continue;
069            int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
070            if (nrExams > 2)
071                penalty++;
072        }
073        /*
074        for (ExamInstructor s : exam.getInstructors()) {
075            Set<Exam> exams = s.getExamsADay(assignment, value.getPeriod());
076            int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
077            if (nrExams > 2)
078                penalty++;
079        }
080        */
081        return penalty;
082    }
083
084    @Override
085    public String getName() {
086        return "Instructor More Than 2 A Day Conflicts";
087    }
088
089    @Override
090    public String toString(Assignment<Exam, ExamPlacement> assignment) {
091        return "iM2D:" + sDoubleFormat.format(getValue(assignment));
092    }
093}