    001package org.cpsolver.coursett.heuristics;
    002
    003import org.cpsolver.coursett.model.Lecture;
    004import org.cpsolver.coursett.model.Placement;
    005import org.cpsolver.ifs.criteria.Criterion;
    006import org.cpsolver.ifs.model.Model;
    007import org.cpsolver.ifs.solution.GeneralSolutionComparator;
    008import org.cpsolver.ifs.solution.Solution;
    009import org.cpsolver.ifs.util.DataProperties;
    010
    011/**
    012 * Timetable (solution) comparator. <br>
    013 * <br>
    014 * The quality of a solution is expressed as a weighted sum combining soft time
    015 * and classroom preferences, satisfied soft group constrains and the total
    016 * number of student conflicts. This allows us to express the importance of
    017 * different types of soft constraints. <br>
    018 * <br>
    019 * The solution comparator prefers a more complete solution (with a smaller
    020 * number of unassigned variables) and a solution with a smaller number of
    021 * perturbations among solutions with the same number of unassigned variables.
    022 * If both solutions have the same number of unassigned variables and
    023 * perturbations, the solution of better quality is selected. <br>
    024 * <br>
    025 * Parameters:
    026 * <table border='1'><caption>Related Solver Parameters</caption>
    027 * <tr>
    028 * <th>Parameter</th>
    029 * <th>Type</th>
    030 * <th>Comment</th>
    031 * </tr>
    032 * <tr>
    033 * <td>Comparator.HardStudentConflictWeight</td>
    034 * <td>{@link Double}</td>
    035 * <td>Weight of hard student conflict (conflict between single-section classes)
    036 * </td>
    037 * </tr>
    038 * <tr>
    039 * <td>Comparator.StudentConflictWeight</td>
    040 * <td>{@link Double}</td>
    041 * <td>Weight of student conflict</td>
    042 * </tr>
    043 * <tr>
    044 * <td>Comparator.TimePreferenceWeight</td>
    045 * <td>{@link Double}</td>
    046 * <td>Time preferences weight</td>
    047 * </tr>
    048 * <tr>
    049 * <td>Comparator.ContrPreferenceWeight</td>
    050 * <td>{@link Double}</td>
    051 * <td>Group constraint preferences weight</td>
    052 * </tr>
    053 * <tr>
    054 * <td>Comparator.RoomPreferenceWeight</td>
    055 * <td>{@link Double}</td>
    056 * <td>Room preferences weight</td>
    057 * </tr>
    058 * <tr>
    059 * <td>Comparator.UselessSlotWeight</td>
    060 * <td>{@link Double}</td>
    061 * <td>Useless slots weight</td>
    062 * </tr>
    063 * <tr>
    064 * <td>Comparator.TooBigRoomWeight</td>
    065 * <td>{@link Double}</td>
    066 * <td>Too big room weight</td>
    067 * </tr>
    068 * <tr>
    069 * <td>Comparator.DistanceInstructorPreferenceWeight</td>
    070 * <td>{@link Double}</td>
    071 * <td>Distance (of the rooms of the back-to-back classes) based instructor
    072 * preferences weight</td>
    073 * </tr>
    074 * <tr>
    075 * <td>Comparator.PerturbationPenaltyWeight</td>
    076 * <td>{@link Double}</td>
    077 * <td>Perturbation penalty (see {@link UniversalPerturbationsCounter})</td>
    078 * </tr>
    079 * <tr>
    080 * <td>Comparator.DeptSpreadPenaltyWeight</td>
    081 * <td>{@link Double}</td>
    082 * <td>Department balancing penalty (see
    083 * {@link org.cpsolver.coursett.constraint.DepartmentSpreadConstraint})</td>
    084 * </tr>
    085 * </table>
    086 *
    087 *
    088 * @author  Tomáš Müller
    089 * @version CourseTT 1.3 (University Course Timetabling)<br>
    090 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    091 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    092 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    093 * <br>
    094 *          This library is free software; you can redistribute it and/or modify
    095 *          it under the terms of the GNU Lesser General Public License as
    096 *          published by the Free Software Foundation; either version 3 of the
    097 *          License, or (at your option) any later version. <br>
    098 * <br>
    099 *          This library is distributed in the hope that it will be useful, but
    100 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    101 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    102 *          Lesser General Public License for more details. <br>
    103 * <br>
    104 *          You should have received a copy of the GNU Lesser General Public
    105 *          License along with this library; if not see
    106 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    107 */
    108@Deprecated
    109public class TimetableComparator extends GeneralSolutionComparator<Lecture, Placement> {
    110
    111    public TimetableComparator(DataProperties properties) {
    112        super(properties);
    113    }
    114
    115    /**
    116     * Use {@link Model#getTotalValue()} instead.
    117     * @param currentSolution current solution
    118     * @return current value
    119     */
    120    @Deprecated
    121    public double currentValue(Solution<Lecture, Placement> currentSolution) {
    122        double ret = 0.0;
    123        for (Criterion<Lecture, Placement> criterion: currentSolution.getModel().getCriteria())
    124            ret += criterion.getWeightedValue();
    125        return ret;
    126    }
    127
    128    /**
    129     * Use {@link Solution#getBestValue()} instead.
    130     * @param currentSolution current solution
    131     * @return best value
    132     */
    133    @Deprecated
    134    public double getBest(Solution<Lecture, Placement> currentSolution) {
    135        double ret = 0.0;
    136        for (Criterion<Lecture, Placement> criterion: currentSolution.getModel().getCriteria())
    137            ret += criterion.getWeightedBest();
    138        return ret;
    139    }
    140}