    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.model.Variable;
    009import org.cpsolver.ifs.util.DataProperties;
    010import org.cpsolver.instructor.model.TeachingAssignment;
    011import org.cpsolver.instructor.model.TeachingRequest;
    012
    013/**
    014 * Original Instructor. This criterion penalizes teaching assignments that are not given
    015 * to the initial instructor (i.e., {@link TeachingRequest} is not assigned to {@link Variable#getInitialAssignment()}).
    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 OriginalInstructor extends InstructorSchedulingCriterion {
    037    private boolean iMPP = false;
    038
    039    public OriginalInstructor() {
    040    }
    041
    042    @Override
    043    public void configure(DataProperties properties) {
    044        super.configure(properties);
    045        iMPP = properties.getPropertyBoolean("General.MPP", iMPP);
    046    }
    047
    048    @Override
    049    public double getWeightDefault(DataProperties config) {
    050        return 100.0;
    051    }
    052
    053    @Override
    054    public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) {
    055        if (iMPP && value.variable().getInitialAssignment() != null) {
    056            return (value.getInstructor().equals(value.variable().getInitialAssignment().getInstructor()) ? 0.0 : 1.0);
    057        } else {
    058            return 0.0;
    059        }
    060    }
    061
    062    @Override
    063    public String getAbbreviation() {
    064        return "Original";
    065    }
    066
    067    @Override
    068    public void getInfo(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Map<String, String> info) {
    069        double val = getValue(assignment);
    070        double[] bounds = getBounds(assignment);
    071        if (bounds[0] <= val && val <= bounds[1] && bounds[0] < bounds[1])
    072            info.put(getName(), getPerc(val, bounds[0], bounds[1]) + "% (" + sDoubleFormat.format(bounds[1] - val) + ")");
    073    }
    074
    075    @Override
    076    public void getInfo(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Map<String, String> info, Collection<TeachingRequest.Variable> variables) {
    077        double val = getValue(assignment, variables);
    078        double[] bounds = getBounds(assignment, variables);
    079        if (bounds[0] <= val && val <= bounds[1] && bounds[0] < bounds[1])
    080            info.put(getName(), getPerc(val, bounds[0], bounds[1]) + "% (" + sDoubleFormat.format(bounds[1] - val) + ")");
    081    }
    082}