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