001 package net.sf.cpsolver.coursett.preference; 002 003 /** 004 * Min-max preference combination. 005 * <br> 006 * <ul> 007 * <li>If at least one preference is required -> required 008 * <li>If at least one preference is prohibited -> prohibited 009 * <li>If max>-min -> max 010 * <li>If -min>max -> min 011 * <li>Otherwise -> 0 012 * </ul> 013 * 014 * @version 015 * CourseTT 1.1 (University Course Timetabling)<br> 016 * Copyright (C) 2006 Tomáš Müller<br> 017 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 018 * Lazenska 391, 76314 Zlin, Czech Republic<br> 019 * <br> 020 * This library is free software; you can redistribute it and/or 021 * modify it under the terms of the GNU Lesser General Public 022 * License as published by the Free Software Foundation; either 023 * version 2.1 of the License, or (at your option) any later version. 024 * <br><br> 025 * This library is distributed in the hope that it will be useful, 026 * but WITHOUT ANY WARRANTY; without even the implied warranty of 027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 028 * Lesser General Public License for more details. 029 * <br><br> 030 * You should have received a copy of the GNU Lesser General Public 031 * License along with this library; if not, write to the Free Software 032 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 033 */ 034 public class MinMaxPreferenceCombination extends PreferenceCombination { 035 int iPreferenceMin = 0; 036 int iPreferenceMax = 0; 037 038 public void addPreferenceInt(int intPref) { 039 super.addPreferenceInt(intPref); 040 iPreferenceMax = Math.max( iPreferenceMax, intPref); 041 iPreferenceMin = Math.min( iPreferenceMin, intPref); 042 } 043 044 public int getPreferenceInt() { 045 return (iPreferenceMax>-iPreferenceMin?iPreferenceMax:-iPreferenceMin>iPreferenceMax?iPreferenceMin:iPreferenceMax); 046 } 047 }