001package org.cpsolver.coursett.criteria; 002 003import java.util.Collection; 004import java.util.Set; 005 006import org.cpsolver.coursett.model.Lecture; 007import org.cpsolver.coursett.model.Placement; 008import org.cpsolver.ifs.assignment.Assignment; 009import org.cpsolver.ifs.util.DataProperties; 010 011 012/** 013 * Student committed conflicts. This criterion counts student conflicts between pairs of classes where 014 * one the classes is committed (i.e., fixed in time and room, belonging to another problem). 015 * <br> 016 * 017 * @version CourseTT 1.3 (University Course Timetabling)<br> 018 * Copyright (C) 2006 - 2014 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 StudentCommittedConflict extends StudentConflict { 037 038 @Override 039 public double getWeightDefault(DataProperties config) { 040 return config.getPropertyDouble("Comparator.CommitedStudentConflictWeight", 1.0); 041 } 042 043 @Override 044 public String getPlacementSelectionWeightName() { 045 return "Placement.NrCommitedStudConfsWeight"; 046 } 047 048 @Override 049 public boolean isApplicable(Lecture l1, Lecture l2) { 050 return l1 != null && l2 != null && !ignore(l1, l2) && committed(l1, l2); // only committed student conflicts 051 } 052 053 @Override 054 public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 055 double[] bounds = super.getBounds(assignment, variables); 056 for (Lecture lecture: variables) { 057 Double max = null; 058 for (Placement placement: lecture.values(assignment)) { 059 if (max == null) { max = new Double(lecture.getCommitedConflicts(placement)); continue; } 060 max = Math.max(max, lecture.getCommitedConflicts(placement)); 061 } 062 if (max != null) bounds[0] += max; 063 } 064 return bounds; 065 } 066 067 @Override 068 public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) { 069 double ret = super.getValue(assignment, value, conflicts); 070 ret += value.variable().getCommitedConflicts(value); 071 if (iIncludeConflicts && conflicts != null) 072 for (Placement conflict: conflicts) 073 ret -= value.variable().getCommitedConflicts(conflict); 074 return ret; 075 } 076 077 @Override 078 public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) { 079 double ret = super.getValue(assignment, variables); 080 for (Lecture lect: variables) { 081 Placement plac = assignment.getValue(lect); 082 if (plac != null) 083 ret += lect.getCommitedConflicts(plac); 084 } 085 return Math.round(ret); 086 } 087}