    001package org.cpsolver.coursett.sectioning;
    002
    003import java.util.ArrayList;
    004import java.util.Collection;
    005import java.util.List;
    006
    007import org.cpsolver.coursett.model.Lecture;
    008
    009/**
    010 * A class wrapping an enrollment of a student into a course. Such an enrollment
    011 * consists of a list of classes and a conflict weight. That is a weighted sum
    012 * of the student conflicts (with other courses of the student) it creates.
    013 *
    014 * @author  Tomáš Müller
    015 * @version CourseTT 1.3 (University Course Timetabling)<br>
    016 *          Copyright (C) 2017 Tomáš Müller<br>
    017 *          <a href="mailto:muller@unitime.org">muller@unitime.org</a><br>
    018 *          <a href="http://muller.unitime.org">http://muller.unitime.org</a><br>
    019 * <br>
    020 *          This library is free software; you can redistribute it and/or modify
    021 *          it under the terms of the GNU Lesser General Public License as
    022 *          published by the Free Software Foundation; either version 3 of the
    023 *          License, or (at your option) any later version. <br>
    024 * <br>
    025 *          This library is distributed in the hope that it will be useful, but
    026 *          WITHOUT ANY WARRANTY; without even the implied warranty of
    027 *          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    028 *          Lesser General Public License for more details. <br>
    029 * <br>
    030 *          You should have received a copy of the GNU Lesser General Public
    031 *          License along with this library; if not see
    032 *          <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>.
    033 */
    034public class SctEnrollment implements Comparable<SctEnrollment> {
    035    private int iId;
    036    private SctStudent iStudent;
    037    private List<Lecture> iLectures;
    038    private double iConflictWeight;
    039
    040    /**
    041     * @param id unique id
    042     * @param student a student
    043     * @param lectures list of classes
    044     * @param conflictWeight conflict weight
    045     */
    046    public SctEnrollment(int id, SctStudent student, Collection<Lecture> lectures, double conflictWeight) {
    047        iId = id;
    048        iStudent = student;
    049        iLectures = new ArrayList<Lecture>(lectures);
    050        iConflictWeight = conflictWeight;
    051    }
    052
    053    /**
    054     * @param id unique id
    055     * @param student a student
    056     * @param lectures list of classes
    057     */
    058    public SctEnrollment(int id, SctStudent student, Collection<Lecture> lectures) {
    059        iId = id;
    060        iStudent = student;
    061        iLectures = new ArrayList<Lecture>(lectures);
    062        iConflictWeight = 0;
    063        for (Lecture lecture: lectures) {
    064            for (Lecture other: student.getStudent().getLectures()) {
    065                if (!lecture.getConfiguration().getOfferingId().equals(other.getConfiguration().getOfferingId()))
    066                    iConflictWeight += student.getJenrConflictWeight(lecture, other);
    067            }
    068            for (Lecture other: lectures)
    069                if (lecture.getClassId().compareTo(other.getClassId()) < 0)
    070                    iConflictWeight += student.getJenrConflictWeight(lecture, other);
    071        }
    072    }
    073
    074    /**
    075     * Student
    076     */
    077    public SctStudent getStudent() { return iStudent; }
    078
    079    /**
    080     * List of classes of this enrollment
    081     */
    082    public List<Lecture> getLectures() { return iLectures; }
    083
    084    /**
    085     * Overall conflict weight
    086     */
    087    public double getConflictWeight() { return iConflictWeight; }
    088
    089    @Override
    090    public int compareTo(SctEnrollment o) {
    091        int cmp = Double.compare(getConflictWeight(), o.getConflictWeight());
    092        if (cmp != 0) return cmp;
    093        return Double.compare(iId, o.iId);
    094    }
    095
    096    public Integer getId() { return iId; }
    097
    098    @Override
    099    public String toString() {
    100        return iConflictWeight + "/" + iLectures;
    101    }
    102}