    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 * Same Room. This criterion counts how well are the same room preferences that are set on an {@link Instructor} met
    015 * (counting {@link Instructor#countSameRooms(Assignment, TeachingAssignment, 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 SameRoom extends InstructorSchedulingCriterion {
    037    private double iDiffTypeWeight = 0.5;
    038
    039    public SameRoom() {
    040        setValueUpdateType(ValueUpdateType.NoUpdate);
    041    }
    042
    043    @Override
    044    public void configure(DataProperties properties) {
    045        super.configure(properties);
    046        iDiffTypeWeight = properties.getPropertyDouble("SameRoom.DifferentTypeWeight", 0.5);
    047    }
    048
    049    @Override
    050    public double getWeightDefault(DataProperties config) {
    051        return 1.0;
    052    }
    053
    054    /**
    055     * Different instructional type weight
    056     * @return penalty for teaching two same-room that are of different instructional type
    057     */
    058    public double getDifferentTypeWeight() { return iDiffTypeWeight; }
    059
    060    @Override
    061    public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) {
    062        return value.getInstructor().countSameRooms(assignment, value, iDiffTypeWeight);
    063    }
    064
    065    @Override
    066    protected double[] computeBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) {
    067        double[] bounds = new double[] { 0.0, 0.0 };
    068        for (Instructor instructor: ((InstructorSchedulingModel)getModel()).getInstructors()) {
    069            bounds[1] += Math.abs(instructor.getSameRoomPreference());
    070        }
    071        return bounds;
    072    }
    073
    074    @Override
    075    public double[] getBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) {
    076        double[] bounds = new double[] { 0.0, 0.0 };
    077        for (Instructor instructor: getInstructors(assignment, variables)) {
    078            bounds[1] += Math.abs(instructor.getSameRoomPreference());
    079        }
    080        return bounds;
    081    }
    082
    083    @Override
    084    public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) {
    085        double value = 0.0;
    086        for (Instructor instructor: getAssignedInstructors(assignment, variables))
    087            value += instructor.getContext(assignment).countSameRoomPreference(iDiffTypeWeight);
    088        return value;
    089    }
    090
    091    @Override
    092    public String getAbbreviation() {
    093        return "SameRoom";
    094    }
    095}