Search in sources :

Example 1 with RandomStudentFilter

use of org.cpsolver.studentsct.filter.RandomStudentFilter in project cpsolver by UniTime.

the class Test method combineStudents.

/**
 * Combine students from the provided two files
 * @param cfg solver configuration
 * @param lastLikeStudentData a file containing last-like student data
 * @param realStudentData a file containing real student data
 * @return combined solution
 */
public static Solution<Request, Enrollment> combineStudents(DataProperties cfg, File lastLikeStudentData, File realStudentData) {
    try {
        RandomStudentFilter rnd = new RandomStudentFilter(1.0);
        StudentSectioningModel model = null;
        Assignment<Request, Enrollment> assignment = new DefaultSingleAssignment<Request, Enrollment>();
        for (StringTokenizer stk = new StringTokenizer(cfg.getProperty("Test.CombineAcceptProb", "1.0"), ","); stk.hasMoreTokens(); ) {
            double acceptProb = Double.parseDouble(stk.nextToken());
            sLog.info("Test.CombineAcceptProb=" + acceptProb);
            rnd.setProbability(acceptProb);
            StudentFilter batchFilter = new CombinedStudentFilter(new ReverseStudentFilter(new FreshmanStudentFilter()), rnd, CombinedStudentFilter.OP_AND);
            model = new StudentSectioningModel(cfg);
            StudentSectioningXMLLoader loader = new StudentSectioningXMLLoader(model, assignment);
            loader.setLoadStudents(false);
            loader.load();
            StudentSectioningXMLLoader lastLikeLoader = new StudentSectioningXMLLoader(model, assignment);
            lastLikeLoader.setInputFile(lastLikeStudentData);
            lastLikeLoader.setLoadOfferings(false);
            lastLikeLoader.setLoadStudents(true);
            lastLikeLoader.load();
            StudentSectioningXMLLoader realLoader = new StudentSectioningXMLLoader(model, assignment);
            realLoader.setInputFile(realStudentData);
            realLoader.setLoadOfferings(false);
            realLoader.setLoadStudents(true);
            realLoader.setStudentFilter(batchFilter);
            realLoader.load();
            fixWeights(model);
            fixPriorities(model);
            Solver<Request, Enrollment> solver = new Solver<Request, Enrollment>(model.getProperties());
            solver.setInitalSolution(model);
            new StudentSectioningXMLSaver(solver).save(new File(new File(model.getProperties().getProperty("General.Output", ".")), "solution-r" + ((int) (100.0 * acceptProb)) + ".xml"));
        }
        return model == null ? null : new Solution<Request, Enrollment>(model, assignment);
    } catch (Exception e) {
        sLog.error("Unable to combine students, reason: " + e.getMessage(), e);
        return null;
    }
}
Also used : FreshmanStudentFilter(org.cpsolver.studentsct.filter.FreshmanStudentFilter) RandomStudentFilter(org.cpsolver.studentsct.filter.RandomStudentFilter) ReverseStudentFilter(org.cpsolver.studentsct.filter.ReverseStudentFilter) StudentFilter(org.cpsolver.studentsct.filter.StudentFilter) CombinedStudentFilter(org.cpsolver.studentsct.filter.CombinedStudentFilter) Solver(org.cpsolver.ifs.solver.Solver) ParallelSolver(org.cpsolver.ifs.solver.ParallelSolver) FreshmanStudentFilter(org.cpsolver.studentsct.filter.FreshmanStudentFilter) RandomStudentFilter(org.cpsolver.studentsct.filter.RandomStudentFilter) Request(org.cpsolver.studentsct.model.Request) CourseRequest(org.cpsolver.studentsct.model.CourseRequest) IOException(java.io.IOException) StringTokenizer(java.util.StringTokenizer) ReverseStudentFilter(org.cpsolver.studentsct.filter.ReverseStudentFilter) Enrollment(org.cpsolver.studentsct.model.Enrollment) CombinedStudentFilter(org.cpsolver.studentsct.filter.CombinedStudentFilter) DefaultSingleAssignment(org.cpsolver.ifs.assignment.DefaultSingleAssignment) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 StringTokenizer (java.util.StringTokenizer)1 DefaultSingleAssignment (org.cpsolver.ifs.assignment.DefaultSingleAssignment)1 ParallelSolver (org.cpsolver.ifs.solver.ParallelSolver)1 Solver (org.cpsolver.ifs.solver.Solver)1 CombinedStudentFilter (org.cpsolver.studentsct.filter.CombinedStudentFilter)1 FreshmanStudentFilter (org.cpsolver.studentsct.filter.FreshmanStudentFilter)1 RandomStudentFilter (org.cpsolver.studentsct.filter.RandomStudentFilter)1 ReverseStudentFilter (org.cpsolver.studentsct.filter.ReverseStudentFilter)1 StudentFilter (org.cpsolver.studentsct.filter.StudentFilter)1 CourseRequest (org.cpsolver.studentsct.model.CourseRequest)1 Enrollment (org.cpsolver.studentsct.model.Enrollment)1 Request (org.cpsolver.studentsct.model.Request)1