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 Tomáš Müller<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    @Override
055    public boolean isApplicable(Student student, Lecture l1, Lecture l2) {
056        return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2) && student.getConflictingPriorty(l1, l2) != null;
057    }
058    
059    public boolean important(Lecture l1, Lecture l2) {
060        JenrlConstraint jenrl = (l1 == null || l2 == null ? null : l1.jenrlConstraint(l2));
061        return jenrl != null && jenrl.priority() > 0.0; 
062    }
063    
064    @Override
065    public void incJenrl(Assignment<Lecture, Placement> assignment, JenrlConstraint jenrl, double studentWeight, Double conflictPriority, Student student) {
066        if (isApplicable(student, jenrl.first(), jenrl.second()) && inConflict(assignment.getValue(jenrl.first()), assignment.getValue(jenrl.second())) && conflictPriority != null)
067            inc(assignment, studentWeight * conflictPriority);
068    }
069    
070    @Override
071    public double getWeightDefault(DataProperties config) {
072        return config.getPropertyDouble("Comparator.ImportantStudentConflictWeight", 3.0 * config.getPropertyDouble("Comparator.StudentConflictWeight", 1.0));
073    }
074    
075    @Override
076    public String getPlacementSelectionWeightName() {
077        return "Placement.NrImportantStudConfsWeight";
078    }
079
080    @Override
081    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) {
082        super.getInfo(assignment, info);
083        double conf = getValue(assignment);
084        if (conf > 0.0) {
085            Criterion<Lecture, Placement> c = getModel().getCriterion(ImportantStudentHardConflict.class);
086            double hard = (c == null ? 0.0 : c.getValue(assignment));
087            info.put("Important student conflicts", sDoubleFormat.format(conf) + (hard > 0.0 ? " [hard: " + sDoubleFormat.format(hard) + "]" : ""));
088        }
089    }
090    
091    @Override
092    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info, Collection<Lecture> variables) {
093        super.getInfo(assignment, info, variables);
094        double conf = getValue(assignment, variables);
095        if (conf > 0.0) {
096            Criterion<Lecture, Placement> c = getModel().getCriterion(ImportantStudentHardConflict.class);
097            double hard = (c == null ? 0.0 : c.getValue(assignment, variables));
098            info.put("Important student conflicts", sDoubleFormat.format(conf) + (hard > 0.0 ? " [hard: " + sDoubleFormat.format(hard) + "]" : ""));
099        }
100    }
101
102}