    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 * @author  Tomáš Müller
    021 * @version CourseTT 1.3 (University Course Timetabling)<br>
    022 *          Copyright (C) 2006 - 2014 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 StudentWorkdayConflict extends StudentConflict {
    041
    042    public int getStudentWorkDayLimit() {
    043        return (getModel() == null ? -1 : ((TimetableModel)getModel()).getStudentWorkDayLimit());
    044    }
    045
    046    @Override
    047    public boolean inConflict(Placement p1, Placement p2) {
    048        return workday(getStudentWorkDayLimit(), p1, p2);
    049    }
    050
    051    @Override
    052    public boolean isApplicable(Lecture l1, Lecture l2) {
    053        return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2); // all student conflicts (including committed)
    054    }
    055
    056    @Override
    057    public double getWeightDefault(DataProperties config) {
    058        return config.getPropertyDouble("Comparator.WorkDayStudentConflictWeight", 0.2);
    059    }
    060
    061    @Override
    062    public String getPlacementSelectionWeightName() {
    063        return "Placement.NrWorkDayStudConfsWeight";
    064    }
    065
    066    @Override
    067    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info) {
    068        super.getInfo(assignment, info);
    069        double conf = getValue(assignment);
    070        if (conf > 0.0)
    071            info.put("Workday student conflicts", sDoubleFormat.format(conf));
    072    }
    073
    074    @Override
    075    public void getInfo(Assignment<Lecture, Placement> assignment, Map<String, String> info, Collection<Lecture> variables) {
    076        super.getInfo(assignment, info, variables);
    077        double conf = getValue(assignment, variables);
    078        if (conf > 0.0)
    079            info.put("Workday student conflicts", sDoubleFormat.format(conf));
    080    }
    081}