use of org.cpsolver.studentsct.filter.ReverseStudentFilter 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;
}
}
Aggregations