Search in sources :

Example 1 with RequestPriority

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

the class CriticalCoursesTable method create.

@Override
public CSVFile create(Assignment<Request, Enrollment> assignment, DataProperties properties) {
    RequestPriority rp = RequestPriority.valueOf(properties.getProperty("priority", RequestPriority.Critical.name()));
    CSVFile csv = new CSVFile();
    csv.setHeader(new CSVFile.CSVField[] { new CSVFile.CSVField("__Student"), new CSVFile.CSVField("Student"), new CSVFile.CSVField("Priority"), new CSVFile.CSVField("Course"), new CSVFile.CSVField("1st Alt"), new CSVFile.CSVField("2nd Alt"), new CSVFile.CSVField("Enrolled"), new CSVFile.CSVField("Choice") });
    for (Student student : getModel().getStudents()) {
        if (student.isDummy())
            continue;
        int priority = 0;
        for (Request r : student.getRequests()) {
            if (r instanceof CourseRequest) {
                CourseRequest cr = (CourseRequest) r;
                priority++;
                if (rp != cr.getRequestPriority() || cr.isAlternative())
                    continue;
                Enrollment e = cr.getAssignment(assignment);
                Course course = cr.getCourses().get(0);
                Course alt1 = (cr.getCourses().size() < 2 ? null : cr.getCourses().get(1));
                Course alt2 = (cr.getCourses().size() < 3 ? null : cr.getCourses().get(2));
                Course enrolled = (e == null ? null : e.getCourse());
                csv.addLine(new CSVFile.CSVField[] { new CSVFile.CSVField(student.getId()), new CSVFile.CSVField(student.getExternalId()), new CSVFile.CSVField(priority), new CSVFile.CSVField(course.getName()), new CSVFile.CSVField(alt1 == null ? "" : alt1.getName()), new CSVFile.CSVField(alt2 == null ? "" : alt2.getName()), new CSVFile.CSVField(enrolled == null ? "" : enrolled.getName()), new CSVFile.CSVField(enrolled == null ? "" : String.valueOf(cr.getCourses().indexOf(enrolled) + 1)) });
            }
        }
    }
    return csv;
}
Also used : CSVFile(org.cpsolver.ifs.util.CSVFile) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) Request(org.cpsolver.studentsct.model.Request) Enrollment(org.cpsolver.studentsct.model.Enrollment) Student(org.cpsolver.studentsct.model.Student) Course(org.cpsolver.studentsct.model.Course) RequestPriority(org.cpsolver.studentsct.model.Request.RequestPriority)

Example 2 with RequestPriority

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

the class StudentSctNeighbourSelection method setup.

public void setup(Solver<Request, Enrollment> solver) {
    if (iMPP)
        registerSelection(new AssignInitialSelection(solver.getProperties()));
    if (iPriorityStudentsFirstSelection && iPriorityStudentsFirstAllIn) {
        if (iUseCriticalCoursesSelection) {
            for (StudentPriority sp : StudentPriority.values()) {
                if (sp == StudentPriority.Normal)
                    break;
                for (int pr = 0; pr < iPriorityRounds; pr++) {
                    // last round >> include all students up to the selected priority
                    boolean includeHigherPriority = (iPriorityLastRoundAllStudents && sp.ordinal() > 0 && (pr + 1 == iPriorityRounds));
                    StudentFilter filter = new PriortyStudentFilter(sp, includeHigherPriority);
                    for (RequestPriority rp : RequestPriority.values()) {
                        for (int cr = 0; cr < iCriticalRounds; cr++) {
                            registerSelection(new CriticalCoursesBranchAndBoundSelection(solver.getProperties(), rp).withFilter(filter));
                            registerSelection(new CriticalBacktrackSelection(solver.getProperties(), rp).withFilter(filter));
                            registerSelection(new CriticalStandardSelection(solver.getProperties(), new UnassignedRequestSelection().withFilter(filter), getValueSelection(), rp));
                            registerSelection(new CriticalBacktrackSelection(solver.getProperties(), rp).withFilter(filter));
                        }
                    }
                }
            }
        } else {
            for (StudentPriority sp : StudentPriority.values()) {
                if (sp == StudentPriority.Normal)
                    break;
                for (int pr = 0; pr < iPriorityRounds; pr++) {
                    // last round >> include all students up to the selected priority
                    boolean includeHigherPriority = (iPriorityLastRoundAllStudents && sp.ordinal() > 0 && (pr + 1 == iPriorityRounds));
                    StudentFilter filter = new PriortyStudentFilter(sp, includeHigherPriority);
                    registerSelection(new BranchBoundSelection(solver.getProperties()).withFilter(filter));
                    registerSelection(new BacktrackSelection(solver.getProperties()).withFilter(filter));
                    registerSelection(new StandardSelection(solver.getProperties(), new UnassignedRequestSelection().withFilter(filter), getValueSelection()));
                    registerSelection(new BacktrackSelection(solver.getProperties()).withFilter(filter));
                }
            }
        }
    }
    if (iUseCriticalCoursesSelection) {
        for (RequestPriority rp : RequestPriority.values()) {
            if (rp == RequestPriority.Normal)
                break;
            for (int cr = 0; cr < iCriticalRounds; cr++) {
                registerSelection(new CriticalCoursesBranchAndBoundSelection(solver.getProperties(), rp));
                registerSelection(new CriticalBacktrackSelection(solver.getProperties(), rp));
                registerSelection(new CriticalStandardSelection(solver.getProperties(), getValueSelection(), rp));
                registerSelection(new CriticalBacktrackSelection(solver.getProperties(), rp));
            }
        }
    }
    if (iPriorityStudentsFirstSelection && !iPriorityStudentsFirstAllIn) {
        for (StudentPriority sp : StudentPriority.values()) {
            if (sp == StudentPriority.Normal)
                break;
            if (((StudentSectioningModel) solver.currentSolution().getModel()).getNbrStudents(sp) == 0)
                continue;
            for (int pr = 0; pr < iPriorityRounds; pr++) {
                // last round >> include all students up to the selected priority
                boolean includeHigherPriority = (iPriorityLastRoundAllStudents && sp.ordinal() > 0 && (pr + 1 == iPriorityRounds));
                StudentFilter filter = new PriortyStudentFilter(sp, includeHigherPriority);
                registerSelection(new BranchBoundSelection(solver.getProperties()).withFilter(filter));
                registerSelection(new BacktrackSelection(solver.getProperties()).withFilter(filter));
                registerSelection(new StandardSelection(solver.getProperties(), new UnassignedRequestSelection().withFilter(filter), getValueSelection()));
                registerSelection(new BacktrackSelection(solver.getProperties()).withFilter(filter));
            }
        }
    }
    if (iUseMinCreditSelection)
        registerSelection(new MinCreditBranchAndBoundSelection(solver.getProperties()));
    // Phase 1: section all students using incremental branch & bound (no
    // unassignments)
    registerSelection(iUseConstruction && !iUseMinCreditSelection ? new PriorityConstructionSelection(solver.getProperties()) : new BranchBoundSelection(solver.getProperties()));
    // Phase 2: pick a student (one by one) with an incomplete schedule, try
    // to find an improvement
    registerSelection(new SwapStudentSelection(solver.getProperties()));
    // Phase 3A: use backtrack neighbour selection
    registerSelection(new BacktrackSelection(solver.getProperties()));
    // Phase 3B: enrollment swap selection
    registerSelection(new StudentEnrollmentSwapSelection(solver.getProperties()));
    // Phase 4: use standard value selection for some time
    registerSelection(new StandardSelection(solver.getProperties(), getVariableSelection(), getValueSelection()));
    // Phase 5: pick a student (one by one) with an incomplete schedule, try
    // to find an improvement, identify problematic students
    SwapStudentSelection swapStudentSelection = new SwapStudentSelection(solver.getProperties());
    registerSelection(swapStudentSelection);
    // Phase 6: random unassignment of some problematic students
    registerSelection(new RndUnProblStudSelection(solver.getProperties(), swapStudentSelection));
    // Phase 7: resection incomplete students
    registerSelection(new ResectionIncompleteStudentsSelection(solver.getProperties()));
    // Phase 8: resection of students that were unassigned in step 6
    registerSelection(new ResectionUnassignedStudentsSelection(solver.getProperties()));
    // Phase 9: pick a student (one by one) with an incomplete schedule, try
    // to find an improvement
    registerSelection(new SwapStudentSelection(solver.getProperties()));
    // Phase 10: use standard value selection for some time
    registerSelection(new StandardSelection(solver.getProperties(), new RouletteWheelRequestSelection(solver.getProperties()), getValueSelection()));
    // Phase 11: pick a student (one by one) with an incomplete schedule,
    // try to find an improvement
    registerSelection(new SwapStudentSelection(solver.getProperties()));
    // Phase 12A: enrollment swap selection
    registerSelection(new StudentEnrollmentSwapSelection(solver.getProperties()));
    // Phase 12B: use backtrack neighbour selection
    registerSelection(new BacktrackSelection(solver.getProperties()));
    if (iShuffleStudentsSelection) {
        // Phase 13: try shuffling students around request groups
        registerSelection(new ShuffleStudentsSelection(solver.getProperties()));
        // Phase 14: use backtrack neighbour selection to fix unassignments from the previous phase
        registerSelection(new BacktrackSelection(solver.getProperties()));
    }
    // Phase 15: reset to best if no improvement has been done in the last cycle
    registerSelection(new RestoreBestSolution(solver.getProperties()));
    // Phase 16: use backtrack neighbour selection
    registerSelection(new BacktrackSelection(solver.getProperties()));
    // Phase 17: section all students using incremental branch & bound
    registerSelection(new BranchBoundSelection(solver.getProperties()));
    // Phase 18: random unassignment of some students
    registerSelection(new RandomUnassignmentSelection(solver.getProperties()));
}
Also used : StudentFilter(org.cpsolver.studentsct.filter.StudentFilter) PriortyStudentFilter(org.cpsolver.studentsct.filter.PriortyStudentFilter) BacktrackSelection(org.cpsolver.studentsct.heuristics.selection.BacktrackSelection) CriticalBacktrackSelection(org.cpsolver.studentsct.heuristics.selection.CriticalBacktrackSelection) CriticalBacktrackSelection(org.cpsolver.studentsct.heuristics.selection.CriticalBacktrackSelection) AssignInitialSelection(org.cpsolver.studentsct.heuristics.selection.AssignInitialSelection) StudentPriority(org.cpsolver.studentsct.model.Student.StudentPriority) UnassignedRequestSelection(org.cpsolver.studentsct.heuristics.selection.UnassignedRequestSelection) ResectionIncompleteStudentsSelection(org.cpsolver.studentsct.heuristics.selection.ResectionIncompleteStudentsSelection) RndUnProblStudSelection(org.cpsolver.studentsct.heuristics.selection.RndUnProblStudSelection) RequestPriority(org.cpsolver.studentsct.model.Request.RequestPriority) CriticalStandardSelection(org.cpsolver.studentsct.heuristics.selection.CriticalStandardSelection) StandardSelection(org.cpsolver.studentsct.heuristics.selection.StandardSelection) BranchBoundSelection(org.cpsolver.studentsct.heuristics.selection.BranchBoundSelection) CriticalStandardSelection(org.cpsolver.studentsct.heuristics.selection.CriticalStandardSelection) CriticalCoursesBranchAndBoundSelection(org.cpsolver.studentsct.heuristics.selection.CriticalCoursesBranchAndBoundSelection) PriorityConstructionSelection(org.cpsolver.studentsct.heuristics.selection.PriorityConstructionSelection) PriortyStudentFilter(org.cpsolver.studentsct.filter.PriortyStudentFilter) StudentEnrollmentSwapSelection(org.cpsolver.studentsct.heuristics.selection.StudentEnrollmentSwapSelection) ShuffleStudentsSelection(org.cpsolver.studentsct.heuristics.selection.ShuffleStudentsSelection) RandomUnassignmentSelection(org.cpsolver.studentsct.heuristics.selection.RandomUnassignmentSelection) ResectionUnassignedStudentsSelection(org.cpsolver.studentsct.heuristics.selection.ResectionUnassignedStudentsSelection) SwapStudentSelection(org.cpsolver.studentsct.heuristics.selection.SwapStudentSelection) MinCreditBranchAndBoundSelection(org.cpsolver.studentsct.heuristics.selection.MinCreditBranchAndBoundSelection)

Aggregations

RequestPriority (org.cpsolver.studentsct.model.Request.RequestPriority)2 CSVFile (org.cpsolver.ifs.util.CSVFile)1 PriortyStudentFilter (org.cpsolver.studentsct.filter.PriortyStudentFilter)1 StudentFilter (org.cpsolver.studentsct.filter.StudentFilter)1 AssignInitialSelection (org.cpsolver.studentsct.heuristics.selection.AssignInitialSelection)1 BacktrackSelection (org.cpsolver.studentsct.heuristics.selection.BacktrackSelection)1 BranchBoundSelection (org.cpsolver.studentsct.heuristics.selection.BranchBoundSelection)1 CriticalBacktrackSelection (org.cpsolver.studentsct.heuristics.selection.CriticalBacktrackSelection)1 CriticalCoursesBranchAndBoundSelection (org.cpsolver.studentsct.heuristics.selection.CriticalCoursesBranchAndBoundSelection)1 CriticalStandardSelection (org.cpsolver.studentsct.heuristics.selection.CriticalStandardSelection)1 MinCreditBranchAndBoundSelection (org.cpsolver.studentsct.heuristics.selection.MinCreditBranchAndBoundSelection)1 PriorityConstructionSelection (org.cpsolver.studentsct.heuristics.selection.PriorityConstructionSelection)1 RandomUnassignmentSelection (org.cpsolver.studentsct.heuristics.selection.RandomUnassignmentSelection)1 ResectionIncompleteStudentsSelection (org.cpsolver.studentsct.heuristics.selection.ResectionIncompleteStudentsSelection)1 ResectionUnassignedStudentsSelection (org.cpsolver.studentsct.heuristics.selection.ResectionUnassignedStudentsSelection)1 RndUnProblStudSelection (org.cpsolver.studentsct.heuristics.selection.RndUnProblStudSelection)1 ShuffleStudentsSelection (org.cpsolver.studentsct.heuristics.selection.ShuffleStudentsSelection)1 StandardSelection (org.cpsolver.studentsct.heuristics.selection.StandardSelection)1 StudentEnrollmentSwapSelection (org.cpsolver.studentsct.heuristics.selection.StudentEnrollmentSwapSelection)1 SwapStudentSelection (org.cpsolver.studentsct.heuristics.selection.SwapStudentSelection)1