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.solver.Solver; 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 TeachingRequest#getInitialAssignment()}). 016 * 017 * @version IFS 1.3 (Instructor Sectioning)<br> 018 * Copyright (C) 2016 Tomas Muller<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 boolean init(Solver<TeachingRequest, TeachingAssignment> solver) { 044 boolean ret = super.init(solver); 045 iMPP = solver.getProperties().getPropertyBoolean("General.MPP", iMPP); 046 return ret; 047 } 048 049 @Override 050 public double getWeightDefault(DataProperties config) { 051 return 100.0; 052 } 053 054 @Override 055 public double getValue(Assignment<TeachingRequest, 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, 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, TeachingAssignment> assignment, Map<String, String> info, Collection<TeachingRequest> 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}