001    package net.sf.cpsolver.exam.criteria;
002    
003    import java.util.Map;
004    import java.util.Set;
005    
006    import net.sf.cpsolver.exam.model.Exam;
007    import net.sf.cpsolver.exam.model.ExamPlacement;
008    import net.sf.cpsolver.exam.model.ExamStudent;
009    import net.sf.cpsolver.ifs.util.DataProperties;
010    
011    /**
012     * Number of more than two exams a day student conflicts. I.e., when an
013     * exam is attended by a student student that attends two or more other
014     * exams at the same day.
015     * <br><br>
016     * More than two exams a day student conflict weight can be set by
017     * problem property Exams.MoreThanTwoADayWeight, or in the input
018     * xml file, property moreThanTwoADayWeight.
019     * 
020     * <br>
021     * 
022     * @version ExamTT 1.2 (Examination Timetabling)<br>
023     *          Copyright (C) 2008 - 2012 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     */
041    public class StudentMoreThan2ADayConflicts extends ExamCriterion {
042    
043        @Override
044        public String getWeightName() {
045            return "Exams.MoreThanTwoADayWeight";
046        }
047        
048        @Override
049        public double getWeightDefault(DataProperties config) {
050            return 100.0;
051        }
052    
053        @Override
054        public double getValue(ExamPlacement value, Set<ExamPlacement> conflicts) {
055            Exam exam = value.variable();
056            int penalty = 0;
057            for (ExamStudent s : exam.getStudents()) {
058                Set<Exam> exams = s.getExamsADay(value.getPeriod());
059                int nrExams = exams.size() + (exams.contains(exam) ? 0 : 1);
060                if (nrExams > 2)
061                    penalty++;
062            }
063            return penalty;
064        }
065        
066        @Override
067        public String getName() {
068            return "More Than 2 A Day Conflicts";
069        }
070        
071        @Override
072        public String getXmlWeightName() {
073            return "moreThanTwoADayWeight";
074        }
075    
076        @Override
077        public void getInfo(Map<String, String> info) {
078            if (getValue() != 0.0)
079                info.put(getName(), sDoubleFormat.format(getValue()));
080        }
081        
082        @Override
083        public String toString() {
084            return "M2D:" + sDoubleFormat.format(getValue());
085        }
086    }