    001package org.cpsolver.coursett.preference;
    002
    003/**
    004 * Min-max preference combination. <br>
    005 * <ul>
    006 * <li>If at least one preference is required &rarr; required
    007 * <li>If at least one preference is prohibited &rarr; prohibited
    008 * <li>If max&gt;-min &rarr; max
    009 * <li>If -min&gt;max &rarr; min
    010 * <li>Otherwise &rarr; 0
    011 * </ul>
    012 *
    013 * @author  Tomáš Müller
    014 * @version CourseTT 1.3 (University Course Timetabling)<br>
    015 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    016 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    017 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    018 * <br>
    019 *          This library is free software; you can redistribute it and/or modify
    020 *          it under the terms of the GNU Lesser General Public License as
    021 *          published by the Free Software Foundation; either version 3 of the
    022 *          License, or (at your option) any later version. <br>
    023 * <br>
    024 *          This library is distributed in the hope that it will be useful, but
    025 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    026 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    027 *          Lesser General Public License for more details. <br>
    028 * <br>
    029 *          You should have received a copy of the GNU Lesser General Public
    030 *          License along with this library; if not see
    031 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    032 */
    033public class MinMaxPreferenceCombination extends PreferenceCombination {
    034    int iPreferenceMin = 0;
    035    int iPreferenceMax = 0;
    036
    037    public MinMaxPreferenceCombination() {}
    038
    039    public MinMaxPreferenceCombination(MinMaxPreferenceCombination c) {
    040        super(c);
    041        iPreferenceMin = c.iPreferenceMin;
    042        iPreferenceMax = c.iPreferenceMax;
    043    }
    044
    045    @Override
    046    public void addPreferenceInt(int intPref) {
    047        super.addPreferenceInt(intPref);
    048        iPreferenceMax = Math.max(iPreferenceMax, intPref);
    049        iPreferenceMin = Math.min(iPreferenceMin, intPref);
    050    }
    051
    052    @Override
    053    public int getPreferenceInt() {
    054        return (iPreferenceMax > -iPreferenceMin ? iPreferenceMax : -iPreferenceMin > iPreferenceMax ? iPreferenceMin
    055                : iPreferenceMax);
    056    }
    057
    058    @Override
    059    public PreferenceCombination clonePreferenceCombination() { return new MinMaxPreferenceCombination(this); }
    060}