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