    001package org.cpsolver.coursett.criteria;
    002
    003import java.util.Collection;
    004import java.util.HashSet;
    005import java.util.Set;
    006
    007import org.cpsolver.coursett.constraint.SpreadConstraint;
    008import org.cpsolver.coursett.model.Lecture;
    009import org.cpsolver.coursett.model.Placement;
    010import org.cpsolver.ifs.assignment.Assignment;
    011import org.cpsolver.ifs.util.DataProperties;
    012
    013
    014
    015/**
    016 * Same subpart balancing penalty. This criterion tries to spread classes of each
    017 * scheduling subpart in time. It also includes all other spread in time distribution
    018 * constraints. This criterion is counted by {@link SpreadConstraint}.
    019 * <br>
    020 *
    021 * @version CourseTT 1.3 (University Course Timetabling)<br>
    022 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    023 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    024 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    025 * <br>
    026 *          This library is free software; you can redistribute it and/or modify
    027 *          it under the terms of the GNU Lesser General Public License as
    028 *          published by the Free Software Foundation; either version 3 of the
    029 *          License, or (at your option) any later version. <br>
    030 * <br>
    031 *          This library is distributed in the hope that it will be useful, but
    032 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    033 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    034 *          Lesser General Public License for more details. <br>
    035 * <br>
    036 *          You should have received a copy of the GNU Lesser General Public
    037 *          License along with this library; if not see
    038 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    039 */
    040public class SameSubpartBalancingPenalty extends TimetablingCriterion {
    041
    042    public SameSubpartBalancingPenalty() {
    043        setValueUpdateType(ValueUpdateType.NoUpdate);
    044    }
    045
    046    @Override
    047    public double getWeightDefault(DataProperties config) {
    048        return 12.0 * config.getPropertyDouble("Comparator.SpreadPenaltyWeight", 1.0);
    049    }
    050
    051    @Override
    052    public String getPlacementSelectionWeightName() {
    053        return "Placement.SpreadPenaltyWeight";
    054    }
    055
    056    @Override
    057    public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    058        double ret = 0.0;
    059        for (SpreadConstraint sc: value.variable().getSpreadConstraints())
    060            ret += sc.getPenalty(assignment, value);
    061        return ret / 12.0;
    062    }
    063
    064    @Override
    065    public double getValue(Assignment<Lecture, Placement> assignment) {
    066        return super.getValue(assignment) / 12.0;
    067    }
    068
    069    @Override
    070    public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    071        double ret = 0;
    072        Set<SpreadConstraint> constraints = new HashSet<SpreadConstraint>();
    073        for (Lecture lect: variables) {
    074            for (SpreadConstraint sc: lect.getSpreadConstraints()) {
    075                if (!constraints.add(sc)) continue;
    076                ret += sc.getPenalty(assignment);
    077            }
    078        }
    079        return ret / 12.0;
    080    }
    081
    082    @Override
    083    public double[] getBounds(Assignment<Lecture, Placement> assignment) {
    084        return new double[] { 0.0, 0.0 };
    085    }
    086
    087    @Override
    088    public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    089        return new double[] { 0.0, 0.0 };
    090    }
    091}