    001package org.cpsolver.coursett;
    002
    003/**
    004 * Course Timetabling common constants. <br>
    005 * <br>
    006 *
    007 * @author  Tomáš Müller
    008 * @version CourseTT 1.3 (University Course Timetabling)<br>
    009 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    010 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    011 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    012 * <br>
    013 *          This library is free software; you can redistribute it and/or modify
    014 *          it under the terms of the GNU Lesser General Public License as
    015 *          published by the Free Software Foundation; either version 3 of the
    016 *          License, or (at your option) any later version. <br>
    017 * <br>
    018 *          This library is distributed in the hope that it will be useful, but
    019 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    020 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    021 *          Lesser General Public License for more details. <br>
    022 * <br>
    023 *          You should have received a copy of the GNU Lesser General Public
    024 *          License along with this library; if not see
    025 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    026 */
    027public class Constants extends org.cpsolver.ifs.Constants {
    028    /** Number of slots per day */
    029    public static final int SLOTS_PER_DAY = 288;
    030
    031    /** Day codes to combine several days into one int */
    032    public static int DAY_CODES[] = new int[] { 64, 32, 16, 8, 4, 2, 1 };
    033    /** All days */
    034    public static int DAY_CODE_ALL = 127;
    035    /** All week days */
    036    public static int DAY_CODE_WEEK = 124;
    037
    038    /** Length of a single slot in minutes */
    039    public static int SLOT_LENGTH_MIN = 5;
    040
    041    /** Start time of the first slot in minutes (from midnight) */
    042    public static int FIRST_SLOT_TIME_MIN = 0;
    043
    044    /** Number of slots per day */
    045    public static int DAY_SLOTS_FIRST = (7 * 60 + 30) / 5; // day starts at 7:30
    046
    047    /** Number of slots per day */
    048    public static int DAY_SLOTS_LAST = (17 * 60 + 30) / 5 - 1; // day ends at 17:30
    049
    050    /** Number of slots per day w/o evening hours */
    051    public static int SLOTS_PER_DAY_NO_EVENINGS = DAY_SLOTS_LAST - DAY_SLOTS_FIRST + 1;
    052
    053    /** Day names in short format M, T, W, Th, F, Sa, Su */
    054    public static String DAY_NAMES_SHORT[] = new String[] { "M", "T", "W", "Th", "F", "S", "Su" };
    055
    056    /** Number of days */
    057    public static int NR_DAYS = DAY_CODES.length;
    058
    059    /** Number of days of week (excludes weekend) */
    060    public static int NR_DAYS_WEEK = 5;
    061
    062    /** Preference: prohibited */
    063    public static final String sPreferenceProhibited = "P";
    064    /** Preference: required */
    065    public static final String sPreferenceRequired = "R";
    066    /** Preference: strongly discouraged */
    067    public static final String sPreferenceStronglyDiscouraged = "2";
    068    /** Preference: discouraged */
    069    public static final String sPreferenceDiscouraged = "1";
    070    /** Preference: preferred */
    071    public static final String sPreferencePreferred = "-1";
    072    /** Preference: strongly preferred */
    073    public static final String sPreferenceStronglyPreferred = "-2";
    074    /** Preference: neutral */
    075    public static final String sPreferenceNeutral = "0";
    076
    077    /** Preference level: prohibited */
    078    public static int sPreferenceLevelProhibited = 100;
    079    /** Preference level: required */
    080    public static int sPreferenceLevelRequired = -100;
    081    /** Preference level: strongly discouraged */
    082    public static int sPreferenceLevelStronglyDiscouraged = 4;
    083    /** Preference level: discouraged */
    084    public static int sPreferenceLevelDiscouraged = 1;
    085    /** Preference level: preferred */
    086    public static int sPreferenceLevelPreferred = -1;
    087    /** Preference level: strongly preferred */
    088    public static int sPreferenceLevelStronglyPreferred = -4;
    089    /** Preference level: neutral */
    090    public static int sPreferenceLevelNeutral = 0;
    091
    092    /** Convert preference to preference level
    093     * @param prologPref prolog preference (R for required, P for prohibited, -2 strongly preferred, ... 2 strongly discouraged)
    094     * @return integer preference
    095     **/
    096    public static int preference2preferenceLevel(String prologPref) {
    097        if (sPreferenceRequired.equals(prologPref))
    098            return sPreferenceLevelRequired;
    099        if (sPreferenceStronglyPreferred.equals(prologPref))
    100            return sPreferenceLevelStronglyPreferred;
    101        if (sPreferencePreferred.equals(prologPref))
    102            return sPreferenceLevelPreferred;
    103        if (sPreferenceDiscouraged.equals(prologPref))
    104            return sPreferenceLevelDiscouraged;
    105        if (sPreferenceStronglyDiscouraged.equals(prologPref))
    106            return sPreferenceLevelStronglyDiscouraged;
    107        if (sPreferenceProhibited.equals(prologPref))
    108            return sPreferenceLevelProhibited;
    109        return sPreferenceLevelNeutral;
    110    }
    111
    112    /** Convert preference level to preference
    113     * @param intPref integer preference
    114     * @return prolog preference (R for required, P for prohibited, -2 strongly preferred, ... 2 strongly discouraged)
    115     **/
    116    public static String preferenceLevel2preference(int intPref) {
    117        if (intPref >= sPreferenceLevelProhibited / 2)
    118            return sPreferenceProhibited;
    119        if (intPref >= sPreferenceLevelStronglyDiscouraged)
    120            return sPreferenceStronglyDiscouraged;
    121        if (intPref > sPreferenceLevelNeutral)
    122            return sPreferenceDiscouraged;
    123        if (intPref <= sPreferenceLevelRequired / 2)
    124            return sPreferenceRequired;
    125        if (intPref <= sPreferenceLevelStronglyPreferred)
    126            return sPreferenceStronglyPreferred;
    127        if (intPref < sPreferenceLevelNeutral)
    128            return sPreferencePreferred;
    129        return sPreferenceNeutral;
    130    }
    131
    132    /** Convert time (hour:minute) to time slot
    133     * @param hour hours
    134     * @param min minutes
    135     * @return time slot
    136     **/
    137    public static int time2slot(int hour, int min) {
    138        return (hour * 60 + min - FIRST_SLOT_TIME_MIN) / SLOT_LENGTH_MIN;
    139    }
    140}