001/*
002 * UniTime 3.5 (University Timetabling Application)
003 * Copyright (C) 2013, UniTime LLC, and individual contributors
004 * as indicated by the @authors tag.
005 * 
006 * This program is free software; you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation; either version 3 of the License, or
009 * (at your option) any later version.
010 * 
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 * 
016 * You should have received a copy of the GNU General Public License along
017 * with this program.  If not, see <http://www.gnu.org/licenses/>.
018 * 
019 */
020package org.cpsolver.studentsct.online.expectations;
021
022import org.cpsolver.ifs.assignment.Assignment;
023import org.cpsolver.ifs.util.DataProperties;
024import org.cpsolver.studentsct.model.Enrollment;
025import org.cpsolver.studentsct.model.Request;
026import org.cpsolver.studentsct.model.Section;
027
028/**
029 * Class is over-expected when {@link Section#getPenalty()} is not negative.
030 * 
031 * @version StudentSct 1.3 (Student Sectioning)<br>
032 *          Copyright (C) 2014 Tomas Muller<br>
033 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
034 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
035 * <br>
036 *          This library is free software; you can redistribute it and/or modify
037 *          it under the terms of the GNU Lesser General Public License as
038 *          published by the Free Software Foundation; either version 3 of the
039 *          License, or (at your option) any later version. <br>
040 * <br>
041 *          This library is distributed in the hope that it will be useful, but
042 *          WITHOUT ANY WARRANTY; without even the implied warranty of
043 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
044 *          Lesser General Public License for more details. <br>
045 * <br>
046 *          You should have received a copy of the GNU Lesser General Public
047 *          License along with this library; if not see <a
048 *          href='http://www.gnu.org/licenses'>http://www.gnu.org/licenses</a>.
049 * 
050 */
051public class PenaltyNotNegative implements OverExpectedCriterion {
052
053    public PenaltyNotNegative(DataProperties config) {
054    }
055
056    @Override
057    public double getOverExpected(Assignment<Request, Enrollment> assignment, Section section, Request request) {
058        if (section.getPenalty() < 0 || section.getLimit() <= 0.0)
059            return 0.0;
060        int subparts = section.getSubpart().getConfig().getSubparts().size();
061        return 1.0 / subparts;
062    }
063
064    @Override
065    public String toString() {
066        return "not-negative";
067    }
068
069    @Override
070    public Integer getExpected(int sectionLimit, double expectedSpace) {
071        if (sectionLimit <= 0.0)
072            return null;
073
074        int expected = (int) Math.round(expectedSpace);
075        if (expected > 0)
076            return expected;
077
078        return null;
079    }
080}