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