001package org.cpsolver.coursett.criteria.additional;
002
003import org.cpsolver.coursett.constraint.JenrlConstraint;
004import org.cpsolver.coursett.criteria.StudentConflict;
005import org.cpsolver.coursett.model.Lecture;
006import org.cpsolver.coursett.model.Placement;
007import org.cpsolver.coursett.model.Student;
008import org.cpsolver.ifs.assignment.Assignment;
009import org.cpsolver.ifs.util.DataProperties;
010
011/**
012 * Quadratic student conflicts. Same as {@link StudentConflict}, however,
013 * student joint enrollments are squared (1 conflict counts as 1, 2 as 4, 3 as 9, etc.).
014 * 
015 * <br>
016 * 
017 * @version CourseTT 1.3 (University Course Timetabling)<br>
018 *          Copyright (C) 2006 - 2014 Tomáš Müller<br>
019 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
020 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
021 * <br>
022 *          This library is free software; you can redistribute it and/or modify
023 *          it under the terms of the GNU Lesser General Public License as
024 *          published by the Free Software Foundation; either version 3 of the
025 *          License, or (at your option) any later version. <br>
026 * <br>
027 *          This library is distributed in the hope that it will be useful, but
028 *          WITHOUT ANY WARRANTY; without even the implied warranty of
029 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
030 *          Lesser General Public License for more details. <br>
031 * <br>
032 *          You should have received a copy of the GNU Lesser General Public
033 *          License along with this library; if not see
034 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
035 */
036
037public class QuadraticStudentConflict extends StudentConflict {
038    
039    @Override
040    public boolean isApplicable(Lecture l1, Lecture l2) {
041        return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2);
042    }
043
044    @Override
045    public double getWeightDefault(DataProperties config) {
046        return config.getPropertyDouble("Comparator.StudentConflictWeight", 1.0);
047    }
048    
049    @Override
050    public String getPlacementSelectionWeightName() {
051        return "Placement.NrStudConfsWeight";
052    }
053
054    @Override
055    protected double jointEnrollment(JenrlConstraint jenrl) {
056        return jenrl.jenrl() * jenrl.jenrl();
057    }
058    
059    @Override
060    public void incJenrl(Assignment<Lecture, Placement> assignment, JenrlConstraint jenrl, double studentWeight, Double conflictPriority, Student student) {
061        if (isApplicable(jenrl.first(), jenrl.second()) && inConflict(assignment.getValue(jenrl.first()), assignment.getValue(jenrl.second()))) {
062            inc(assignment, (jenrl.jenrl() * jenrl.jenrl()) - (jenrl.jenrl() - studentWeight) * (jenrl.jenrl() - studentWeight));
063        }
064    }
065    
066}