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 Tomas Muller<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 048 // 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 final int sPreferenceLevelProhibited = 100; 079 /** Preference level: required */ 080 public static final int sPreferenceLevelRequired = -100; 081 /** Preference level: strongly discouraged */ 082 public static final int sPreferenceLevelStronglyDiscouraged = 4; 083 /** Preference level: discouraged */ 084 public static final int sPreferenceLevelDiscouraged = 1; 085 /** Preference level: preferred */ 086 public static final int sPreferenceLevelPreferred = -1; 087 /** Preference level: strongly preferred */ 088 public static final int sPreferenceLevelStronglyPreferred = -4; 089 /** Preference level: neutral */ 090 public static final 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}