Skip to content

Commit

Permalink
Student Scheduling: Concurrent Modification
Browse files Browse the repository at this point in the history
- improved handing of concurrent modification errors during backtracking (caused by a model change during the search)
  - retry computation of the neighbour selection up to five times rather than skipping to the next student/request
  • Loading branch information
tomas-muller committed Nov 15, 2020
1 parent 55c3eab commit 12657a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -114,15 +115,20 @@ public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollme
Enrollment e = request.getAssignment(solution.getAssignment());
if (e != null && request instanceof FreeTimeRequest) continue;
if (e != null && e.getPriority() == 0 && ((CourseRequest)request).getSelectedChoices().isEmpty()) continue;
Neighbour<Request, Enrollment> n = iRBtNSel.selectNeighbour(solution, request);
if (iRBtNSel.getContext() != null) {
iNbrIterations ++;
iTotalTime += iRBtNSel.getContext().getTime();
if (iRBtNSel.getContext().isTimeoutReached()) iNbrTimeoutReached ++;
if (n == null) iNbrNoSolution ++;
for (int i = 0; i < 5; i++) {
try {
Neighbour<Request, Enrollment> n = iRBtNSel.selectNeighbour(solution, request);
if (iRBtNSel.getContext() != null) {
iNbrIterations ++;
iTotalTime += iRBtNSel.getContext().getTime();
if (iRBtNSel.getContext().isTimeoutReached()) iNbrTimeoutReached ++;
if (n == null) iNbrNoSolution ++;
}
if (n != null && n.value(solution.getAssignment()) <= 0.0)
return n;
break;
} catch (ConcurrentModificationException ex) {}
}
if (n != null && n.value(solution.getAssignment()) <= 0.0)
return n;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -192,9 +193,13 @@ public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollme
Student student = null;
while ((student = nextStudent()) != null) {
Progress.getInstance(solution.getModel()).incProgress();
Neighbour<Request, Enrollment> neighbour = getSelection(solution.getAssignment(), student).select();
if (neighbour != null)
return neighbour;
for (int i = 0; i < 5; i++) {
try {
Neighbour<Request, Enrollment> neighbour = getSelection(solution.getAssignment(), student).select();
if (neighbour != null) return neighbour;
break;
} catch (ConcurrentModificationException e) {}
}
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -162,13 +163,18 @@ public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollme
Progress.getInstance(solution.getModel()).incProgress();
if (student.isComplete(solution.getAssignment()) || student.nrAssignedRequests(solution.getAssignment()) == 0)
continue;
Selection selection = getSelection(solution.getAssignment(), student);
Neighbour<Request, Enrollment> neighbour = selection.select();
if (neighbour != null) {
addStudent(student);
return neighbour;
} else
iProblemStudents.addAll(selection.getProblemStudents());
for (int i = 0; i < 5; i++) {
try {
Selection selection = getSelection(solution.getAssignment(), student);
Neighbour<Request, Enrollment> neighbour = selection.select();
if (neighbour != null) {
addStudent(student);
return neighbour;
} else
iProblemStudents.addAll(selection.getProblemStudents());
break;
} catch (ConcurrentModificationException e) {}
}
}
return null;
}
Expand Down

0 comments on commit 12657a9

Please sign in to comment.