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