    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 * @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 InstructorNotAvailableConflicts extends InstructorDirectConflicts {
    044
    045    @Override
    046    public double getValue(Assignment<Exam, ExamPlacement> assignment, ExamPlacement value, Set<ExamPlacement> conflicts) {
    047        Exam exam = value.variable();
    048        // if (!exam.isAllowDirectConflicts()) return 0;
    049        int penalty = 0;
    050        for (ExamInstructor s : exam.getInstructors()) {
    051            if (!s.isAvailable(value.getPeriod()))
    052                penalty++;
    053        }
    054        return penalty;
    055    }
    056
    057    @Override
    058    public double getValue(Assignment<Exam, ExamPlacement> assignment, Collection<Exam> exams) {
    059        double ret = 0;
    060        for (Exam exam: exams) {
    061            ExamPlacement placement = assignment.getValue(exam);
    062            if (placement != null) ret += getValue(assignment, placement, null);
    063        }
    064        return ret;
    065    }
    066
    067    @Override
    068    public String getName() {
    069        return "Instructor Not Available Conflicts";
    070    }
    071
    072    @Override
    073    public void getInfo(Assignment<Exam, ExamPlacement> assignment, Map<String, String> info) {
    074    }
    075
    076    @Override
    077    public String toString(Assignment<Exam, ExamPlacement> assignment) {
    078        return (getValue(assignment) <= 0.0 ? "" : "iNA:" + sDoubleFormat.format(getValue(assignment)));
    079    }
    080}