Search in sources :

Example 51 with Request

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

the class Test method fixWeights.

private static void fixWeights(StudentSectioningModel model) {
    HashMap<Course, Integer> lastLike = new HashMap<Course, Integer>();
    HashMap<Course, Integer> real = new HashMap<Course, Integer>();
    HashSet<Long> lastLikeIds = new HashSet<Long>();
    HashSet<Long> realIds = new HashSet<Long>();
    for (Student student : model.getStudents()) {
        if (student.isDummy()) {
            if (!lastLikeIds.add(new Long(student.getId()))) {
                sLog.error("Two last-like student with id " + student.getId());
            }
        } else {
            if (!realIds.add(new Long(student.getId()))) {
                sLog.error("Two real student with id " + student.getId());
            }
        }
        for (Request request : student.getRequests()) {
            if (request instanceof CourseRequest) {
                CourseRequest courseRequest = (CourseRequest) request;
                Course course = courseRequest.getCourses().get(0);
                Integer cnt = (student.isDummy() ? lastLike : real).get(course);
                (student.isDummy() ? lastLike : real).put(course, new Integer((cnt == null ? 0 : cnt.intValue()) + 1));
            }
        }
    }
    for (Student student : new ArrayList<Student>(model.getStudents())) {
        if (student.isDummy() && realIds.contains(new Long(student.getId()))) {
            sLog.warn("There is both last-like and real student with id " + student.getId());
            long newId = -1;
            while (true) {
                newId = 1 + (long) (999999999L * Math.random());
                if (!realIds.contains(new Long(newId)) && !lastLikeIds.contains(new Long(newId)))
                    break;
            }
            lastLikeIds.remove(new Long(student.getId()));
            lastLikeIds.add(new Long(newId));
            student.setId(newId);
            sLog.warn("  -- last-like student id changed to " + student.getId());
        }
        for (Request request : new ArrayList<Request>(student.getRequests())) {
            if (!student.isDummy()) {
                request.setWeight(1.0);
                continue;
            }
            if (request instanceof CourseRequest) {
                CourseRequest courseRequest = (CourseRequest) request;
                Course course = courseRequest.getCourses().get(0);
                Integer lastLikeCnt = lastLike.get(course);
                Integer realCnt = real.get(course);
                courseRequest.setWeight(getLastLikeStudentWeight(course, realCnt == null ? 0 : realCnt.intValue(), lastLikeCnt == null ? 0 : lastLikeCnt.intValue()));
            } else
                request.setWeight(1.0);
            if (request.getWeight() <= 0.0) {
                model.removeVariable(request);
                student.getRequests().remove(request);
            }
        }
        if (student.getRequests().isEmpty()) {
            model.getStudents().remove(student);
        }
    }
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) HashMap(java.util.HashMap) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) ArrayList(java.util.ArrayList) Course(org.cpsolver.studentsct.model.Course) Student(org.cpsolver.studentsct.model.Student) HashSet(java.util.HashSet)

Example 52 with Request

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

the class Test method load.

/** Load student sectioning model 
     * @param cfg solver configuration
     * @return loaded solution
     **/
public static Solution<Request, Enrollment> load(DataProperties cfg) {
    StudentSectioningModel model = null;
    Assignment<Request, Enrollment> assignment = null;
    try {
        if (cfg.getProperty("Test.CombineStudents") == null) {
            model = new StudentSectioningModel(cfg);
            assignment = new DefaultSingleAssignment<Request, Enrollment>();
            new StudentSectioningXMLLoader(model, assignment).load();
        } else {
            Solution<Request, Enrollment> solution = combineStudents(cfg, new File(cfg.getProperty("Test.CombineStudentsLastLike", cfg.getProperty("General.Input", "." + File.separator + "solution.xml"))), new File(cfg.getProperty("Test.CombineStudents")));
            model = (StudentSectioningModel) solution.getModel();
            assignment = solution.getAssignment();
        }
        if (cfg.getProperty("Test.ExtraStudents") != null) {
            StudentSectioningXMLLoader extra = new StudentSectioningXMLLoader(model, assignment);
            extra.setInputFile(new File(cfg.getProperty("Test.ExtraStudents")));
            extra.setLoadOfferings(false);
            extra.setLoadStudents(true);
            extra.setStudentFilter(new ExtraStudentFilter(model));
            extra.load();
        }
        if (cfg.getProperty("Test.LastLikeCourseDemands") != null)
            loadLastLikeCourseDemandsXml(model, new File(cfg.getProperty("Test.LastLikeCourseDemands")));
        if (cfg.getProperty("Test.StudentInfos") != null)
            loadStudentInfoXml(model, new File(cfg.getProperty("Test.StudentInfos")));
        if (cfg.getProperty("Test.CrsReq") != null)
            loadCrsReqFiles(model, cfg.getProperty("Test.CrsReq"));
    } catch (Exception e) {
        sLog.error("Unable to load model, reason: " + e.getMessage(), e);
        return null;
    }
    if (cfg.getPropertyBoolean("Debug.DistanceConflict", false))
        DistanceConflict.sDebug = true;
    if (cfg.getPropertyBoolean("Debug.BranchBoundSelection", false))
        BranchBoundSelection.sDebug = true;
    if (cfg.getPropertyBoolean("Debug.SwapStudentsSelection", false))
        SwapStudentSelection.sDebug = true;
    if (cfg.getPropertyBoolean("Debug.TimeOverlaps", false))
        TimeOverlapsCounter.sDebug = true;
    if (cfg.getProperty("CourseRequest.SameTimePrecise") != null)
        CourseRequest.sSameTimePrecise = cfg.getPropertyBoolean("CourseRequest.SameTimePrecise", false);
    Logger.getLogger(BacktrackNeighbourSelection.class).setLevel(cfg.getPropertyBoolean("Debug.BacktrackNeighbourSelection", false) ? Level.DEBUG : Level.INFO);
    if (cfg.getPropertyBoolean("Test.FixPriorities", false))
        fixPriorities(model);
    return new Solution<Request, Enrollment>(model, assignment);
}
Also used : Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment) File(java.io.File) IOException(java.io.IOException) Solution(org.cpsolver.ifs.solution.Solution) BacktrackNeighbourSelection(org.cpsolver.ifs.heuristics.BacktrackNeighbourSelection)

Example 53 with Request

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

the class StudentSectioningModel method removeStudent.

/**
     * Remove a student from the model
     * @param student a student to be removed from the problem
     */
public void removeStudent(Student student) {
    iStudents.remove(student);
    if (student.isDummy())
        iNrDummyStudents--;
    StudentConflict conflict = null;
    for (Request request : student.getRequests()) {
        for (Constraint<Request, Enrollment> c : request.constraints()) {
            if (c instanceof StudentConflict) {
                conflict = (StudentConflict) c;
                break;
            }
        }
        if (conflict != null)
            conflict.removeVariable(request);
        removeVariable(request);
    }
    if (conflict != null)
        removeConstraint(conflict);
}
Also used : StudentConflict(org.cpsolver.studentsct.constraint.StudentConflict) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Enrollment(org.cpsolver.studentsct.model.Enrollment)

Example 54 with Request

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

the class OverlapCheck method check.

/**
     * Check for overlapping sections that are attended by the same student
     * @param a current assignment
     * @return false, if there is such a case
     */
public boolean check(Assignment<Request, Enrollment> a) {
    sLog.info("Checking for overlaps...");
    boolean ret = true;
    for (Student student : getModel().getStudents()) {
        HashMap<TimeLocation, SctAssignment> times = new HashMap<TimeLocation, SctAssignment>();
        for (Request request : student.getRequests()) {
            Enrollment enrollment = a.getValue(request);
            if (enrollment == null)
                continue;
            for (SctAssignment assignment : enrollment.getAssignments()) {
                if (assignment.getTime() == null)
                    continue;
                for (TimeLocation time : times.keySet()) {
                    if (time.hasIntersection(assignment.getTime())) {
                        sLog.error("Student " + student + " assignment " + assignment + " overlaps with " + times.get(time));
                        ret = false;
                    }
                }
                times.put(assignment.getTime(), assignment);
            }
        }
    }
    return ret;
}
Also used : TimeLocation(org.cpsolver.coursett.model.TimeLocation) HashMap(java.util.HashMap) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student) SctAssignment(org.cpsolver.studentsct.model.SctAssignment)

Example 55 with Request

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

the class LinkedSections method createConstraint.

/**
     * Create linked-section constraints for a given student
     */
private LinkedSectionsConstraint createConstraint(Student student) {
    List<Request> requests = new ArrayList<Request>();
    int nrOfferings = 0;
    requests: for (Request request : student.getRequests()) {
        if (request instanceof CourseRequest) {
            for (Course course : ((CourseRequest) request).getCourses()) {
                Map<Subpart, Set<Section>> subpartsThisOffering = iSections.get(course.getOffering());
                if (subpartsThisOffering != null) {
                    requests.add(request);
                    nrOfferings++;
                    continue requests;
                }
            }
        }
    }
    if (nrOfferings <= 1)
        return null;
    LinkedSectionsConstraint constraint = new LinkedSectionsConstraint(student, requests);
    student.getRequests().get(0).getModel().addConstraint(constraint);
    return constraint;
}
Also used : CourseRequest(org.cpsolver.studentsct.model.CourseRequest) ArrayList(java.util.ArrayList) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Course(org.cpsolver.studentsct.model.Course) HashMap(java.util.HashMap) Map(java.util.Map) Section(org.cpsolver.studentsct.model.Section) Constraint(org.cpsolver.ifs.model.Constraint)

Aggregations

Request (org.cpsolver.studentsct.model.Request)65 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)51 Enrollment (org.cpsolver.studentsct.model.Enrollment)47 FreeTimeRequest (org.cpsolver.studentsct.model.FreeTimeRequest)23 Section (org.cpsolver.studentsct.model.Section)22 ArrayList (java.util.ArrayList)21 Student (org.cpsolver.studentsct.model.Student)21 Course (org.cpsolver.studentsct.model.Course)20 HashSet (java.util.HashSet)18 HashMap (java.util.HashMap)14 Subpart (org.cpsolver.studentsct.model.Subpart)10 Map (java.util.Map)9 DataProperties (org.cpsolver.ifs.util.DataProperties)9 Config (org.cpsolver.studentsct.model.Config)8 Offering (org.cpsolver.studentsct.model.Offering)8 Set (java.util.Set)7 DefaultSingleAssignment (org.cpsolver.ifs.assignment.DefaultSingleAssignment)7 File (java.io.File)6 IOException (java.io.IOException)6 TreeSet (java.util.TreeSet)6