Search in sources :

Example 1 with Choice

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

the class StudentSectioningXMLSaver method saveCourseRequest.

/**
 * Save course request
 * @param requestEl request element to be populated
 * @param request course request to be saved
 */
protected void saveCourseRequest(Element requestEl, CourseRequest request) {
    requestEl.addAttribute("id", getId("request", request.getId()));
    requestEl.addAttribute("priority", String.valueOf(request.getPriority()));
    if (request.isAlternative())
        requestEl.addAttribute("alternative", "true");
    if (request.getWeight() != 1.0)
        requestEl.addAttribute("weight", sStudentWeightFormat.format(request.getWeight()));
    requestEl.addAttribute("waitlist", request.isWaitlist() ? "true" : "false");
    if (request.getRequestPriority() != RequestPriority.Normal)
        requestEl.addAttribute("importance", request.getRequestPriority().name());
    if (request.getRequestPriority() == RequestPriority.Critical)
        requestEl.addAttribute("critical", "true");
    if (request.getTimeStamp() != null)
        requestEl.addAttribute("timeStamp", request.getTimeStamp().toString());
    boolean first = true;
    for (Course course : request.getCourses()) {
        if (first)
            requestEl.addAttribute("course", getId("course", course.getId()));
        else
            requestEl.addElement("alternative").addAttribute("course", getId("course", course.getId()));
        first = false;
    }
    for (Choice choice : request.getWaitlistedChoices()) {
        Element choiceEl = requestEl.addElement("waitlisted");
        choiceEl.addAttribute("offering", getId("offering", choice.getOffering().getId()));
        choiceEl.setText(choice.getId());
    }
    for (Choice choice : request.getSelectedChoices()) {
        Element choiceEl = requestEl.addElement("selected");
        choiceEl.addAttribute("offering", getId("offering", choice.getOffering().getId()));
        choiceEl.setText(choice.getId());
    }
    for (Choice choice : request.getRequiredChoices()) {
        Element choiceEl = requestEl.addElement("required");
        choiceEl.addAttribute("offering", getId("offering", choice.getOffering().getId()));
        choiceEl.setText(choice.getId());
    }
    if (iSaveInitial && request.getInitialAssignment() != null) {
        saveEnrollment(requestEl.addElement("initial"), request.getInitialAssignment());
    }
    if (iSaveCurrent && getAssignment().getValue(request) != null) {
        saveEnrollment(requestEl.addElement("current"), getAssignment().getValue(request));
    }
    if (iSaveBest && request.getBestAssignment() != null) {
        saveEnrollment(requestEl.addElement("best"), request.getBestAssignment());
    }
    if (request.isFixed())
        saveEnrollment(requestEl.addElement("fixed"), request.getFixedValue());
    for (RequestGroup g : request.getRequestGroups()) {
        Element groupEl = requestEl.addElement("group").addAttribute("id", getId("group", g.getId())).addAttribute("course", getId("course", g.getCourse().getId()));
        if (iShowNames)
            groupEl.addAttribute("name", g.getName());
    }
}
Also used : Choice(org.cpsolver.studentsct.model.Choice) RequestGroup(org.cpsolver.studentsct.model.RequestGroup) Element(org.dom4j.Element) Course(org.cpsolver.studentsct.model.Course)

Example 2 with Choice

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

the class EqualStudentWeights method main.

/**
 * Test case -- run to see the weights for a few courses
 * @param args program arguments
 */
public static void main(String[] args) {
    EqualStudentWeights pw = new EqualStudentWeights(new DataProperties());
    DecimalFormat df = new DecimalFormat("0.0000");
    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(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 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<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]));
    }
    System.out.println("Disbalanced sections (by 2 / 10 students):");
    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>();
            Subpart x = new Subpart(0, "Lec", "Lec", cfg, null);
            Section a = new Section(0, 10, "x", x, p, null);
            new Section(1, 10, "y", x, p, null);
            sections.add(a);
            a.assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            a.assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            cfg.getContext(assignment).assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            cfg.getContext(assignment).assigned(assignment, new Enrollment(s.getRequests().get(0), i, cfg, sections, assignment));
            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("Same sections:");
    pw.iMPP = true;
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        double dif = 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);
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, sections, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
            dif = pw.getDifference(e);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]) + " (" + df.format(dif) + ")");
    }
    System.out.println("Same choice sections:");
    pw.iMPP = true;
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        double dif = 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<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
            dif = pw.getDifference(e);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]) + " (" + df.format(dif) + ")");
    }
    System.out.println("Same time sections:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double dif = 0;
        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<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null, new Instructor(1, null, "Josef Novak", null)));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
            dif = pw.getDifference(e);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]) + " (" + df.format(dif) + ")");
    }
    System.out.println("Same configuration sections:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        double dif = 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);
            cr.getSelectedChoices().add(new Choice(cfg));
            cr.setInitialAssignment(null);
            w[i] = pw.getWeight(assignment, e, null, null);
            dif = pw.getDifference(e);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]) + " (" + df.format(dif) + ")");
    }
    System.out.println("Different time sections:");
    Placement q = new Placement(null, new TimeLocation(1, 102, 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 };
        double dif = 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<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(1, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), q, null));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
            dif = pw.getDifference(e);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]) + " (" + df.format(dif) + ")");
    }
    System.out.println("Two sections, one same choice, one same time:");
    for (Request r : s.getRequests()) {
        CourseRequest cr = (CourseRequest) r;
        double[] w = new double[] { 0.0, 0.0, 0.0 };
        double dif = 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));
            sections.add(new Section(1, 1, "y", new Subpart(1, "Rec", "Rec", cfg, null), p, null));
            Enrollment e = new Enrollment(cr, i, cfg, sections, assignment);
            Set<SctAssignment> other = new HashSet<SctAssignment>();
            other.add(new Section(2, 1, "x", new Subpart(0, "Lec", "Lec", cfg, null), p, null));
            other.add(new Section(3, 1, "y", new Subpart(1, "Rec", "Rec", cfg, null), p, null, new Instructor(1, null, "Josef Novak", null)));
            cr.setInitialAssignment(new Enrollment(cr, i, cfg, other, assignment));
            w[i] = pw.getWeight(assignment, e, null, null);
            dif = pw.getDifference(e);
        }
        System.out.println(cr + ": " + df.format(w[0]) + "  " + df.format(w[1]) + "  " + df.format(w[2]) + " (" + df.format(dif) + ")");
    }
}
Also used : Choice(org.cpsolver.studentsct.model.Choice) TimeLocation(org.cpsolver.coursett.model.TimeLocation) Config(org.cpsolver.studentsct.model.Config) DecimalFormat(java.text.DecimalFormat) DistanceConflict(org.cpsolver.studentsct.extension.DistanceConflict) Instructor(org.cpsolver.studentsct.model.Instructor) 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 3 with Choice

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

the class TableauReport method create.

@Override
public CSVFile create(Assignment<Request, Enrollment> assignment, DataProperties properties) {
    CSVFile csv = new CSVFile();
    boolean simple = properties.getPropertyBoolean("simple", false);
    if (simple) {
        csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("__Student"), new CSVFile.CSVField("Student"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("Course Limit"), new CSVFile.CSVField("Primary"), new CSVFile.CSVField("Priority"), new CSVFile.CSVField("Alternativity"), new CSVFile.CSVField("Enrolled"), new CSVFile.CSVField("Request Type") });
    } else {
        csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("__Student"), new CSVFile.CSVField("Student"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("Course Limit"), new CSVFile.CSVField("Controlling Course"), new CSVFile.CSVField("Primary"), new CSVFile.CSVField("Priority"), new CSVFile.CSVField("Alternativity"), new CSVFile.CSVField("Enrolled"), new CSVFile.CSVField("Credits"), new CSVFile.CSVField("Sections"), new CSVFile.CSVField("Preferred Sections"), new CSVFile.CSVField("Required Sections"), new CSVFile.CSVField("Instructional Method"), new CSVFile.CSVField("Preferred Instructional Methods"), new CSVFile.CSVField("Required Instructional Methods"), new CSVFile.CSVField("Request Type") });
    }
    for (Student student : getModel().getStudents()) {
        if (student.isDummy())
            continue;
        int regPriority = 1, altPriority = 1;
        for (Request r : student.getRequests()) {
            if (r instanceof CourseRequest) {
                CourseRequest cr = (CourseRequest) r;
                Enrollment e = cr.getAssignment(assignment);
                int primary = (cr.isAlternative() ? 0 : 1);
                int priority = 0;
                if (cr.isAlternative())
                    priority = altPriority++;
                else
                    priority = regPriority++;
                int alternativity = 0;
                for (Course course : cr.getCourses()) {
                    int enrolled = (e != null && e.getCourse().equals(course) ? 1 : 0);
                    String sect = null;
                    if (e != null && e.getCourse().equals(course)) {
                        sect = "";
                        Set<String> added = new HashSet<String>();
                        for (Section s : e.getSections()) {
                            String x = s.getName(e.getCourse().getId());
                            if (x.indexOf('-') > 0)
                                x = x.substring(0, x.indexOf('-'));
                            if (added.add(x))
                                sect += (sect.isEmpty() ? "" : ",") + x;
                        }
                    }
                    String imR = "", sctR = "";
                    Set<String> addedR = new HashSet<String>();
                    for (Choice ch : cr.getRequiredChoices()) {
                        if (course.getOffering().equals(ch.getOffering())) {
                            if (ch.getConfigId() != null) {
                                for (Config cfg : ch.getOffering().getConfigs()) {
                                    if (ch.getConfigId().equals(cfg.getId())) {
                                        String im = cfg.getInstructionalMethodReference();
                                        if (im != null && addedR.add(im))
                                            imR += (imR.isEmpty() ? "" : ",") + im;
                                    }
                                }
                            }
                            if (ch.getSectionId() != null) {
                                String x = ch.getOffering().getSection(ch.getSectionId()).getName(course.getId());
                                if (x.indexOf('-') > 0)
                                    x = x.substring(0, x.indexOf('-'));
                                if (addedR.add(x))
                                    sctR += (sctR.isEmpty() ? "" : ",") + x;
                            }
                        }
                    }
                    for (Reservation rs : cr.getReservations(course)) {
                        if (rs.mustBeUsed()) {
                            for (Map.Entry<Subpart, Set<Section>> ent : rs.getSections().entrySet()) {
                                for (Section s : ent.getValue()) {
                                    String x = s.getName(course.getId());
                                    if (x.indexOf('-') > 0)
                                        x = x.substring(0, x.indexOf('-'));
                                    if (addedR.add(x))
                                        sctR += (sctR.isEmpty() ? "" : ",") + x;
                                }
                            }
                            if (rs.getSections().isEmpty()) {
                                for (Config cfg : rs.getConfigs()) {
                                    String im = cfg.getInstructionalMethodReference();
                                    if (im != null && addedR.add(im))
                                        imR += (imR.isEmpty() ? "" : ",") + im;
                                }
                            }
                        }
                    }
                    String imP = "", sctP = "";
                    for (Choice ch : cr.getSelectedChoices()) {
                        Set<String> added = new HashSet<String>();
                        if (course.getOffering().equals(ch.getOffering())) {
                            if (ch.getConfigId() != null) {
                                for (Config cfg : ch.getOffering().getConfigs()) {
                                    if (ch.getConfigId().equals(cfg.getId())) {
                                        String im = cfg.getInstructionalMethodReference();
                                        if (im != null && added.add(im))
                                            imP += (imP.isEmpty() ? "" : ",") + im;
                                    }
                                }
                            }
                            if (ch.getSectionId() != null) {
                                String x = ch.getOffering().getSection(ch.getSectionId()).getName(course.getId());
                                if (x.indexOf('-') > 0)
                                    x = x.substring(0, x.indexOf('-'));
                                if (added.add(x))
                                    sctP += (sctP.isEmpty() ? "" : ",") + x;
                            }
                        }
                    }
                    if (simple)
                        csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(student.getId()), new CSVFile.CSVField(student.getExternalId()), new CSVFile.CSVField(course.getName()), new CSVFile.CSVField(course.getLimit() < 0 ? null : course.getLimit()), new CSVFile.CSVField(primary == 1 ? "Yes" : "No"), new CSVFile.CSVField(priority), new CSVFile.CSVField(alternativity), new CSVFile.CSVField(enrolled == 1 ? "Yes" : "No"), new CSVFile.CSVField(cr.getRequestPriority() == null ? "" : cr.getRequestPriority().name()) });
                    else
                        csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(student.getId()), new CSVFile.CSVField(student.getExternalId()), new CSVFile.CSVField(course.getName()), new CSVFile.CSVField(course.getLimit() < 0 ? null : course.getLimit()), new CSVFile.CSVField(course.getOffering().getCourses().size() <= 1 ? null : course.getOffering().getName()), new CSVFile.CSVField(primary == 1 ? "Yes" : "No"), new CSVFile.CSVField(priority), new CSVFile.CSVField(alternativity), new CSVFile.CSVField(enrolled == 1 ? "Yes" : "No"), new CSVFile.CSVField(enrolled == 1 ? e.getCredit() : course.getCreditValue() == null ? 0f : course.getCreditValue()), new CSVFile.CSVField(sect), new CSVFile.CSVField(sctP), new CSVFile.CSVField(sctR), new CSVFile.CSVField(e != null ? e.getConfig().getInstructionalMethodReference() : null), new CSVFile.CSVField(imP), new CSVFile.CSVField(imR), new CSVFile.CSVField(cr.getRequestPriority() == null ? "" : cr.getRequestPriority().name()) });
                    alternativity++;
                }
            }
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) Choice(org.cpsolver.studentsct.model.Choice) Set(java.util.Set) HashSet(java.util.HashSet) Config(org.cpsolver.studentsct.model.Config) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Student(org.cpsolver.studentsct.model.Student) Section(org.cpsolver.studentsct.model.Section) Reservation(org.cpsolver.studentsct.reservation.Reservation) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Subpart(org.cpsolver.studentsct.model.Subpart) Enrollment(org.cpsolver.studentsct.model.Enrollment) Course(org.cpsolver.studentsct.model.Course) Map(java.util.Map) HashSet(java.util.HashSet)

Example 4 with Choice

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

the class StudentSectioningXMLLoader method loadCourseRequest.

/**
 * Load course request
 * @param requestEl request element
 * @param student parent student
 * @param offeringTable offering table
 * @param courseTable course table
 * @return loaded course request
 */
public CourseRequest loadCourseRequest(Element requestEl, Student student, Map<Long, Offering> offeringTable, Map<Long, Course> courseTable) {
    List<Course> courses = new ArrayList<Course>();
    courses.add(courseTable.get(Long.valueOf(requestEl.attributeValue("course"))));
    for (Iterator<?> k = requestEl.elementIterator("alternative"); k.hasNext(); ) courses.add(courseTable.get(Long.valueOf(((Element) k.next()).attributeValue("course"))));
    Long timeStamp = null;
    if (requestEl.attributeValue("timeStamp") != null)
        timeStamp = Long.valueOf(requestEl.attributeValue("timeStamp"));
    CourseRequest courseRequest = new CourseRequest(Long.parseLong(requestEl.attributeValue("id")), Integer.parseInt(requestEl.attributeValue("priority")), "true".equals(requestEl.attributeValue("alternative")), student, courses, "true".equals(requestEl.attributeValue("waitlist", "false")), RequestPriority.valueOf(requestEl.attributeValue("importance", "true".equals(requestEl.attributeValue("critical", "false")) ? RequestPriority.Critical.name() : RequestPriority.Normal.name())), timeStamp);
    if (iWaitlistCritical && RequestPriority.Critical.isCritical(courseRequest) && !courseRequest.isAlternative())
        courseRequest.setWaitlist(true);
    if (requestEl.attributeValue("weight") != null)
        courseRequest.setWeight(Double.parseDouble(requestEl.attributeValue("weight")));
    for (Iterator<?> k = requestEl.elementIterator("waitlisted"); k.hasNext(); ) {
        Element choiceEl = (Element) k.next();
        courseRequest.getWaitlistedChoices().add(new Choice(offeringTable.get(Long.valueOf(choiceEl.attributeValue("offering"))), choiceEl.getText()));
    }
    for (Iterator<?> k = requestEl.elementIterator("selected"); k.hasNext(); ) {
        Element choiceEl = (Element) k.next();
        courseRequest.getSelectedChoices().add(new Choice(offeringTable.get(Long.valueOf(choiceEl.attributeValue("offering"))), choiceEl.getText()));
    }
    for (Iterator<?> k = requestEl.elementIterator("required"); k.hasNext(); ) {
        Element choiceEl = (Element) k.next();
        courseRequest.getRequiredChoices().add(new Choice(offeringTable.get(Long.valueOf(choiceEl.attributeValue("offering"))), choiceEl.getText()));
    }
    groups: for (Iterator<?> k = requestEl.elementIterator("group"); k.hasNext(); ) {
        Element groupEl = (Element) k.next();
        long gid = Long.parseLong(groupEl.attributeValue("id"));
        String gname = groupEl.attributeValue("name", "g" + gid);
        Course course = courseTable.get(Long.valueOf(groupEl.attributeValue("course")));
        for (RequestGroup g : course.getRequestGroups()) {
            if (g.getId() == gid) {
                courseRequest.addRequestGroup(g);
                continue groups;
            }
        }
        courseRequest.addRequestGroup(new RequestGroup(gid, gname, course));
    }
    return courseRequest;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Choice(org.cpsolver.studentsct.model.Choice) RequestGroup(org.cpsolver.studentsct.model.RequestGroup) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Course(org.cpsolver.studentsct.model.Course)

Example 5 with Choice

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

the class PriorityStudentWeights method getSelection.

/**
 * Return how much the given enrollment is different from the selection (if any)
 * @param enrollment given enrollment
 * @return 0.0 when all the sections are the same, 1.0 when all the section are different (including different times)
 */
public double getSelection(Enrollment enrollment) {
    if (enrollment.getStudent().isDummy())
        return 1.0;
    if (enrollment.isCourseRequest()) {
        CourseRequest cr = (CourseRequest) enrollment.getRequest();
        if (!cr.getSelectedChoices().isEmpty()) {
            double similarSections = 0.0;
            for (Section section : enrollment.getSections()) {
                double bestChoice = 0.0;
                for (Choice ch : cr.getSelectedChoices()) {
                    if (bestChoice < 1.0 && ch.sameSection(section)) {
                        bestChoice = 1.0;
                    } else if (bestChoice < iSameChoiceWeight && ch.sameChoice(section)) {
                        bestChoice = iSameChoiceWeight;
                    } else if (bestChoice < iSameTimeWeight && ch.sameOffering(section) && ch.sameInstructionalType(section) && ch.sameTime(section)) {
                        bestChoice = iSameTimeWeight;
                    } else if (bestChoice < iSameConfigWeight && ch.sameConfiguration(section)) {
                        bestChoice = iSameConfigWeight;
                    }
                }
                similarSections += bestChoice;
            }
            return 1.0 - similarSections / enrollment.getAssignments().size();
        } else {
            return 1.0;
        }
    } else {
        return 1.0;
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Choice(org.cpsolver.studentsct.model.Choice) Section(org.cpsolver.studentsct.model.Section)

Aggregations

Choice (org.cpsolver.studentsct.model.Choice)5 Course (org.cpsolver.studentsct.model.Course)4 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)4 Section (org.cpsolver.studentsct.model.Section)3 HashSet (java.util.HashSet)2 Config (org.cpsolver.studentsct.model.Config)2 Enrollment (org.cpsolver.studentsct.model.Enrollment)2 Request (org.cpsolver.studentsct.model.Request)2 RequestGroup (org.cpsolver.studentsct.model.RequestGroup)2 Student (org.cpsolver.studentsct.model.Student)2 Subpart (org.cpsolver.studentsct.model.Subpart)2 Element (org.dom4j.Element)2 DecimalFormat (java.text.DecimalFormat)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 Placement (org.cpsolver.coursett.model.Placement)1 RoomLocation (org.cpsolver.coursett.model.RoomLocation)1