    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 * @author  Tomáš Müller
    024 * @version CourseTT 1.3 (University Course Timetabling)<br>
    025 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    026 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    027 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    028 * <br>
    029 *          This library is free software; you can redistribute it and/or modify
    030 *          it under the terms of the GNU Lesser General Public License as
    031 *          published by the Free Software Foundation; either version 3 of the
    032 *          License, or (at your option) any later version. <br>
    033 * <br>
    034 *          This library is distributed in the hope that it will be useful, but
    035 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    036 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    037 *          Lesser General Public License for more details. <br>
    038 * <br>
    039 *          You should have received a copy of the GNU Lesser General Public
    040 *          License along with this library; if not see
    041 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    042 */
    043public class ImportantStudentConflict extends StudentConflict {
    044
    045    @Override
    046    protected double jointEnrollment(JenrlConstraint jenrl) {
    047        return jenrl.priority();
    048    }
    049
    050    @Override
    051    public boolean isApplicable(Lecture l1, Lecture l2) {
    052        return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2) && important(l1, l2);
    053    }
    054
    055    @Override
    056    public boolean isApplicable(Student student, Lecture l1, Lecture l2) {
    057        return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2) && student.getConflictingPriorty(l1, l2) != null;
    058    }
    059
    060    public boolean important(Lecture l1, Lecture l2) {
    061        JenrlConstraint jenrl = (l1 == null || l2 == null ? null : l1.jenrlConstraint(l2));
    062        return jenrl != null && jenrl.priority() > 0.0;
    063    }
    064
    065    @Override
    066    public void incJenrl(Assignment<Lecture, Placement> assignment, JenrlConstraint jenrl, double studentWeight, Double conflictPriority, Student student) {
    067        if (isApplicable(student, jenrl.first(), jenrl.second()) && inConflict(assignment.getValue(jenrl.first()), assignment.getValue(jenrl.second())) && conflictPriority != null)
    068            inc(assignment, studentWeight * conflictPriority);
    069    }
    070
    071    @Override
    072    public double getWeightDefault(DataProperties config) {
    073        return config.getPropertyDouble("Comparator.ImportantStudentConflictWeight", 3.0 * config.getPropertyDouble("Comparator.StudentConflictWeight", 1.0));
    074    }
    075
    076    @Override
    077    public String getPlacementSelectionWeightName() {
    078        return "Placement.NrImportantStudConfsWeight";
    079    }
    080
    081    @Override
    082    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) {
    083        super.getInfo(assignment, info);
    084        double conf = getValue(assignment);
    085        if (conf > 0.0) {
    086            Criterion<Lecture, Placement> c = getModel().getCriterion(ImportantStudentHardConflict.class);
    087            double hard = (c == null ? 0.0 : c.getValue(assignment));
    088            info.put("Important student conflicts", sDoubleFormat.format(conf) + (hard > 0.0 ? " [hard: " + sDoubleFormat.format(hard) + "]" : ""));
    089        }
    090    }
    091
    092    @Override
    093    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info, Collection<Lecture> variables) {
    094        super.getInfo(assignment, info, variables);
    095        double conf = getValue(assignment, variables);
    096        if (conf > 0.0) {
    097            Criterion<Lecture, Placement> c = getModel().getCriterion(ImportantStudentHardConflict.class);
    098            double hard = (c == null ? 0.0 : c.getValue(assignment, variables));
    099            info.put("Important student conflicts", sDoubleFormat.format(conf) + (hard > 0.0 ? " [hard: " + sDoubleFormat.format(hard) + "]" : ""));
    100        }
    101    }
    102
    103}