001 package net.sf.cpsolver.coursett.criteria; 002 003 import java.util.Collection; 004 import java.util.Set; 005 006 import net.sf.cpsolver.coursett.model.Lecture; 007 import net.sf.cpsolver.coursett.model.Placement; 008 import net.sf.cpsolver.ifs.util.DataProperties; 009 010 /** 011 * Student committed conflicts. This criterion counts student conflicts between pairs of classes where 012 * one the classes is committed (i.e., fixed in time and room, belonging to another problem). 013 * <br> 014 * 015 * @version CourseTT 1.2 (University Course Timetabling)<br> 016 * Copyright (C) 2006 - 2011 Tomas Muller<br> 017 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 018 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 019 * <br> 020 * This library is free software; you can redistribute it and/or modify 021 * it under the terms of the GNU Lesser General Public License as 022 * published by the Free Software Foundation; either version 3 of the 023 * License, or (at your option) any later version. <br> 024 * <br> 025 * This library is distributed in the hope that it will be useful, but 026 * WITHOUT ANY WARRANTY; without even the implied warranty of 027 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 028 * Lesser General Public License for more details. <br> 029 * <br> 030 * You should have received a copy of the GNU Lesser General Public 031 * License along with this library; if not see 032 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 033 */ 034 public class StudentCommittedConflict extends StudentConflict { 035 036 @Override 037 public double getWeightDefault(DataProperties config) { 038 return config.getPropertyDouble("Comparator.CommitedStudentConflictWeight", 1.0); 039 } 040 041 @Override 042 public String getPlacementSelectionWeightName() { 043 return "Placement.NrCommitedStudConfsWeight"; 044 } 045 046 @Override 047 public boolean isApplicable(Lecture l1, Lecture l2) { 048 return committed(l1, l2); // only committed student conflicts 049 } 050 051 052 @Override 053 public boolean inConflict(Placement p1, Placement p2) { 054 return committed(p1, p2) && super.inConflict(p1, p2); 055 } 056 057 @Override 058 public double[] getBounds() { 059 if (iBounds == null) 060 computeBounds(); 061 double[] bounds = super.getBounds(); 062 return new double[] { bounds[0] + iBounds[0], bounds[1] + iBounds[1] }; 063 } 064 065 @Override 066 public void computeBounds() { 067 iBounds = new double[] { 0.0, 0.0 }; 068 for (Lecture lecture: getModel().variables()) { 069 Double max = null; 070 for (Placement placement: lecture.values()) { 071 if (max == null) { max = new Double(lecture.getCommitedConflicts(placement)); continue; } 072 max = Math.max(max, lecture.getCommitedConflicts(placement)); 073 } 074 if (max != null) iBounds[0] += max; 075 } 076 } 077 078 @Override 079 public double[] getBounds(Collection<Lecture> variables) { 080 double[] bounds = super.getBounds(variables); 081 for (Lecture lecture: variables) { 082 Double max = null; 083 for (Placement placement: lecture.values()) { 084 if (max == null) { max = new Double(lecture.getCommitedConflicts(placement)); continue; } 085 max = Math.max(max, lecture.getCommitedConflicts(placement)); 086 } 087 if (max != null) bounds[0] += max; 088 } 089 return bounds; 090 } 091 092 @Override 093 public double getValue(Placement value, Set<Placement> conflicts) { 094 double ret = super.getValue(value, conflicts); 095 ret += value.variable().getCommitedConflicts(value); 096 if (iIncludeConflicts && conflicts != null) 097 for (Placement conflict: conflicts) 098 ret -= value.variable().getCommitedConflicts(conflict); 099 return ret; 100 } 101 102 @Override 103 public double getValue(Collection<Lecture> variables) { 104 double ret = super.getValue(variables); 105 for (Lecture lect: variables) 106 if (lect.getAssignment() != null) 107 ret += lect.getCommitedConflicts(lect.getAssignment()); 108 return Math.round(ret); 109 } 110 }