    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 * @version ExamTT 1.3 (Examination Timetabling)<br>
    024 *          Copyright (C) 2008 - 2014 Tomáš Müller<br>
    025 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    026 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    027 * <br>
    028 *          This library is free software; you can redistribute it and/or modify
    029 *          it under the terms of the GNU Lesser General Public License as
    030 *          published by the Free Software Foundation; either version 3 of the
    031 *          License, or (at your option) any later version. <br>
    032 * <br>
    033 *          This library is distributed in the hope that it will be useful, but
    034 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    035 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    036 *          Lesser General Public License for more details. <br>
    037 * <br>
    038 *          You should have received a copy of the GNU Lesser General Public
    039 *          License along with this library; if not see
    040 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    041 */
    042public class StudentNotAvailableConflicts extends StudentDirectConflicts {
    043
    044    @Override
    045    public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    046        Exam exam = value.variable();
    047        int penalty = 0;
    048        for (ExamStudent s : exam.getStudents()) {
    049            if (!s.isAvailable(value.getPeriod()))
    050                penalty++;
    051        }
    052        return penalty;
    053    }
    054
    055    @Override
    056    public String getName() {
    057        return "Not Available Conflicts";
    058    }
    059
    060    @Override
    061    public void getInfo(Assignment<Exam, ExamPlacement> assignment, Map<String, String> info) {
    062    }
    063
    064    @Override
    065    public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> exams) {
    066        double ret = 0;
    067        for (Exam exam: exams) {
    068            ExamPlacement placement = assignment.getValue(exam);
    069            if (placement != null) ret += getValue(assignment, placement, null);
    070        }
    071        return ret;
    072    }
    073
    074    @Override
    075    public String toString(Assignment<Exam, ExamPlacement> assignment) {
    076        return (getValue(assignment) <= 0.0 ? "" : "NA:" + sDoubleFormat.format(getValue(assignment)));
    077    }
    078
    079}