Search in sources :

Example 6 with Course

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

the class StudentSectioningXMLLoader method loadOfferings.

/**
     * Load offerings
     * @param offeringsEl offerings element
     * @param offeringTable offering table
     * @param courseTable course table
     * @param timetable provided timetable (null if to be loaded from the given document)
     */
protected void loadOfferings(Element offeringsEl, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable, Map<Long, Placement> timetable) {
    HashMap<Long, Config> configTable = new HashMap<Long, Config>();
    HashMap<Long, Subpart> subpartTable = new HashMap<Long, Subpart>();
    HashMap<Long, Section> sectionTable = new HashMap<Long, Section>();
    for (Iterator<?> i = offeringsEl.elementIterator("offering"); i.hasNext(); ) {
        Element offeringEl = (Element) i.next();
        Offering offering = new Offering(Long.parseLong(offeringEl.attributeValue("id")), offeringEl.attributeValue("name", "O" + offeringEl.attributeValue("id")));
        offeringTable.put(new Long(offering.getId()), offering);
        getModel().addOffering(offering);
        for (Iterator<?> j = offeringEl.elementIterator("course"); j.hasNext(); ) {
            Element courseEl = (Element) j.next();
            Course course = loadCourse(courseEl, offering);
            courseTable.put(new Long(course.getId()), course);
        }
        for (Iterator<?> j = offeringEl.elementIterator("config"); j.hasNext(); ) {
            Element configEl = (Element) j.next();
            Config config = loadConfig(configEl, offering, subpartTable, sectionTable, timetable);
            configTable.put(config.getId(), config);
        }
        for (Iterator<?> j = offeringEl.elementIterator("reservation"); j.hasNext(); ) {
            Element reservationEl = (Element) j.next();
            loadReservation(reservationEl, offering, configTable, sectionTable);
        }
    }
}
Also used : HashMap(java.util.HashMap) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section) Offering(org.cpsolver.studentsct.model.Offering)

Example 7 with Course

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

the class StudentSectioningModel method getInfo.

/**
     * Model info
     */
@Override
public Map<String, String> getInfo(Assignment<Request, Enrollment> assignment) {
    Map<String, String> info = super.getInfo(assignment);
    StudentSectioningModelContext context = getContext(assignment);
    if (!getStudents().isEmpty())
        info.put("Students with complete schedule", sDoubleFormat.format(100.0 * context.nrComplete() / getStudents().size()) + "% (" + context.nrComplete() + "/" + getStudents().size() + ")");
    if (getDistanceConflict() != null && getDistanceConflict().getTotalNrConflicts(assignment) != 0)
        info.put("Student distance conflicts", String.valueOf(getDistanceConflict().getTotalNrConflicts(assignment)));
    if (getTimeOverlaps() != null && getTimeOverlaps().getTotalNrConflicts(assignment) != 0)
        info.put("Time overlapping conflicts", String.valueOf(getTimeOverlaps().getTotalNrConflicts(assignment)));
    int nrLastLikeStudents = getNrLastLikeStudents(false);
    if (nrLastLikeStudents != 0 && nrLastLikeStudents != getStudents().size()) {
        int nrRealStudents = getStudents().size() - nrLastLikeStudents;
        int nrLastLikeCompleteStudents = getNrCompleteLastLikeStudents(assignment, false);
        int nrRealCompleteStudents = context.nrComplete() - nrLastLikeCompleteStudents;
        if (nrLastLikeStudents > 0)
            info.put("Projected students with complete schedule", sDecimalFormat.format(100.0 * nrLastLikeCompleteStudents / nrLastLikeStudents) + "% (" + nrLastLikeCompleteStudents + "/" + nrLastLikeStudents + ")");
        if (nrRealStudents > 0)
            info.put("Real students with complete schedule", sDecimalFormat.format(100.0 * nrRealCompleteStudents / nrRealStudents) + "% (" + nrRealCompleteStudents + "/" + nrRealStudents + ")");
        int nrLastLikeRequests = getNrLastLikeRequests(false);
        int nrRealRequests = variables().size() - nrLastLikeRequests;
        int nrLastLikeAssignedRequests = context.getNrAssignedLastLikeRequests();
        int nrRealAssignedRequests = assignment.nrAssignedVariables() - nrLastLikeAssignedRequests;
        if (nrLastLikeRequests > 0)
            info.put("Projected assigned requests", sDecimalFormat.format(100.0 * nrLastLikeAssignedRequests / nrLastLikeRequests) + "% (" + nrLastLikeAssignedRequests + "/" + nrLastLikeRequests + ")");
        if (nrRealRequests > 0)
            info.put("Real assigned requests", sDecimalFormat.format(100.0 * nrRealAssignedRequests / nrRealRequests) + "% (" + nrRealAssignedRequests + "/" + nrRealRequests + ")");
        if (getDistanceConflict() != null && getDistanceConflict().getTotalNrConflicts(assignment) > 0)
            info.put("Student distance conflicts", String.valueOf(getDistanceConflict().getTotalNrConflicts(assignment)));
        if (getTimeOverlaps() != null && getTimeOverlaps().getTotalNrConflicts(assignment) > 0)
            info.put("Time overlapping conflicts", String.valueOf(getTimeOverlaps().getTotalNrConflicts(assignment)));
    }
    context.getInfo(assignment, info);
    double groupSpread = 0.0;
    double groupCount = 0;
    for (Offering offering : iOfferings) {
        for (Course course : offering.getCourses()) {
            for (RequestGroup group : course.getRequestGroups()) {
                groupSpread += group.getAverageSpread(assignment) * group.getEnrollmentWeight(assignment, null);
                groupCount += group.getEnrollmentWeight(assignment, null);
            }
        }
    }
    if (groupCount > 0)
        info.put("Same group", sDecimalFormat.format(100.0 * groupSpread / groupCount) + "%");
    return info;
}
Also used : RequestGroup(org.cpsolver.studentsct.model.RequestGroup) Course(org.cpsolver.studentsct.model.Course) Offering(org.cpsolver.studentsct.model.Offering) Constraint(org.cpsolver.ifs.model.Constraint)

Example 8 with Course

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

the class StudentSectioningModel method toString.

@Override
public String toString(Assignment<Request, Enrollment> assignment) {
    double groupSpread = 0.0;
    double groupCount = 0;
    for (Offering offering : iOfferings) {
        for (Course course : offering.getCourses()) {
            for (RequestGroup group : course.getRequestGroups()) {
                groupSpread += group.getAverageSpread(assignment) * group.getEnrollmentWeight(assignment, null);
                groupCount += group.getEnrollmentWeight(assignment, null);
            }
        }
    }
    return (getNrRealStudents(false) > 0 ? "RRq:" + getNrAssignedRealRequests(assignment, false) + "/" + getNrRealRequests(false) + ", " : "") + (getNrLastLikeStudents(false) > 0 ? "DRq:" + getNrAssignedLastLikeRequests(assignment, false) + "/" + getNrLastLikeRequests(false) + ", " : "") + (getNrRealStudents(false) > 0 ? "RS:" + getNrCompleteRealStudents(assignment, false) + "/" + getNrRealStudents(false) + ", " : "") + (getNrLastLikeStudents(false) > 0 ? "DS:" + getNrCompleteLastLikeStudents(assignment, false) + "/" + getNrLastLikeStudents(false) + ", " : "") + "V:" + sDecimalFormat.format(-getTotalValue(assignment)) + (getDistanceConflict() == null ? "" : ", DC:" + getDistanceConflict().getTotalNrConflicts(assignment)) + (getTimeOverlaps() == null ? "" : ", TOC:" + getTimeOverlaps().getTotalNrConflicts(assignment)) + (iMPP ? ", IS:" + sDecimalFormat.format(100.0 * getContext(assignment).iAssignedSameSectionWeight / iTotalMPPCRWeight) + "%" : "") + (iMPP ? ", IT:" + sDecimalFormat.format(100.0 * getContext(assignment).iAssignedSameTimeWeight / iTotalMPPCRWeight) + "%" : "") + ", %:" + sDecimalFormat.format(-100.0 * getTotalValue(assignment) / (getStudents().size() - iNrDummyStudents + (iProjectedStudentWeight < 0.0 ? iNrDummyStudents * (iTotalDummyWeight / iNrDummyRequests) : iProjectedStudentWeight * iTotalDummyWeight))) + (groupCount > 0 ? ", SG:" + sDecimalFormat.format(100.0 * groupSpread / groupCount) + "%" : "");
}
Also used : RequestGroup(org.cpsolver.studentsct.model.RequestGroup) Course(org.cpsolver.studentsct.model.Course) Offering(org.cpsolver.studentsct.model.Offering)

Example 9 with Course

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

the class OriginalStudentWeights method main.

/**
     * Test case -- run to see the weights for a few courses
     * @param args program arguments
     */
public static void main(String[] args) {
    OriginalStudentWeights pw = new OriginalStudentWeights(new DataProperties());
    DecimalFormat df = new DecimalFormat("0.000");
    Student s = new Student(0l);
    new CourseRequest(1l, 0, false, s, ToolBox.toList(new Course(1, "A", "1", new Offering(0, "A")), new Course(1, "A", "2", new Offering(0, "A")), new Course(1, "A", "3", new Offering(0, "A"))), false, null);
    new CourseRequest(2l, 1, false, s, ToolBox.toList(new Course(1, "B", "1", new Offering(0, "B")), new Course(1, "B", "2", new Offering(0, "B")), new Course(1, "B", "3", new Offering(0, "B"))), false, null);
    new CourseRequest(3l, 2, false, s, ToolBox.toList(new Course(1, "C", "1", new Offering(0, "C")), new Course(1, "C", "2", new Offering(0, "C")), new Course(1, "C", "3", new Offering(0, "C"))), false, null);
    new CourseRequest(4l, 3, false, s, ToolBox.toList(new Course(1, "D", "1", new Offering(0, "D")), new Course(1, "D", "2", new Offering(0, "D")), new Course(1, "D", "3", new Offering(0, "D"))), false, null);
    new CourseRequest(5l, 4, false, s, ToolBox.toList(new Course(1, "E", "1", new Offering(0, "E")), new Course(1, "E", "2", new Offering(0, "E")), new Course(1, "E", "3", new Offering(0, "E"))), false, null);
    new CourseRequest(6l, 5, true, s, ToolBox.toList(new Course(1, "F", "1", new Offering(0, "F")), new Course(1, "F", "2", new Offering(0, "F")), new Course(1, "F", "3", new Offering(0, "F"))), false, null);
    new CourseRequest(7l, 6, true, s, ToolBox.toList(new Course(1, "G", "1", new Offering(0, "G")), new Course(1, "G", "2", new Offering(0, "G")), new Course(1, "G", "3", new Offering(0, "G"))), false, null);
    Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
    Placement p = new Placement(null, new TimeLocation(1, 90, 12, 0, 0, null, null, new BitSet(), 10), new ArrayList<RoomLocation>());
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            w[i] = pw.getWeight(assignment, e, null, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With one distance conflict:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
            w[i] = pw.getWeight(assignment, e, dc, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With two distance conflicts:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<DistanceConflict.Conflict> dc = new HashSet<DistanceConflict.Conflict>();
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, (Section) sections.iterator().next()));
            dc.add(new DistanceConflict.Conflict(s, e, (Section) sections.iterator().next(), e, new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null)));
            w[i] = pw.getWeight(assignment, e, dc, null);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
    System.out.println("With 25% time overlapping conflicts:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        for (int i = 0; i < cr.getCourses().size(); i++) {
            Config cfg = new Config(0l, -1, "", cr.getCourses().get(i).getOffering());
            Set<SctAssignment> sections = new HashSet<SctAssignment>();
            sections.add(new Section(0, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<TimeOverlapsCounter.Conflict> toc = new HashSet<TimeOverlapsCounter.Conflict>();
            toc.add(new TimeOverlapsCounter.Conflict(s, 3, e, sections.iterator().next(), e, sections.iterator().next()));
            w[i] = pw.getWeight(assignment, e, null, toc);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]));
    }
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) Config(org.cpsolver.studentsct.model.Config) DecimalFormat(java.text.DecimalFormat) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) DataProperties(org.cpsolver.ifs.util.DataProperties) Placement(org.cpsolver.coursett.model.Placement) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) HashSet(java.util.HashSet) RoomLocation(org.cpsolver.coursett.model.RoomLocation) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) BitSet(java.util.BitSet) Student(org.cpsolver.studentsct.model.Student) Offering(org.cpsolver.studentsct.model.Offering) Section(org.cpsolver.studentsct.model.Section) TimeOverlapsCounter(org.cpsolver.studentsct.extension.TimeOverlapsCounter) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) Subpart(org.cpsolver.studentsct.model.Subpart) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) SctAssignment(org.cpsolver.studentsct.model.SctAssignment)

Example 10 with Course

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

the class StudentSectioningXMLSaver method saveOffering.

/**
     * Save given offering
     * @param offeringEl offering element to be populated
     * @param offering offering to be saved
     */
protected void saveOffering(Element offeringEl, Offering offering) {
    offeringEl.addAttribute("id", getId("offering", offering.getId()));
    if (iShowNames)
        offeringEl.addAttribute("name", offering.getName());
    for (Course course : offering.getCourses()) {
        Element courseEl = offeringEl.addElement("course");
        saveCourse(courseEl, course);
    }
    for (Config config : offering.getConfigs()) {
        Element configEl = offeringEl.addElement("config");
        saveConfig(configEl, config);
    }
}
Also used : Config(org.cpsolver.studentsct.model.Config) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course)

Aggregations

Course (org.cpsolver.studentsct.model.Course)37 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)22 Request (org.cpsolver.studentsct.model.Request)20 Section (org.cpsolver.studentsct.model.Section)19 HashSet (java.util.HashSet)16 Offering (org.cpsolver.studentsct.model.Offering)15 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 Enrollment (org.cpsolver.studentsct.model.Enrollment)14 Config (org.cpsolver.studentsct.model.Config)13 Subpart (org.cpsolver.studentsct.model.Subpart)12 Element (org.dom4j.Element)10 Map (java.util.Map)9 Student (org.cpsolver.studentsct.model.Student)9 TreeSet (java.util.TreeSet)7 CSVFile (org.cpsolver.ifs.util.CSVFile)7 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)7 Set (java.util.Set)6 Comparator (java.util.Comparator)5 DataProperties (org.cpsolver.ifs.util.DataProperties)5