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