    001package org.cpsolver.instructor.criteria;
    002
    003import java.util.Collection;
    004import java.util.Map;
    005import java.util.Set;
    006
    007import org.cpsolver.ifs.assignment.Assignment;
    008import org.cpsolver.ifs.util.DataProperties;
    009import org.cpsolver.instructor.model.Instructor;
    010import org.cpsolver.instructor.model.InstructorSchedulingModel;
    011import org.cpsolver.instructor.model.TeachingAssignment;
    012import org.cpsolver.instructor.model.TeachingRequest;
    013
    014/**
    015 * Different Lecture. If an instructor is teaching two or more assignments of the same course, this criterion counts cases when these
    016 * assignments do not share a common part (e.g., have a different lecture, counting {@link Instructor#differentLectures(Assignment, TeachingAssignment)}).
    017 *
    018 * @version IFS 1.3 (Instructor Sectioning)<br>
    019 *          Copyright (C) 2016 Tomáš Müller<br>
    020 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    021 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    022 * <br>
    023 *          This library is free software; you can redistribute it and/or modify
    024 *          it under the terms of the GNU Lesser General Public License as
    025 *          published by the Free Software Foundation; either version 3 of the
    026 *          License, or (at your option) any later version. <br>
    027 * <br>
    028 *          This library is distributed in the hope that it will be useful, but
    029 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    030 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    031 *          Lesser General Public License for more details. <br>
    032 * <br>
    033 *          You should have received a copy of the GNU Lesser General Public
    034 *          License along with this library; if not see
    035 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    036 */
    037public class DifferentLecture extends InstructorSchedulingCriterion {
    038
    039    public DifferentLecture() {
    040        setValueUpdateType(ValueUpdateType.NoUpdate);
    041    }
    042
    043    @Override
    044    public double getWeightDefault(DataProperties config) {
    045        return 1000.0;
    046    }
    047
    048    @Override
    049    public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) {
    050        return value.getInstructor().differentLectures(assignment, value);
    051    }
    052
    053    @Override
    054    public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) {
    055        double value = 0.0;
    056        for (Instructor instructor: getAssignedInstructors(assignment, variables)) {
    057            value += instructor.getContext(assignment).countDifferentLectures();
    058        }
    059        return value;
    060    }
    061
    062    @Override
    063    protected double[] computeBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment) {
    064        return new double[] { 0.0, ((InstructorSchedulingModel)getModel()).getInstructors().size() };
    065    }
    066
    067    @Override
    068    public double[] getBounds(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Collection<TeachingRequest.Variable> variables) {
    069        return new double[] { 0.0, getInstructors(assignment, variables).size() };
    070    }
    071
    072    @Override
    073    public String getAbbreviation() {
    074        return "DiffLecture";
    075    }
    076
    077    @Override
    078    public void getInfo(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Map<String, String> info) {
    079        double val = getValue(assignment);
    080        double[] bounds = getBounds(assignment);
    081        if (bounds[0] <= val && val <= bounds[1] && bounds[0] < bounds[1])
    082            info.put("Same Lecture", getPerc(val, bounds[0], bounds[1]) + "% (" + sDoubleFormat.format(bounds[1] - val) + ")");
    083    }
    084
    085    @Override
    086    public void getInfo(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Map<String, String> info, Collection<TeachingRequest.Variable> variables) {
    087        double val = getValue(assignment, variables);
    088        double[] bounds = getBounds(assignment, variables);
    089        if (bounds[0] <= val && val <= bounds[1] && bounds[0] < bounds[1])
    090            info.put("Same Lecture", getPerc(val, bounds[0], bounds[1]) + "% (" + sDoubleFormat.format(bounds[1] - val) + ")");
    091    }
    092}