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 * @author Tomáš Müller 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 OriginalInstructor extends InstructorSchedulingCriterion { 038 private boolean iMPP = false; 039 040 public OriginalInstructor() { 041 } 042 043 @Override 044 public void configure(DataProperties properties) { 045 super.configure(properties); 046 iMPP = properties.getPropertyBoolean("General.MPP", iMPP); 047 } 048 049 @Override 050 public double getWeightDefault(DataProperties config) { 051 return 100.0; 052 } 053 054 @Override 055 public double getValue(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, TeachingAssignment value, Set<TeachingAssignment> conflicts) { 056 if (iMPP && value.variable().getInitialAssignment() != null) { 057 return (value.getInstructor().equals(value.variable().getInitialAssignment().getInstructor()) ? 0.0 : 1.0); 058 } else { 059 return 0.0; 060 } 061 } 062 063 @Override 064 public String getAbbreviation() { 065 return "Original"; 066 } 067 068 @Override 069 public void getInfo(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Map<String, String> info) { 070 double val = getValue(assignment); 071 double[] bounds = getBounds(assignment); 072 if (bounds[0] <= val && val <= bounds[1] && bounds[0] < bounds[1]) 073 info.put(getName(), getPerc(val, bounds[0], bounds[1]) + "% (" + sDoubleFormat.format(bounds[1] - val) + ")"); 074 } 075 076 @Override 077 public void getInfo(Assignment<TeachingRequest.Variable, TeachingAssignment> assignment, Map<String, String> info, Collection<TeachingRequest.Variable> variables) { 078 double val = getValue(assignment, variables); 079 double[] bounds = getBounds(assignment, variables); 080 if (bounds[0] <= val && val <= bounds[1] && bounds[0] < bounds[1]) 081 info.put(getName(), getPerc(val, bounds[0], bounds[1]) + "% (" + sDoubleFormat.format(bounds[1] - val) + ")"); 082 } 083}