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