001package org.cpsolver.exam.criteria;
002
003import java.util.Collection;
004import java.util.Map;
005import java.util.Set;
006
007import org.cpsolver.exam.model.Exam;
008import org.cpsolver.exam.model.ExamPlacement;
009import org.cpsolver.exam.model.ExamStudent;
010import org.cpsolver.ifs.assignment.Assignment;
011
012
013/**
014 * Number of direct student conflicts caused by the fact that a student is
015 * not available.
016 * <br><br>
017 * Direct student conflict weight can be set by problem property
018 * Exams.DirectConflictWeight, or in the input xml file, property
019 * directConflictWeight.
020 * 
021 * <br>
022 * 
023 * @author  Tomáš Müller
024 * @version ExamTT 1.3 (Examination Timetabling)<br>
025 *          Copyright (C) 2008 - 2014 Tomáš Müller<br>
026 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
027 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
028 * <br>
029 *          This library is free software; you can redistribute it and/or modify
030 *          it under the terms of the GNU Lesser General Public License as
031 *          published by the Free Software Foundation; either version 3 of the
032 *          License, or (at your option) any later version. <br>
033 * <br>
034 *          This library is distributed in the hope that it will be useful, but
035 *          WITHOUT ANY WARRANTY; without even the implied warranty of
036 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
037 *          Lesser General Public License for more details. <br>
038 * <br>
039 *          You should have received a copy of the GNU Lesser General Public
040 *          License along with this library; if not see
041 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
042 */
043public class StudentNotAvailableConflicts extends StudentDirectConflicts {
044
045    @Override
046    public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
047        Exam exam = value.variable();
048        int penalty = 0;
049        for (ExamStudent s : exam.getStudents()) {
050            if (!s.isAvailable(value.getPeriod()))
051                penalty++;
052        }
053        return penalty;
054    }
055
056    @Override
057    public String getName() {
058        return "Not Available Conflicts";
059    }
060    
061    @Override
062    public void getInfo(Assignment<Exam, ExamPlacement> assignment, Map<String, String> info) {
063    }
064    
065    @Override
066    public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> exams) {
067        double ret = 0;
068        for (Exam exam: exams) {
069            ExamPlacement placement = assignment.getValue(exam);
070            if (placement != null) ret += getValue(assignment, placement, null);
071        }
072        return ret;
073    }
074
075    @Override
076    public String toString(Assignment<Exam, ExamPlacement> assignment) {
077        return (getValue(assignment) <= 0.0 ? "" : "NA:" + sDoubleFormat.format(getValue(assignment)));
078    }
079
080}