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