    001package org.cpsolver.coursett.criteria;
    002
    003import java.util.Collection;
    004import java.util.Map;
    005
    006import org.cpsolver.coursett.constraint.JenrlConstraint;
    007import org.cpsolver.coursett.model.Lecture;
    008import org.cpsolver.coursett.model.Placement;
    009import org.cpsolver.coursett.model.TimetableModel;
    010import org.cpsolver.ifs.assignment.Assignment;
    011import org.cpsolver.ifs.util.DataProperties;
    012
    013/**
    014 * Student work-day conflicts. This criterion counts student work-day conflicts between classes.
    015 * A work-day conflict occurs when two classes that are attended by the same student (or students)
    016 * are placed on the same day (or days) in times that are too far a part. The combinations of classes
    017 * that share students are maintained by {@link JenrlConstraint}.
    018 * <br>
    019 *
    020 * @version CourseTT 1.3 (University Course Timetabling)<br>
    021 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    022 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    023 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    024 * <br>
    025 *          This library is free software; you can redistribute it and/or modify
    026 *          it under the terms of the GNU Lesser General Public License as
    027 *          published by the Free Software Foundation; either version 3 of the
    028 *          License, or (at your option) any later version. <br>
    029 * <br>
    030 *          This library is distributed in the hope that it will be useful, but
    031 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    032 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    033 *          Lesser General Public License for more details. <br>
    034 * <br>
    035 *          You should have received a copy of the GNU Lesser General Public
    036 *          License along with this library; if not see
    037 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    038 */
    039public class StudentWorkdayConflict extends StudentConflict {
    040
    041    public int getStudentWorkDayLimit() {
    042        return (getModel() == null ? -1 : ((TimetableModel)getModel()).getStudentWorkDayLimit());
    043    }
    044
    045    @Override
    046    public boolean inConflict(Placement p1, Placement p2) {
    047        return workday(getStudentWorkDayLimit(), p1, p2);
    048    }
    049
    050    @Override
    051    public boolean isApplicable(Lecture l1, Lecture l2) {
    052        return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2); // all student conflicts (including committed)
    053    }
    054
    055    @Override
    056    public double getWeightDefault(DataProperties config) {
    057        return config.getPropertyDouble("Comparator.WorkDayStudentConflictWeight", 0.2);
    058    }
    059
    060    @Override
    061    public String getPlacementSelectionWeightName() {
    062        return "Placement.NrWorkDayStudConfsWeight";
    063    }
    064
    065    @Override
    066    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) {
    067        super.getInfo(assignment, info);
    068        double conf = getValue(assignment);
    069        if (conf > 0.0)
    070            info.put("Workday student conflicts", sDoubleFormat.format(conf));
    071    }
    072
    073    @Override
    074    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info, Collection<Lecture> variables) {
    075        super.getInfo(assignment, info, variables);
    076        double conf = getValue(assignment, variables);
    077        if (conf > 0.0)
    078            info.put("Workday student conflicts", sDoubleFormat.format(conf));
    079    }
    080}