use of org.cpsolver.studentsct.model.CourseRequest in project cpsolver by UniTime.
the class MultiCriteriaBranchAndBoundSelection method backTrack.
/**
* branch & bound search
*/
public void backTrack(int idx) {
if (iTimeout > 0 && (JProf.currentTimeMillis() - iT0) > iTimeout) {
iTimeoutReached = true;
return;
}
if (idx == iCurrentAssignment.length) {
if (iBestAssignment == null || iComparator.compare(iAssignment, iCurrentAssignment, iBestAssignment) < 0)
saveBest();
return;
} else if (iBestAssignment != null && !iComparator.canImprove(iAssignment, idx, iCurrentAssignment, iBestAssignment)) {
return;
}
Request request = iStudent.getRequests().get(idx);
if (!canAssign(request, idx)) {
backTrack(idx + 1);
return;
}
List<Enrollment> values = null;
if (request instanceof CourseRequest) {
CourseRequest courseRequest = (CourseRequest) request;
if (!courseRequest.getSelectedChoices().isEmpty()) {
values = courseRequest.getSelectedEnrollments(iAssignment, true);
if (values != null && !values.isEmpty()) {
boolean hasNoConflictValue = false;
for (Enrollment enrollment : values) {
if (inConflict(idx, enrollment))
continue;
hasNoConflictValue = true;
iCurrentAssignment[idx] = enrollment;
backTrack(idx + 1);
iCurrentAssignment[idx] = null;
}
if (hasNoConflictValue && iBranchWhenSelectedHasNoConflict)
return;
}
}
values = iValues.get(courseRequest);
if (values == null) {
values = values(courseRequest);
iValues.put(courseRequest, values);
}
} else {
values = request.computeEnrollments(iAssignment);
}
boolean hasNoConflictValue = false;
for (Enrollment enrollment : values) {
if (inConflict(idx, enrollment))
continue;
hasNoConflictValue = true;
iCurrentAssignment[idx] = enrollment;
backTrack(idx + 1);
iCurrentAssignment[idx] = null;
}
if (canLeaveUnassigned(request) || (!hasNoConflictValue && request instanceof CourseRequest))
backTrack(idx + 1);
}
use of org.cpsolver.studentsct.model.CourseRequest in project cpsolver by UniTime.
the class MultiCriteriaBranchAndBoundSelection method isAllowed.
public boolean isAllowed(int idx, Enrollment enrollment) {
if (enrollment.isCourseRequest()) {
CourseRequest request = (CourseRequest) enrollment.getRequest();
if (iRequiredUnassinged != null && iRequiredUnassinged.contains(request))
return false;
Config reqConfig = iRequiredConfig.get(request);
if (reqConfig != null) {
if (!reqConfig.equals(enrollment.getConfig()))
return false;
Hashtable<Subpart, Section> reqSections = iRequiredSection.get(request);
for (Section section : enrollment.getSections()) {
Section reqSection = reqSections.get(section.getSubpart());
if (reqSection == null)
continue;
if (!section.equals(reqSection))
return false;
}
}
} else if (iRequiredFreeTimes.contains(enrollment.getRequest())) {
if (enrollment.getAssignments() == null || enrollment.getAssignments().isEmpty())
return false;
}
return true;
}
Aggregations