Search in sources :

Example 36 with Course

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

the class StudentPreferencePenalties method setPenalties.

/**
     * Set the computed penalties to all sections of all requests of the given
     * student
     * @param student given student
     * @param distributionType penalty distribution type
     */
public static void setPenalties(Student student, int distributionType) {
    if (sDebug)
        sLog.debug("Setting penalties for " + student);
    StudentPreferencePenalties penalties = new StudentPreferencePenalties(distributionType);
    for (Request request : student.getRequests()) {
        if (!(request instanceof CourseRequest))
            continue;
        CourseRequest courseRequest = (CourseRequest) request;
        if (sDebug)
            sLog.debug("-- " + courseRequest);
        for (Course course : courseRequest.getCourses()) {
            if (sDebug)
                sLog.debug("  -- " + course.getName());
            for (Config config : course.getOffering().getConfigs()) {
                if (sDebug)
                    sLog.debug("    -- " + config.getName());
                for (Subpart subpart : config.getSubparts()) {
                    if (sDebug)
                        sLog.debug("      -- " + subpart.getName());
                    for (Section section : subpart.getSections()) {
                        section.setPenalty(penalties.getPenalty(section));
                        if (sDebug)
                            sLog.debug("        -- " + section);
                    }
                }
            }
        }
        courseRequest.clearCache();
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Config(org.cpsolver.studentsct.model.Config) Subpart(org.cpsolver.studentsct.model.Subpart) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) FreeTimeRequest(org.cpsolver.studentsct.model.FreeTimeRequest) Request(org.cpsolver.studentsct.model.Request) Course(org.cpsolver.studentsct.model.Course) Section(org.cpsolver.studentsct.model.Section)

Example 37 with Course

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

the class StudentSctBBTest method getMessages.

/**
     * Return a list of messages ({@link Message} objects) from the sectioning
     * of the given student
     * @return enrollment messages
     */
public List<Message> getMessages() {
    Assignment<Request, Enrollment> assignment = getSolution().getAssignment();
    List<Message> ret = new ArrayList<Message>();
    ret.add(new Message(Message.sMsgLevelInfo, null, "<li>Solution found in " + iTime + " ms."));
    if (iTimeoutReached)
        ret.add(new Message(Message.sMsgLevelInfo, null, "<li>Time out reached, solution optimality can not be guaranteed."));
    for (Request request : getStudent().getRequests()) {
        if (!request.isAlternative() && assignment.getValue(request) == null) {
            ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll to " + request + ", " + (request instanceof CourseRequest ? ((CourseRequest) request).getCourses().size() == 1 ? "course is" : "courses are" : "time is") + " not available."));
            Collection<Enrollment> values = (request instanceof CourseRequest ? (Collection<Enrollment>) ((CourseRequest) request).getAvaiableEnrollmentsSkipSameTime(assignment) : request.computeEnrollments(assignment));
            for (Iterator<Enrollment> f = values.iterator(); f.hasNext(); ) {
                Enrollment enrollment = f.next();
                Set<Enrollment> conf = conflictValues(assignment, enrollment);
                if (conf != null && !conf.isEmpty()) {
                    Enrollment conflict = conf.iterator().next();
                    if (conflict.equals(enrollment))
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + enrollment.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> is not available."));
                    else
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + enrollment.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> conflicts with " + conflict.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "</ul>"));
                }
            }
        }
        if (request instanceof CourseRequest && assignment.getValue(request) != null) {
            CourseRequest courseRequest = (CourseRequest) request;
            Enrollment enrollment = assignment.getValue(request);
            List<Enrollment> selectedEnrollments = courseRequest.getSelectedEnrollments(assignment, false);
            if (selectedEnrollments != null && !selectedEnrollments.isEmpty() && !selectedEnrollments.contains(enrollment)) {
                Course course = (courseRequest.getSelectedChoices().iterator().next()).getOffering().getCourse(getStudent());
                Enrollment selected = selectedEnrollments.get(0);
                Set<Enrollment> conf = conflictValues(assignment, selected);
                if (conf != null && !conf.isEmpty()) {
                    ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll selected enrollment for " + course.getName() + ", seleted " + (courseRequest.getSelectedChoices().size() == 1 ? "class is" : "classes are") + " conflicting with other choices."));
                    Enrollment conflict = conf.iterator().next();
                    if (conflict.equals(selected))
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + selected.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> is not available."));
                    else
                        ret.add(new Message(Message.sMsgLevelInfo, request, "<ul>Assignment of " + selected.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "<br> conflicts with " + conflict.getName().replaceAll("\n", "<br>&nbsp;&nbsp;&nbsp;&nbsp;") + "</ul>"));
                } else {
                    ret.add(new Message(Message.sMsgLevelWarn, request, "<li>Unable to enroll selected enrollment for " + course.getName() + "."));
                }
            }
        }
    }
    return ret;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) ArrayList(java.util.ArrayList) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) Collection(java.util.Collection) 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