    001package org.cpsolver.coursett.criteria;
    002
    003import java.util.Collection;
    004import java.util.Set;
    005
    006import org.cpsolver.coursett.model.Lecture;
    007import org.cpsolver.coursett.model.Placement;
    008import org.cpsolver.ifs.assignment.Assignment;
    009import org.cpsolver.ifs.util.DataProperties;
    010
    011
    012/**
    013 * Student committed conflicts. This criterion counts student conflicts between pairs of classes where
    014 * one the classes is committed (i.e., fixed in time and room, belonging to another problem).
    015 * <br>
    016 *
    017 * @author  Tomáš Müller
    018 * @version CourseTT 1.3 (University Course Timetabling)<br>
    019 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
    020 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    021 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    022 * <br>
    023 *          This library is free software; you can redistribute it and/or modify
    024 *          it under the terms of the GNU Lesser General Public License as
    025 *          published by the Free Software Foundation; either version 3 of the
    026 *          License, or (at your option) any later version. <br>
    027 * <br>
    028 *          This library is distributed in the hope that it will be useful, but
    029 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    030 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    031 *          Lesser General Public License for more details. <br>
    032 * <br>
    033 *          You should have received a copy of the GNU Lesser General Public
    034 *          License along with this library; if not see
    035 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    036 */
    037public class StudentCommittedConflict extends StudentConflict {
    038
    039    @Override
    040    public double getWeightDefault(DataProperties config) {
    041        return config.getPropertyDouble("Comparator.CommitedStudentConflictWeight", 1.0);
    042    }
    043
    044    @Override
    045    public String getPlacementSelectionWeightName() {
    046        return "Placement.NrCommitedStudConfsWeight";
    047    }
    048
    049    @Override
    050    public boolean isApplicable(Lecture l1, Lecture l2) {
    051        return l1 != null && l2 != null && !ignore(l1, l2) && committed(l1, l2); // only committed student conflicts
    052    }
    053
    054    @Override
    055    public double[] getBounds(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    056        double[] bounds = super.getBounds(assignment, variables);
    057        for (Lecture lecture: variables) {
    058            Double max = null;
    059            for (Placement placement: lecture.values(assignment)) {
    060                if (max == null) { max = Double.valueOf(lecture.getCommitedConflicts(placement)); continue; }
    061                max = Math.max(max, lecture.getCommitedConflicts(placement));
    062            }
    063            if (max != null) bounds[0] += max;
    064        }
    065        return bounds;
    066    }
    067
    068    @Override
    069    public double getValue(Assignment<Lecture, Placement> assignment, Placement value, Set<Placement> conflicts) {
    070        double ret = super.getValue(assignment, value, conflicts);
    071        ret += value.variable().getCommitedConflicts(value);
    072        if (iIncludeConflicts && conflicts != null)
    073            for (Placement conflict: conflicts)
    074                ret -= value.variable().getCommitedConflicts(conflict);
    075        return ret;
    076    }
    077
    078    @Override
    079    public double getValue(Assignment<Lecture, Placement> assignment, Collection<Lecture> variables) {
    080        double ret = super.getValue(assignment, variables);
    081        for (Lecture lect: variables) {
    082            Placement plac = assignment.getValue(lect);
    083            if (plac != null)
    084                ret += lect.getCommitedConflicts(plac);
    085        }
    086        return Math.round(ret);
    087    }
    088}