    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.ExamInstructor;
    009import org.cpsolver.exam.model.ExamPlacement;
    010import org.cpsolver.ifs.assignment.Assignment;
    011
    012
    013/**
    014 * Number of direct instructor conflicts caused by the fact that an instructor is
    015 * not available.
    016 * <br><br>
    017 * Direct instructor conflict weight can be set by problem property
    018 * Exams.InstructorDirectConflictWeight, or in the input xml file, property
    019 * instructorDirectConflictWeight.
    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 InstructorNotAvailableConflicts extends InstructorDirectConflicts {
    043
    044    @Override
    045    public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    046        Exam exam = value.variable();
    047        // if (!exam.isAllowDirectConflicts()) return 0;
    048        int penalty = 0;
    049        for (ExamInstructor s : exam.getInstructors()) {
    050            if (!s.isAvailable(value.getPeriod()))
    051                penalty++;
    052        }
    053        return penalty;
    054    }
    055
    056    @Override
    057    public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> exams) {
    058        double ret = 0;
    059        for (Exam exam: exams) {
    060            ExamPlacement placement = assignment.getValue(exam);
    061            if (placement != null) ret += getValue(assignment, placement, null);
    062        }
    063        return ret;
    064    }
    065
    066    @Override
    067    public String getName() {
    068        return "Instructor Not Available Conflicts";
    069    }
    070
    071    @Override
    072    public void getInfo(Assignment<Exam, ExamPlacement> assignment, Map<String, String> info) {
    073    }
    074
    075    @Override
    076    public String toString(Assignment<Exam, ExamPlacement> assignment) {
    077        return (getValue(assignment) <= 0.0 ? "" : "iNA:" + sDoubleFormat.format(getValue(assignment)));
    078    }
    079}