001    package net.sf.cpsolver.coursett;
002    
003    /**
004     * Course Timetabling common constants.
005     * <br><br>
006     * 
007     * @version
008     * CourseTT 1.1 (University Course Timetabling)<br>
009     * Copyright (C) 2006 Tomáš Müller<br>
010     * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
011     * Lazenska 391, 76314 Zlin, Czech Republic<br>
012     * <br>
013     * This library is free software; you can redistribute it and/or
014     * modify it under the terms of the GNU Lesser General Public
015     * License as published by the Free Software Foundation; either
016     * version 2.1 of the License, or (at your option) any later version.
017     * <br><br>
018     * This library is distributed in the hope that it will be useful,
019     * but 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.
022     * <br><br>
023     * You should have received a copy of the GNU Lesser General Public
024     * License along with this library; if not, write to the Free Software
025     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
026     */
027    public class Constants  extends net.sf.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    
054        /** Day names in short format M, T, W, Th, F, Sa, Su */
055        public static String DAY_NAMES_SHORT[] = new String[] {
056                "M", "T", "W", "Th", "F", "S", "Su"
057            };
058    
059        /** Number of days */
060        public static int NR_DAYS = DAY_CODES.length;
061    
062        /** Number of days of week (excludes weekend) */
063        public static int NR_DAYS_WEEK = 5;
064    
065        /** Preference: prohibited */
066        public static final String sPreferenceProhibited = "P";
067        /** Preference: required */
068        public static final String sPreferenceRequired = "R";
069        /** Preference: strongly discouraged */
070        public static final String sPreferenceStronglyDiscouraged = "2";
071        /** Preference: discouraged */
072        public static final String sPreferenceDiscouraged = "1";
073        /** Preference: preferred */
074        public static final String sPreferencePreferred = "-1";
075        /** Preference: strongly preferred */
076        public static final String sPreferenceStronglyPreferred = "-2";
077        /** Preference: neutral */
078        public static final String sPreferenceNeutral = "0";
079    
080        /** Preference level: prohibited */
081        public static final int sPreferenceLevelProhibited = 100;
082        /** Preference level: required */
083        public static final int sPreferenceLevelRequired = -100;
084        /** Preference level: strongly discouraged */
085        public static final int sPreferenceLevelStronglyDiscouraged = 4;
086        /** Preference level: discouraged */
087        public static final int sPreferenceLevelDiscouraged = 1;
088        /** Preference level: preferred */
089        public static final int sPreferenceLevelPreferred = -1;
090        /** Preference level: strongly preferred */
091        public static final int sPreferenceLevelStronglyPreferred = -4;
092        /** Preference level: neutral */
093        public static final int sPreferenceLevelNeutral = 0;
094        
095        /** Convert preference to preference level */
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        public static String preferenceLevel2preference(int intPref) {
114            if (intPref>=sPreferenceLevelProhibited/2) return sPreferenceProhibited;
115            if (intPref>=sPreferenceLevelStronglyDiscouraged) return sPreferenceStronglyDiscouraged;
116            if (intPref>sPreferenceLevelNeutral) return sPreferenceDiscouraged;
117            if (intPref<=sPreferenceLevelRequired/2) return sPreferenceRequired;
118            if (intPref<=sPreferenceLevelStronglyPreferred) return sPreferenceStronglyPreferred;
119            if (intPref<sPreferenceLevelNeutral) return sPreferencePreferred;
120            return sPreferenceNeutral;
121        }
122        
123        /** Convert time (hour:minute) to time slot */ 
124        public static int time2slot(int hour, int min) {
125            return (hour*60+min-FIRST_SLOT_TIME_MIN)/SLOT_LENGTH_MIN;
126        }
127    }