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 * @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 */
037
038public class QuadraticStudentConflict extends StudentConflict {
039    
040    @Override
041    public boolean isApplicable(Lecture l1, Lecture l2) {
042        return l1 != null && l2 != null && !ignore(l1, l2) && applicable(l1, l2);
043    }
044
045    @Override
046    public double getWeightDefault(DataProperties config) {
047        return config.getPropertyDouble("Comparator.StudentConflictWeight", 1.0);
048    }
049    
050    @Override
051    public String getPlacementSelectionWeightName() {
052        return "Placement.NrStudConfsWeight";
053    }
054
055    @Override
056    protected double jointEnrollment(JenrlConstraint jenrl) {
057        return jenrl.jenrl() * jenrl.jenrl();
058    }
059    
060    @Override
061    public void incJenrl(Assignment<Lecture, Placement> assignment, JenrlConstraint jenrl, double studentWeight, Double conflictPriority, Student student) {
062        if (isApplicable(jenrl.first(), jenrl.second()) && inConflict(assignment.getValue(jenrl.first()), assignment.getValue(jenrl.second()))) {
063            inc(assignment, (jenrl.jenrl() * jenrl.jenrl()) - (jenrl.jenrl() - studentWeight) * (jenrl.jenrl() - studentWeight));
064        }
065    }
066    
067}