001package net.sf.cpsolver.coursett; 002 003/** 004 * Course Timetabling common constants. <br> 005 * <br> 006 * 007 * @version CourseTT 1.2 (University Course Timetabling)<br> 008 * Copyright (C) 2006 - 2010 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 net.sf.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 public static int preference2preferenceLevel(String prologPref) { 094 if (sPreferenceRequired.equals(prologPref)) 095 return sPreferenceLevelRequired; 096 if (sPreferenceStronglyPreferred.equals(prologPref)) 097 return sPreferenceLevelStronglyPreferred; 098 if (sPreferencePreferred.equals(prologPref)) 099 return sPreferenceLevelPreferred; 100 if (sPreferenceDiscouraged.equals(prologPref)) 101 return sPreferenceLevelDiscouraged; 102 if (sPreferenceStronglyDiscouraged.equals(prologPref)) 103 return sPreferenceLevelStronglyDiscouraged; 104 if (sPreferenceProhibited.equals(prologPref)) 105 return sPreferenceLevelProhibited; 106 return sPreferenceLevelNeutral; 107 } 108 109 /** Convert preference level to preference */ 110 public static String preferenceLevel2preference(int intPref) { 111 if (intPref >= sPreferenceLevelProhibited / 2) 112 return sPreferenceProhibited; 113 if (intPref >= sPreferenceLevelStronglyDiscouraged) 114 return sPreferenceStronglyDiscouraged; 115 if (intPref > sPreferenceLevelNeutral) 116 return sPreferenceDiscouraged; 117 if (intPref <= sPreferenceLevelRequired / 2) 118 return sPreferenceRequired; 119 if (intPref <= sPreferenceLevelStronglyPreferred) 120 return sPreferenceStronglyPreferred; 121 if (intPref < sPreferenceLevelNeutral) 122 return sPreferencePreferred; 123 return sPreferenceNeutral; 124 } 125 126 /** Convert time (hour:minute) to time slot */ 127 public static int time2slot(int hour, int min) { 128 return (hour * 60 + min - FIRST_SLOT_TIME_MIN) / SLOT_LENGTH_MIN; 129 } 130}