Skip to content

Commit

Permalink
Student Scheduling: Branch&Bound / Backtrack
Browse files Browse the repository at this point in the history
- when sorting possible enrollments, avoid contract violations
  • Loading branch information
tomas-muller committed Feb 24, 2021
1 parent 14e629e commit 7bdb71e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ protected Iterator<Enrollment> values(BacktrackNeighbourSelection<Request, Enrol
final CourseRequest request = (CourseRequest)variable;
final StudentSectioningModel model = (StudentSectioningModel)context.getModel();
final Assignment<Request, Enrollment> assignment = context.getAssignment();
final Enrollment current = assignment.getValue(request);
List<Enrollment> values = (iMaxValues > 0 ? request.computeRandomEnrollments(assignment, iMaxValues) : request.computeEnrollments(assignment));
Collections.sort(values, new Comparator<Enrollment>() {
private HashMap<Enrollment, Double> iValues = new HashMap<Enrollment, Double>();
Expand All @@ -107,8 +108,9 @@ private Double value(Enrollment e) {
}
@Override
public int compare(Enrollment e1, Enrollment e2) {
if (e1.equals(assignment.getValue(request))) return -1;
if (e2.equals(assignment.getValue(request))) return 1;
if (e1.equals(e2)) return 0;
if (e1.equals(current)) return -1;
if (e2.equals(current)) return 1;
Double v1 = value(e1), v2 = value(e2);
return v1.equals(v2) ? e1.compareTo(assignment, e2) : v2.compareTo(v1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ private Double value(Enrollment e) {

@Override
public int compare(Enrollment e1, Enrollment e2) {
if (e1.equals(e2)) return 0;
if (e1.equals(iCurrentAssignment.getValue(request))) return -1;
if (e2.equals(iCurrentAssignment.getValue(request))) return 1;
if (iTimesToAvoid != null) {
Expand Down

0 comments on commit 7bdb71e

Please sign in to comment.