Search in sources :

Example 41 with Section

use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.

the class TimeOverlapConflictTable method createTable.

/**
     * Create report
     * 
     * @param assignment current assignment
     * @param includeLastLikeStudents
     *            true, if last-like students should be included (i.e.,
     *            {@link Student#isDummy()} is true)
     * @param includeRealStudents
     *            true, if real students should be included (i.e.,
     *            {@link Student#isDummy()} is false)
     * @param useAmPm use 12-hour format
     * @return report as comma separated text file
     */
public CSVFile createTable(Assignment<Request, Enrollment> assignment, boolean includeLastLikeStudents, boolean includeRealStudents, boolean useAmPm) {
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("Course"), new CSVFile.CSVField("Total\nConflicts"), new CSVFile.CSVField("Class"), new CSVFile.CSVField("Meeting Time"), new CSVFile.CSVField("Time\nConflicts"), new CSVFile.CSVField("% of Total\nConflicts"), new CSVFile.CSVField("Conflicting\nClass"), new CSVFile.CSVField("Conflicting\nMeeting Time"), new CSVFile.CSVField("Overlap [min]"), new CSVFile.CSVField("Joined\nConflicts"), new CSVFile.CSVField("% of Total\nConflicts") });
    Set<Conflict> confs = new HashSet<Conflict>();
    for (Request r1 : getModel().variables()) {
        Enrollment e1 = assignment.getValue(r1);
        if (e1 == null || r1 instanceof FreeTimeRequest)
            continue;
        for (Request r2 : r1.getStudent().getRequests()) {
            Enrollment e2 = assignment.getValue(r2);
            if (r2 instanceof FreeTimeRequest) {
                FreeTimeRequest ft = (FreeTimeRequest) r2;
                confs.addAll(iTOC.conflicts(e1, ft.createEnrollment()));
            } else if (e2 != null && r1.getId() < r2.getId()) {
                confs.addAll(iTOC.conflicts(e1, e2));
            }
        }
    }
    HashMap<Course, Set<Long>> totals = new HashMap<Course, Set<Long>>();
    HashMap<CourseSection, Map<CourseSection, Double>> conflictingPairs = new HashMap<CourseSection, Map<CourseSection, Double>>();
    HashMap<CourseSection, Set<Long>> sectionOverlaps = new HashMap<CourseSection, Set<Long>>();
    for (Conflict conflict : confs) {
        if (conflict.getStudent().isDummy() && !includeLastLikeStudents)
            continue;
        if (!conflict.getStudent().isDummy() && !includeRealStudents)
            continue;
        if (conflict.getR1() == null || conflict.getR1() instanceof FreeTimeRequest || conflict.getR2() == null || conflict.getR2() instanceof FreeTimeRequest)
            continue;
        Section s1 = (Section) conflict.getS1(), s2 = (Section) conflict.getS2();
        Request r1 = conflict.getR1();
        Course c1 = assignment.getValue(conflict.getR1()).getCourse();
        Request r2 = conflict.getR2();
        Course c2 = assignment.getValue(conflict.getR2()).getCourse();
        CourseSection a = new CourseSection(c1, s1);
        CourseSection b = new CourseSection(c2, s2);
        Set<Long> students = totals.get(c1);
        if (students == null) {
            students = new HashSet<Long>();
            totals.put(c1, students);
        }
        students.add(r1.getStudent().getId());
        students = totals.get(c2);
        if (students == null) {
            students = new HashSet<Long>();
            totals.put(c2, students);
        }
        students.add(r2.getStudent().getId());
        Set<Long> total = sectionOverlaps.get(a);
        if (total == null) {
            total = new HashSet<Long>();
            sectionOverlaps.put(a, total);
        }
        total.add(r1.getStudent().getId());
        Map<CourseSection, Double> pair = conflictingPairs.get(a);
        if (pair == null) {
            pair = new HashMap<CourseSection, Double>();
            conflictingPairs.put(a, pair);
        }
        Double prev = pair.get(b);
        pair.put(b, r2.getWeight() + (prev == null ? 0.0 : prev.doubleValue()));
        total = sectionOverlaps.get(b);
        if (total == null) {
            total = new HashSet<Long>();
            sectionOverlaps.put(b, total);
        }
        total.add(r2.getStudent().getId());
        pair = conflictingPairs.get(b);
        if (pair == null) {
            pair = new HashMap<CourseSection, Double>();
            conflictingPairs.put(b, pair);
        }
        prev = pair.get(a);
        pair.put(a, r1.getWeight() + (prev == null ? 0.0 : prev.doubleValue()));
    }
    Comparator<Course> courseComparator = new Comparator<Course>() {

        @Override
        public int compare(Course a, Course b) {
            int cmp = a.getName().compareTo(b.getName());
            if (cmp != 0)
                return cmp;
            return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
        }
    };
    Comparator<Section> sectionComparator = new Comparator<Section>() {

        @Override
        public int compare(Section a, Section b) {
            int cmp = a.getSubpart().getConfig().getOffering().getName().compareTo(b.getSubpart().getConfig().getOffering().getName());
            if (cmp != 0)
                return cmp;
            cmp = a.getSubpart().getInstructionalType().compareTo(b.getSubpart().getInstructionalType());
            // cmp = a.getName().compareTo(b.getName());
            if (cmp != 0)
                return cmp;
            return a.getId() < b.getId() ? -1 : a.getId() == b.getId() ? 0 : 1;
        }
    };
    TreeSet<Course> courses = new TreeSet<Course>(courseComparator);
    courses.addAll(totals.keySet());
    for (Course course : courses) {
        Set<Long> total = totals.get(course);
        TreeSet<Section> sections = new TreeSet<Section>(sectionComparator);
        for (Map.Entry<CourseSection, Set<Long>> entry : sectionOverlaps.entrySet()) if (course.equals(entry.getKey().getCourse()))
            sections.add(entry.getKey().getSection());
        boolean firstCourse = true;
        for (Section section : sections) {
            Set<Long> sectionOverlap = sectionOverlaps.get(new CourseSection(course, section));
            Map<CourseSection, Double> pair = conflictingPairs.get(new CourseSection(course, section));
            boolean firstClass = true;
            for (CourseSection other : new TreeSet<CourseSection>(pair.keySet())) {
                List<CSVFile.CSVField> line = new ArrayList<CSVFile.CSVField>();
                line.add(new CSVFile.CSVField(firstCourse && firstClass ? course.getName() : ""));
                line.add(new CSVFile.CSVField(firstCourse && firstClass ? total.size() : ""));
                line.add(new CSVFile.CSVField(firstClass ? section.getSubpart().getName() + " " + section.getName(course.getId()) : ""));
                line.add(new CSVFile.CSVField(firstClass ? section.getTime() == null ? "" : section.getTime().getDayHeader() + " " + section.getTime().getStartTimeHeader(useAmPm) + " - " + section.getTime().getEndTimeHeader(useAmPm) : ""));
                line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? String.valueOf(sectionOverlap.size()) : ""));
                line.add(new CSVFile.CSVField(firstClass && sectionOverlap != null ? sDF2.format(((double) sectionOverlap.size()) / total.size()) : ""));
                line.add(new CSVFile.CSVField(other.getCourse().getName() + " " + other.getSection().getSubpart().getName() + " " + other.getSection().getName(other.getCourse().getId())));
                line.add(new CSVFile.CSVField(other.getSection().getTime().getDayHeader() + " " + other.getSection().getTime().getStartTimeHeader(useAmPm) + " - " + other.getSection().getTime().getEndTimeHeader(useAmPm)));
                line.add(new CSVFile.CSVField(sDF1.format(5 * iTOC.share(section, other.getSection()))));
                line.add(new CSVFile.CSVField(sDF1.format(pair.get(other))));
                line.add(new CSVFile.CSVField(sDF2.format(pair.get(other) / total.size())));
                csv.addLine(line);
                firstClass = false;
            }
            firstCourse = false;
        }
        csv.addLine();
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) TreeSet(java.util.TreeSet) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Section(org.cpsolver.studentsct.model.Section) Conflict(org.cpsolver.studentsct.extension.TimeOverlapsCounter.Conflict) HashMap(java.util.HashMap) Map(java.util.Map)

Example 42 with Section

use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.

the class Reservation method nrChoices.

/** Number of choices and number of chaing choices in the given sub enrollment */
private int[] nrChoices(Config config, int idx, HashSet<Section> sections, boolean matching) {
    if (config.getSubparts().size() == idx) {
        return new int[] { 1, matching ? 1 : 0 };
    } else {
        Subpart subpart = config.getSubparts().get(idx);
        Set<Section> matchingSections = getSections(subpart);
        int choicesThisSubpart = 0;
        int matchingChoicesThisSubpart = 0;
        for (Section section : subpart.getSections()) {
            if (section.getParent() != null && !sections.contains(section.getParent()))
                continue;
            if (section.isOverlapping(sections))
                continue;
            sections.add(section);
            boolean m = matching && (matchingSections == null || matchingSections.contains(section));
            int[] x = nrChoices(config, 1 + idx, sections, m);
            choicesThisSubpart += x[0];
            matchingChoicesThisSubpart += x[1];
            sections.remove(section);
        }
        return new int[] { choicesThisSubpart, matchingChoicesThisSubpart };
    }
}
Also used : Subpart(org.cpsolver.studentsct.model.Subpart) Section(org.cpsolver.studentsct.model.Section)

Example 43 with Section

use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.

the class SuggestionSelection method setRequiredSections.

@Override
public void setRequiredSections(Hashtable<CourseRequest, Set<Section>> requiredSections) {
    iRequiredConfig = new Hashtable<CourseRequest, Config>();
    iRequiredSection = new Hashtable<CourseRequest, Hashtable<Subpart, Section>>();
    if (requiredSections != null) {
        for (Map.Entry<CourseRequest, Set<Section>> entry : requiredSections.entrySet()) {
            Hashtable<Subpart, Section> subSection = new Hashtable<Subpart, Section>();
            iRequiredSection.put(entry.getKey(), subSection);
            for (Section section : entry.getValue()) {
                if (subSection.isEmpty())
                    iRequiredConfig.put(entry.getKey(), section.getSubpart().getConfig());
                subSection.put(section.getSubpart(), section);
            }
        }
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Set(java.util.Set) Config(org.cpsolver.studentsct.model.Config) Hashtable(java.util.Hashtable) Subpart(org.cpsolver.studentsct.model.Subpart) Map(java.util.Map) Section(org.cpsolver.studentsct.model.Section)

Example 44 with Section

use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.

the class MultiCriteriaBranchAndBoundSelection method isAllowed.

public boolean isAllowed(int idx, Enrollment enrollment) {
    if (enrollment.isCourseRequest()) {
        CourseRequest request = (CourseRequest) enrollment.getRequest();
        Config reqConfig = iRequiredConfig.get(request);
        if (reqConfig != null) {
            if (!reqConfig.equals(enrollment.getConfig()))
                return false;
            Hashtable<Subpart, Section> reqSections = iRequiredSection.get(request);
            for (Section section : enrollment.getSections()) {
                Section reqSection = reqSections.get(section.getSubpart());
                if (reqSection == null)
                    continue;
                if (!section.equals(reqSection))
                    return false;
            }
        }
    } else if (iRequiredFreeTimes.contains(enrollment.getRequest())) {
        if (enrollment.getAssignments() == null || enrollment.getAssignments().isEmpty())
            return false;
    }
    return true;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Section(org.cpsolver.studentsct.model.Section)

Example 45 with Section

use of org.cpsolver.studentsct.model.Section in project cpsolver by UniTime.

the class MultiCriteriaBranchAndBoundSelection method setRequiredSections.

@Override
public void setRequiredSections(Hashtable<CourseRequest, Set<Section>> requiredSections) {
    if (requiredSections != null) {
        for (Map.Entry<CourseRequest, Set<Section>> entry : requiredSections.entrySet()) {
            Hashtable<Subpart, Section> subSection = new Hashtable<Subpart, Section>();
            iRequiredSection.put(entry.getKey(), subSection);
            for (Section section : entry.getValue()) {
                if (subSection.isEmpty())
                    iRequiredConfig.put(entry.getKey(), section.getSubpart().getConfig());
                subSection.put(section.getSubpart(), section);
            }
        }
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Set(java.util.Set) Hashtable(java.util.Hashtable) Subpart(org.cpsolver.studentsct.model.Subpart) HashMap(java.util.HashMap) Map(java.util.Map) Section(org.cpsolver.studentsct.model.Section)

Aggregations

Section (org.cpsolver.studentsct.model.Section)59 Subpart (org.cpsolver.studentsct.model.Subpart)34 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)32 Config (org.cpsolver.studentsct.model.Config)23 Request (org.cpsolver.studentsct.model.Request)22 Course (org.cpsolver.studentsct.model.Course)19 Enrollment (org.cpsolver.studentsct.model.Enrollment)19 Offering (org.cpsolver.studentsct.model.Offering)17 HashSet (java.util.HashSet)14 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)14 ArrayList (java.util.ArrayList)13 Set (java.util.Set)11 TreeSet (java.util.TreeSet)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 Element (org.dom4j.Element)9 Student (org.cpsolver.studentsct.model.Student)7 CSVFile (org.cpsolver.ifs.util.CSVFile)6 DistanceConflict (org.cpsolver.studentsct.extension.DistanceConflict)6 RoomLocation (org.cpsolver.coursett.model.RoomLocation)5