    001package org.cpsolver.instructor.criteria;
    002
    003import java.util.Collection;
    004import java.util.Set;
    005
    006import org.cpsolver.ifs.assignment.Assignment;
    007import org.cpsolver.ifs.util.DataProperties;
    008import org.cpsolver.instructor.model.Instructor;
    009import org.cpsolver.instructor.model.InstructorSchedulingModel;
    010import org.cpsolver.instructor.model.TeachingAssignment;
    011import org.cpsolver.instructor.model.TeachingRequest;
    012
    013/**
    014 * Back to Back. This criterion counts how well are the back-to-back preferences that are set on an {@link Instructor} met
    015 * (counting {@link Instructor#countBackToBacks(Assignment, TeachingAssignment, double, double)}).
    016 *
    017 * @version IFS 1.3 (Instructor Sectioning)<br>
    018 *          Copyright (C) 2016 Tomáš Müller<br>
    019 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    020 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    021 * <br>
    022 *          This library is free software; you can redistribute it and/or modify
    023 *          it under the terms of the GNU Lesser General Public License as
    024 *          published by the Free Software Foundation; either version 3 of the
    025 *          License, or (at your option) any later version. <br>
    026 * <br>
    027 *          This library is distributed in the hope that it will be useful, but
    028 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    029 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    030 *          Lesser General Public License for more details. <br>
    031 * <br>
    032 *          You should have received a copy of the GNU Lesser General Public
    033 *          License along with this library; if not see
    034 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    035 */
    036public class BackToBack extends InstructorSchedulingCriterion {
    037    private double iDiffRoomWeight = 0.8, iDiffTypeWeight = 0.5;
    038
    039    public BackToBack() {
    040        setValueUpdateType(ValueUpdateType.NoUpdate);
    041    }
    042
    043    @Override
    044    public void configure(DataProperties properties) {
    045        super.configure(properties);
    046        iDiffRoomWeight = properties.getPropertyDouble("BackToBack.DifferentRoomWeight", 0.8);
    047        iDiffTypeWeight = properties.getPropertyDouble("BackToBack.DifferentTypeWeight", 0.5);
    048    }
    049
    050    @Override
    051    public double getWeightDefault(DataProperties config) {
    052        return 1.0;
    053    }
    054
    055    /**
    056     * Different room weight
    057     * @return penalty for teaching two back-to-back that are in different rooms
    058     */
    059    public double getDifferentRoomWeight() { return iDiffRoomWeight; }
    060
    061    /**
    062     * Different instructional type weight
    063     * @return penalty for teaching two back-to-back that are of different instructional type
    064     */
    065    public double getDifferentTypeWeight() { return iDiffTypeWeight; }
    066
    067    @Override
    068    public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) {
    069        return value.getInstructor().countBackToBacks(assignment, value, iDiffRoomWeight, iDiffTypeWeight);
    070    }
    071
    072    @Override
    073    protected double[] computeBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) {
    074        double[] bounds = new double[] { 0.0, 0.0 };
    075        for (Instructor instructor: ((InstructorSchedulingModel)getModel()).getInstructors()) {
    076            bounds[1] += Math.abs(instructor.getBackToBackPreference());
    077        }
    078        return bounds;
    079    }
    080
    081    @Override
    082    public double[] getBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) {
    083        double[] bounds = new double[] { 0.0, 0.0 };
    084        for (Instructor instructor: getInstructors(assignment, variables)) {
    085            bounds[1] += Math.abs(instructor.getBackToBackPreference());
    086        }
    087        return bounds;
    088    }
    089
    090    @Override
    091    public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) {
    092        double value = 0.0;
    093        for (Instructor instructor: getAssignedInstructors(assignment, variables))
    094            value += instructor.getContext(assignment).countBackToBackPreference(iDiffRoomWeight, iDiffTypeWeight);
    095        return value;
    096    }
    097
    098    @Override
    099    public String getAbbreviation() {
    100        return "Back2Back";
    101    }
    102}