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