use of org.cpsolver.studentsct.filter.StudentFilter 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;
}
}
use of org.cpsolver.studentsct.filter.StudentFilter in project cpsolver by UniTime.
the class StandardSelection method init.
/**
* Initialization
*/
@Override
public void init(Solver<Request, Enrollment> solver) {
StudentFilter filter = null;
if (iVariableSelection instanceof UnassignedRequestSelection)
filter = ((UnassignedRequestSelection) iVariableSelection).getFilter();
init(solver, "Ifs" + (filter == null ? "" : " (" + filter.getName().toLowerCase() + " students)") + "...");
}
use of org.cpsolver.studentsct.filter.StudentFilter in project cpsolver by UniTime.
the class CriticalStandardSelection method init.
@Override
public void init(Solver<Request, Enrollment> solver) {
StudentFilter filter = null;
if (iVariableSelection instanceof UnassignedRequestSelection)
filter = ((UnassignedRequestSelection) iVariableSelection).getFilter();
init(solver, iPriority.name() + " Ifs" + (filter == null ? "" : " (" + filter.getName().toLowerCase() + " students)") + "...");
}
use of org.cpsolver.studentsct.filter.StudentFilter 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()));
}
Aggregations