001package org.cpsolver.coursett.criteria.additional; 002 003import java.util.Collection; 004import java.util.Map; 005 006import org.cpsolver.coursett.constraint.JenrlConstraint; 007import org.cpsolver.coursett.criteria.StudentConflict; 008import org.cpsolver.coursett.model.Lecture; 009import org.cpsolver.coursett.model.Placement; 010import org.cpsolver.coursett.model.Student; 011import org.cpsolver.ifs.assignment.Assignment; 012import org.cpsolver.ifs.criteria.Criterion; 013import org.cpsolver.ifs.util.DataProperties; 014 015 016/** 017 * Important student conflicts. Some student conflicts can be counted differently, 018 * using Comparator.ImportantStudentConflictWeight. Importance of a conflict is 019 * defined by the student - offering request priority {@link Student#getPriority(Long)}. 020 * 021 * <br> 022 * 023 * @version CourseTT 1.3 (University Course Timetabling)<br> 024 * Copyright (C) 2006 - 2014 Tomas Muller<br> 025 * <a href="mailto:muller@unitime.org">muller@unitime.org</a><br> 026 * <a href="http://muller.unitime.org">http://muller.unitime.org</a><br> 027 * <br> 028 * This library is free software; you can redistribute it and/or modify 029 * it under the terms of the GNU Lesser General Public License as 030 * published by the Free Software Foundation; either version 3 of the 031 * License, or (at your option) any later version. <br> 032 * <br> 033 * This library is distributed in the hope that it will be useful, but 034 * WITHOUT ANY WARRANTY; without even the implied warranty of 035 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 036 * Lesser General Public License for more details. <br> 037 * <br> 038 * You should have received a copy of the GNU Lesser General Public 039 * License along with this library; if not see 040 * <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>. 041 */ 042public class ImportantStudentConflict extends StudentConflict { 043 044 @Override 045 protected double jointEnrollment(JenrlConstraint jenrl) { 046 return jenrl.priority(); 047 } 048 049 @Override 050 public boolean isApplicable(Lecture l1, Lecture l2) { 051 return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2) && important(l1, l2); 052 } 053 054 public boolean important(Lecture l1, Lecture l2) { 055 JenrlConstraint jenrl = (l1 == null || l2 == null ? null : l1.jenrlConstraint(l2)); 056 return jenrl != null && jenrl.priority() > 0.0; 057 } 058 059 @Override 060 public void incJenrl(Assignment<Lecture, Placement> assignment, JenrlConstraint jenrl, double studentWeight, Double conflictPriority, Student student) { 061 if (isApplicable(jenrl.first(), jenrl.second()) && inConflict(assignment.getValue(jenrl.first()), assignment.getValue(jenrl.second())) && conflictPriority != null) 062 inc(assignment, studentWeight * conflictPriority); 063 } 064 065 @Override 066 public double getWeightDefault(DataProperties config) { 067 return config.getPropertyDouble("Comparator.ImportantStudentConflictWeight", 3.0 * config.getPropertyDouble("Comparator.StudentConflictWeight", 1.0)); 068 } 069 070 @Override 071 public String getPlacementSelectionWeightName() { 072 return "Placement.NrImportantStudConfsWeight"; 073 } 074 075 @Override 076 public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) { 077 super.getInfo(assignment, info); 078 double conf = getValue(assignment); 079 if (conf > 0.0) { 080 Criterion<Lecture, Placement> c = getModel().getCriterion(ImportantStudentHardConflict.class); 081 double hard = (c == null ? 0.0 : c.getValue(assignment)); 082 info.put("Important student conflicts", sDoubleFormat.format(conf) + (hard > 0.0 ? " [hard: " + sDoubleFormat.format(hard) + "]" : "")); 083 } 084 } 085 086 @Override 087 public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info, Collection<Lecture> variables) { 088 super.getInfo(assignment, info, variables); 089 double conf = getValue(assignment, variables); 090 if (conf > 0.0) { 091 Criterion<Lecture, Placement> c = getModel().getCriterion(ImportantStudentHardConflict.class); 092 double hard = (c == null ? 0.0 : c.getValue(assignment, variables)); 093 info.put("Important student conflicts", sDoubleFormat.format(conf) + (hard > 0.0 ? " [hard: " + sDoubleFormat.format(hard) + "]" : "")); 094 } 095 } 096 097}